Use Fiber::StackPool in the interpreter#14395
Merged
straight-shoota merged 1 commit intocrystal-lang:masterfrom Mar 26, 2024
Merged
Use Fiber::StackPool in the interpreter#14395straight-shoota merged 1 commit intocrystal-lang:masterfrom
Fiber::StackPool in the interpreter#14395straight-shoota merged 1 commit intocrystal-lang:masterfrom
Conversation
Collaborator
|
Nice! One question: could we pass a grow upwards/downwards flag and protect the appropriate stack end? |
Contributor
Author
|
The guard page violation would go to the interpreter, but its stack trace will be different from that of the interpreted code, so guarding the highest address range of the stack alone wouldn't be sufficient if we need to handle stack overflows in the interpreter. It is probably easier to set a hard limit on the number of interpreter call frames directly |
straight-shoota
approved these changes
Mar 25, 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.
For some reason, when the GC allocates an 8 MB fiber stack in the interpreter, it might expand the heap only to find that the new pages are already black-listed, so it repeats until the system gives a good heap address. A single allocation could sometimes commit over 4 GB of memory this way.
This PR bypasses the GC entirely and allocates those fiber stacks using
mmaporVirtualAllocdirectly, the same as non-interpreted code. It doesn't change how stack pools are used, everyCrystal::Repl::Interpreterstill maintains its own pool. Apart from making specs likechannel_spec.cractually finish on Windows, it looks like the interpreted stdlib specs also run slightly faster on Linux.The REPL interpreter object still uses the old allocation via
Crystal::Repl::Interpreter.new's default argument for@stack.