Use per-scheduler stack pools (let's recycle)#14100
Merged
straight-shoota merged 1 commit intocrystal-lang:masterfrom Jan 10, 2024
Merged
Use per-scheduler stack pools (let's recycle)#14100straight-shoota merged 1 commit intocrystal-lang:masterfrom
straight-shoota merged 1 commit intocrystal-lang:masterfrom
Conversation
f82fc19 to
d9db37b
Compare
Collaborator
Author
|
NOTE: I rebased the branch on top of #14099 which was required (must assign each stack collector fiber to its own thread). |
straight-shoota
approved these changes
Dec 22, 2023
Member
straight-shoota
left a comment
There was a problem hiding this comment.
LGTM.
It's particularly nice that this simplifies the code quite a bit.
The stack pool was only used to create new stacks when MT was enabled. The stacks were then pushed to each scheduler's free stacks, and eventually dropped on reschedule (after context swap, so we're sure to only ever deallocated stacks that are no longer used). This led the stacks to never be reused with MT. Only created then deallocated. This patch changes the behavior to have a stack pool running on each scheduler, and to use it to create and collect the stacks, and reuse them when possible. It also drops the mutex since the stack pool can never be accessed in parallel (in fact it never was). Also starts a collecting fiber on each thread. It may only lead to better performance if there are different fibers, running on multiple threads that are spawning fibers. It won't have much (or any) impact if there is only one fiber spawning other fibers (e.g. a HTTP::Server) as the stack of fibers that run on another thread won't be reused (different stack pool).
d9db37b to
ea8a3c1
Compare
Collaborator
Author
|
Rebased from master & force pushed to remove the duplicate commit (set current thread) from #14099 |
beta-ziliani
approved these changes
Jan 4, 2024
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The stack pool was only used to create new stacks when MT was enabled. The stacks were then pushed to each scheduler's free stacks, and eventually dropped on reschedule (after context swap, so we're sure to only ever deallocate stacks that are no longer used). This led the stacks to never be reused with MT. Only allocated, put back into a pool, then deallocated.
This patch changes the behavior to have a stack pool running on each scheduler, and to use it to create and collect the stacks, and reuse them when possible. It also drops the mutex since the stack pool can never be accessed in parallel (in fact it never was).
Also starts a collecting fiber on each thread.
Stacks won't necessarily return to the pool that created them. For example if thread A allocates a stack, then the scheduler sends the fiber to thread B, then the stack will be returned to thread B's scheduler.
It may thus only lead to better performance if there are different fibers, running on multiple threads that are spawning fibers. It won't have much (or any) impact if there is only one fiber spawning other fibers (e.g. a HTTP::Server).