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

YJIT: Instrument global allocations on stats build #6712

Merged
merged 2 commits into from Nov 13, 2022

Conversation

k0kubun
Copy link
Member

@k0kubun k0kubun commented Nov 11, 2022

For stats build, this PR allows you to measure how much memory YJIT uses in Rust.

Enabling YJIT currently consumes a lot more memory than what's used for code pages. I think it's nice to monitor changes in allocated bytes before attempting to reduce it because some changes could come at the cost of implementation complexity and we shouldn't do it when it's not really effective.

Example

The current state of 25 itrs on railsbench:

inline_code_size:         4855668
outlined_code_size:       4852936
freed_code_size:                0
yjit_alloc_size:         25114317

When 9.7MB is used for JIT code, 25.1MB is used for Rust's global allocations.

Benchmark

Its performance impact on stats build seems negligible. Here's the yjit-bench result on railsbench.

Before

itr #1: 1503ms
itr #2: 1164ms
itr #3: 1148ms
itr #4: 1179ms
itr #5: 1114ms
itr #6: 1173ms
itr #7: 1165ms
itr #8: 1153ms
itr #9: 1173ms
itr #10: 1152ms
itr #11: 1149ms
itr #12: 1180ms
itr #13: 1166ms
itr #14: 1138ms
itr #15: 1179ms
itr #16: 1149ms
itr #17: 1163ms
itr #18: 1173ms
itr #19: 1144ms
itr #20: 1166ms
itr #21: 1171ms
itr #22: 1169ms
itr #23: 1149ms
itr #24: 1146ms
itr #25: 1174ms

After

itr #1: 1443ms
itr #2: 1135ms
itr #3: 1131ms
itr #4: 1149ms
itr #5: 1143ms
itr #6: 1130ms
itr #7: 1136ms
itr #8: 1150ms
itr #9: 1164ms
itr #10: 1134ms
itr #11: 1134ms
itr #12: 1178ms
itr #13: 1127ms
itr #14: 1134ms
itr #15: 1109ms
itr #16: 1110ms
itr #17: 1155ms
itr #18: 1140ms
itr #19: 1130ms
itr #20: 1150ms
itr #21: 1163ms
itr #22: 1155ms
itr #23: 1144ms
itr #24: 1165ms
itr #25: 1130ms

@k0kubun k0kubun marked this pull request as ready for review November 11, 2022 00:10
@matzbot matzbot requested a review from a team November 11, 2022 00:10
yjit/src/stats.rs Outdated Show resolved Hide resolved
Copy link
Member

@XrXr XrXr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you can get the stats without a region by calling GLOBAL_ALLOCATOR.stats(). If that works it should simplify the code a lot.

@k0kubun
Copy link
Member Author

k0kubun commented Nov 11, 2022

Indeed 9c3c0b3. Thank you for the finding. This seems to return the same number.

@maximecb maximecb merged commit 6246788 into ruby:master Nov 13, 2022
@maximecb maximecb deleted the yjit-stats-alloc branch November 13, 2022 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants