Skip to content
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

RFC 2 : Delay Fiber stack association #15404

Conversation

ysbaddaden
Copy link
Contributor

Fiber#initialize now takes an explicit stack. The public API doesn't change, and we can still create a Fiber without an explicit stack, taken from the current scheduler/context's stack pool.

Fiber::ExecutionContext#spawn takes advantage of this to take a stack from the execution context's stack pool, instead of the current context's stack pool. Cross context spawns thus won't take a stack from context A but release the stack in context B (where it actually ran) which would prevent stack recycling.

This also permits to create lots of Fiber instances in specs using a minimal fake stack, instead of requesting 8MB of virtual memory for each fiber, despite the fibers never running... which is leaking memory because we only release the stacks when the fiber terminates.

Follow up to #15345 and #15350

`Fiber::ExecutionContext#spawn` takes advantage of this to take a stack
from the execution context's stack pool, instead of the current
context's stack pool. Cross context spawns thus won't take a stack from
context A but release the stack in context B (where it actually ran)
which would prevent stack recycling.

This also permits to create lots of Fiber instances in specs using a
minimal fake stack, instead of requesting 8MB of virtual memory for each
fiber, despite the fibers never running... which is leaking memory
because we only release the stacks when the fiber terminates.
@ysbaddaden
Copy link
Contributor Author

Allright: it eventually passed on mingw64 too.

@ysbaddaden ysbaddaden closed this Feb 4, 2025
@ysbaddaden ysbaddaden deleted the feature/execution-context-delay-fiber-stack-association branch February 4, 2025 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant