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
Manually compact GC before fork #2093
Conversation
a62f551
to
2b4eb74
Compare
JFYI, using ruby master in actions: https://github.com/ruby/psych/blob/master/.github/workflows/ubuntu-rvm.yml |
Would it be worthwhile to add a At work, we often will use eye to monitor child processes for memory bloat and have eye kill them. It would be beneficial to have this only done on the first fork instead of every time we fork. |
9c46fea
to
020e4d8
Compare
I'm getting failures on GitHub actions for 2.7.0 and 2.3.x and 2.3.8 with just
Any idea how to debug or what needs to be changed @MSP-Greg ? |
At present, standard GitHub actions just has Ruby 2.4.x, 2.5.x, & 2.6.x installed. Anything else needs code using a container, installing and using rvm, or a special action step. @dentarg & PR #2087 adds Ruby 2.3 in a container. The Ruby/Psych code I linked to adds ruby-head using rvm. I can add 2.3 & ruby-head to Windows, but that won't run this code as fork is not available... |
Rub 2.7.0 introduced `GC.compact` which allows manual compaction of Ruby slots. A good time to do this is before forking so that memory fragmentation can be reduced. - https://www.ruby-lang.org/en/news/2019/12/17/ruby-2-7-0-rc1-released/ - https://www.youtube.com/watch?v=1F3gXYhQsAY One issue with memory fragmentation when forking is that while a page in memory might have only one free slot, as that slot is written to after fork, the entire page is written so the benefit of CoW optimizations are greatly reduced. Manually compacting GC reduces the number of pages with empty slots. This PR manually compacts memory right before Puma forks and after other `before_fork` hooks are called.
020e4d8
to
abd3f35
Compare
All the Travis 2.7.0 tests passed, and all the Actions tests that are not broken passed. |
Seems good! |
Rub 2.7.0 introduced
GC.compact
which allows manual compaction of Ruby slots. A good time to do this is before forking so that memory fragmentation can be reduced.One issue with memory fragmentation when forking is that while a page in memory might have only one free slot, as that slot is written to after fork, the entire page is written so the benefit of CoW optimizations are greatly reduced. Manually compacting GC reduces the number of pages with empty slots.
This PR manually compacts memory right before Puma forks and after other
before_fork
hooks are called.Description
Please describe your pull request. Thank you for contributing! You're the best.
Your checklist for this pull request
[changelog skip]
the pull request title.[ci skip]
to the title of the PR.#issue
" to the PR description or my commit messages.