Improve thread stack limit checking #1805

Closed
opened 1 year ago by Moonchild · 6 comments
Owner

Our determination of thread stack quotas can do with some improvements.

Of course this still won't solve environments like Alpine Linux that still need to increase the default stack size at link time to at least 1MB -- their default of 128kB is simply insufficient for a modern browser.

Self-assigning this because I have a good idea how to do this. Will need someone native in Linux to test this with some vigor on a few distros, though.

Our determination of thread stack quotas can do with some improvements. Of course this still won't solve environments like Alpine Linux that still need to increase the default stack size at link time to at least 1MB -- their default of 128kB is simply insufficient for a modern browser. Self-assigning this because I have a good idea how to do this. Will need someone native in Linux to test this with some vigor on a few distros, though.
Moonchild added the
Javascript
Enhancement
OS: Linux
OS: Linux (AltArch)
Verification Needed
labels 1 year ago
Moonchild self-assigned this 1 year ago
Moonchild added the
Performance
label 5 months ago
Moonchild removed the
OS: Linux
OS: Linux (AltArch)
labels 5 months ago
Poster
Owner

@athenian200 what would be the default thread stack limit on SunOS/Illumos?
Most Linux distros use 8MB. Mac also has 8MB. Windows defaults to 1MB/x86 and 2MB/x64 but we override that ourselves (and we can read what it has at run-time).

@athenian200 what would be the default thread stack limit on SunOS/Illumos? Most Linux distros use 8MB. Mac also has 8MB. Windows defaults to 1MB/x86 and 2MB/x64 but we override that ourselves (and we can read what it has at run-time).
Collaborator

Hmm... well, is the thread stack size you're talking about here the same as the stack size that would be reported by most Linux distros as ulimit -s?

The answer is a little different depending on whether you're talking about illumos or Oracle Solaris.

Oracle Solaris 11 uses 8MB for the default stack size, and illumos uses 10MB for the default stack size. Earlier versions of Solaris like Solaris 10 and earlier defaulted to 2MB like Windows I think, but it was eventually increased to 8MB for Solaris and 10MB for illumos respectively. Though you have always been able to raise it if you needed to.

Hmm... well, is the thread stack size you're talking about here the same as the stack size that would be reported by most Linux distros as `ulimit -s`? The answer is a little different depending on whether you're talking about illumos or Oracle Solaris. Oracle Solaris 11 uses 8MB for the default stack size, and illumos uses 10MB for the default stack size. Earlier versions of Solaris like Solaris 10 and earlier defaulted to 2MB like Windows I think, but it was eventually increased to 8MB for Solaris and 10MB for illumos respectively. Though you have always been able to raise it if you needed to.
Poster
Owner

It's all I needed to know. so I can just treat it the same as the Linuxes. Thanks!
How did you test for sunos preferably, by the way?
I could make it XP_UNIX, I guess, since I'm testing for Mac first

It's all I needed to know. so I can just treat it the same as the Linuxes. Thanks! How did you test for sunos preferably, by the way? I could make it XP_UNIX, I guess, since I'm testing for Mac first
Collaborator

I used ulimit -s to test the stack size for SunOS, and I got 10240 on illumos, and 8192 on Solaris. That value seems to be reported in KiB, and I think that translates to 10MiB and 8MiB respectively.

I'm sure there is a library function somewhere that can test it as well if you want to test in code, but that was the command I used.

I used `ulimit -s` to test the stack size for SunOS, and I got 10240 on illumos, and 8192 on Solaris. That value seems to be reported in KiB, and I think that translates to 10MiB and 8MiB respectively. I'm sure there is a library function somewhere that can test it as well if you want to test in code, but that was the command I used.
Collaborator

Well, I looked it up, and it seems like you can check the minimum allowed stack size on the system with sysconf(_SC_THREAD_STACK_MIN), and it reports 8192 on everything, presumably meaning it can never be set lower than that, although illumos does set it higher.

You can also use pthread_attr_setstacksize to set the stack size manually when using pthreads, of course.

Well, I looked it up, and it seems like you can check the minimum allowed stack size on the system with `sysconf(_SC_THREAD_STACK_MIN)`, and it reports 8192 on everything, presumably meaning it can never be set lower than that, although illumos does set it higher. You can also use `pthread_attr_setstacksize` to set the stack size manually when using pthreads, of course.
Moonchild added this to the 31.2.0 milestone 5 months ago
Poster
Owner

You can also use pthread_attr_setstacksize to set the stack size manually when using pthreads, of course.

Well I don't intend to set it dynamically here :)

The idea is to find a proper default maximum with as much space as possible to use, and then cap it as-necessary if > 2MB for JS to prevent lock-ups before "too much recursion" errors get thrown by bad code.
Alpine builders will still have to manually set their stack size at build time to the minimum for the rendering changes though as the layout depth of ~1000 with this change will require approximately 1.5-2 MB of thread stack to work. So on Linux I suggest always ensuring the minimum of 2MB at build time (passing a linker flag like we do on windows, I guess?) if the distro uses an unreasonably small stack.

> You can also use pthread_attr_setstacksize to set the stack size manually when using pthreads, of course. Well I don't intend to set it dynamically here :) The idea is to find a proper *default maximum* with as much space as possible to use, and then cap it as-necessary if > 2MB for JS to prevent lock-ups before "too much recursion" errors get thrown by bad code. Alpine builders will still have to manually set their stack size at build time to the minimum for the rendering changes though as the layout depth of ~1000 with this change will require approximately 1.5-2 MB of thread stack to work. So on Linux I suggest always ensuring the minimum of 2MB at build time (passing a linker flag like we do on windows, I guess?) if the distro uses an unreasonably small stack.
Moonchild closed this issue 5 months ago
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: MoonchildProductions/UXP#1805
Loading…
There is no content yet.