-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document the behaviour of RUST_MIN_STACK=0 #135178
base: master
Are you sure you want to change the base?
Conversation
While digging through the code I noticed it went out of its way to distinguish RUST_MIN_STACK=0 from the sentinel value of 0, with no justification given. Then I did some searching and discovered at least one person knew that it made Rust use the platform default stack size to work under valgrind better. [0] This took me deeper into the guts of the platform-specific thread code where indeed i saw comments and/or explicit checks about 0 being a special sentinel to discard the 2MiB default in favour of "whatever the platform thread API wants to pick". These docs are already heavily caveated with "this is platform-specific" so I see no harm in specifying this further-platform-specific behaviour. [0]: https://nest.pijul.com/pijul/pijul/discussions/498
Instances of platform-specific code referencing this behaviour as intended/supported: rust/library/std/src/sys/pal/unix/thread.rs Lines 55 to 63 in 0f1e965
rust/library/std/src/sys/pal/windows/thread.rs Lines 26 to 40 in 0f1e965
|
@@ -125,9 +125,12 @@ | |||
//! ## Stack size | |||
//! | |||
//! The default stack size is platform-dependent and subject to change. | |||
//! Currently, it is 2 MiB on all Tier-1 platforms. | |||
//! Currently, it is 2 MiB on all Tier-1 platforms to make programs behave more consistently | |||
//! cross-platform (notably Windows would otherwise default to 1MiB stacks). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, maybe this is a nitpick but the Windows comment isn't strictly accurate. The default size is linker-defined, which does (on MSVC at least) use 1MiB if not otherwise set but it can be different. So saying 0 means 1MiB on Windows is not necessarily true even now and in the future Rust might opt to use a different value by default.
That said, I'm not sure it's worth going on about /stack
here, Maybe it's acceptable to say "1MiB" in a lies to children kind of way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's basically the emotional arc I went through. I was sorely tempted to specify "usually" or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair. I'm a little bit uncomfortable with std docs that aren't technically correct but it is truthish and it does make sense to mention the 1MiB somewhere as it's something that does trip up cross-platform code (admittedly mostly for the main thread rather than spawning new ones but still).
Checking some stuff more closely I think what I'm documenting is wrong on linux/macos, where we don't seem to check for 0 and instead do Note that in the following code rust/library/std/src/sys/pal/unix/thread.rs Lines 65 to 83 in 0f1e965
|
I guess it's keeping with the spirit of "it's platform-specific" to have 0 get handled so inconsistently but it's Weird that it's like... Almost A Convention but Not. |
r? libs-api |
While digging through the code I noticed it went out of its way to distinguish RUST_MIN_STACK=0 from the sentinel value of 0, with no justification given.
Then I did some searching and discovered at least one person knew that it made Rust use the platform default stack size to work under valgrind better. 0
This took me deeper into the guts of the platform-specific thread code where indeed i saw comments and/or explicit checks about 0 being a special sentinel to discard the 2MiB default in favour of "whatever the platform thread API wants to pick".
These docs are already heavily caveated with "this is platform-specific" so I see no harm in specifying this further-platform-specific behaviour.