Segmented stacks aren't the only solution though.

If the concern is many tasks that block for a long time, I imagine a
mechanism to bundle a bunch of small, dormant stacks into a single page so
that the original pages could be released to the OS.

If stacks were additionally relocatable (which requires similar machinery
as precise moving GC, if I'm not mistaken) then the released pages could be
re-used for other tasks or heaps, which would be especially helpful on
32-bit. To address the problem of running out of address space on 32-bit,
small-stack tasks could request a single-page stack (plus a guard page),
which is enlarged by relocation as needed.

Combining these techniques, you might be able to have up to a million small
tasks in a 32-bit process.

From: Bill Myers <[email protected]>
>
> The advantage of segmented stacks is that blocked tasks only take up as
> much memory as they actually need to store state, so that for instance a
> network server can use a task for each connection, and still only use, say,
> 64 bytes per connection if that's possible instead of the number of stack
> pages that got allocated for previous computation (assuming an "extreme"
> version that allocates a stack segment on every call).
>
> However, there is another approach that can replace segmented stacks for
> that purpose, namely having the compiler automatically transform blocking
> functions to instead return a future (with limited lifetime).
>
> This means that segmented allocation only happens for functions that
> indirectly perform I/O and only allocates the exact amount of memory needed
> to retain state that must persistent across the blocking I/O operation,
> while other functions execute normally using traditional stacks.
>
> The simplest example of this feature is async/await in C# 5, and Scala has
> a delimited continuation passing transformation that can be used to do the
> same thing.
>
> Has this been considered for Rust?
>
>
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to