-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Make split stacks (segmented stacks) optional #8345
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
From a "runtimeless rust" perspective, this is a bit of a nuanced issue. I believe that there are a few viable modes of operation which may be desired for "split stacks":
I think that the vast majority of people will fall into option 1 (they're just using rust normally), and then a large portion of the remaining people will fall into bucket 3. In bucket 3 there are no assumptions made about the stack, and it's up to your own runtime to guarantee that you have enough. This could involve allocating guard pages, but regardless the compiler doesn't need to know about it. @thestinger brings up a good point though in that option 2 should not be left out. There are many situations where stack overflow is a serious problem, and having checks against that is very beneficial. The downside of this option is the stack limit must be stored in one particular location (where LLVM expects it). I think that the most difficult part here will be clearly documenting what option 2 implies for each architecture. From a user's perspective they'll have to ensure that the stack limit is in the right place before calling any rust code (or use a #[no_split_stack] attribute). From that, as an actionable item, I would propose the following following states based on crate attributes:
What do others think about this? These attributes have diverged a bit from discussing optional split stacks to more of a runtimeless-rust, but most of this is still about split stacks so I decided to leave it here rather than on the metabug. |
I don't think we should have The solution to the 1-5% performance hit from the checks is to use guard pages and only insert the check when functions allocate more than the guard page size - it shouldn't be too hard to teach LLVM to omit them in those cases. |
Omitting If rust is a language which wants to target everything, then I think it should be configurable in almost every way. I can think that perhaps various microcontrollers or kernels don't need to bother with stack protection and it just provides an extra burden to define. That being said, it would be very easy to emulate Thinking about it though, I can't think of too many strategies that would actually be taken, so there would probably be just a few libraries (maybe officially maintained?) which provide this functionality.
Regardless though, I think that there should be a |
Why bother having An alternative is to forbid functions using more than N stack space, and reserve N space as guard pages. If you don't have virtual memory you need |
Nominating for Well-Covered (unless this is a backwards-incompatible issue and I'm oblivious). |
The conclusion was that we would always use split stacks, but on 64-bit platforms with overcommit we would make the initial segment large enough that it doesn't need to grow in typical use. This was also already implemented in the old runtime. For freestanding Rust the question is more open - certainly one can build without split stacks if they like. |
In that case I'm happy to close. Anyone can reopen this if they feel that there's more to discuss. |
Right now there's no way (that I know of) to build programs without split stacks, so if we want to support that shouldn't the issue stay open? |
There's another issue open about the relevant part from here: #5768 |
That seems like a relevant issue, but not the same to me. That's talking more about a configurable stack size while this is talking about configuring whether a call to I agree with @brson that for a freestanding rust it should be possible to build without split stacks, so reopening. |
Something kind of relevant is that split stacks are not yet implemented in the new runtime, they loom large on the todo list though. |
Not in scope for a milestone |
Segmented stacks have been removed so this is no longer relevant. |
Update docs for `map_flatten` on `Option` case closes rust-lang#8345 changelog: [`map_flatten`] Add docs info for `Option` case
I know this has been discussed before, but I couldn't find a bug for it. I believe @thestinger is of the opinion that the constant overhead of split stacks and the narrow use case (spawning enormous numbers of I/O-bound tasks on 32-bit architectures) isn't acceptable, and will keep Rust from ever matching the performance of C++.
I remember at least some of the developers (pcwalton? brson?) saying that split stacks won't go away, but could become optional. I can't seem to find the dicussions, though.
Making segmented stacks optional should also simplify runtimeless Rust (#3608).
The text was updated successfully, but these errors were encountered: