Add RUBY_GC_HEAP_INIT_SIZE_%d_SLOTS to pre-init pools granularly#7235
Conversation
peterzhu2118
left a comment
There was a problem hiding this comment.
Can you also add some tests for this?
d270b94 to
65a9ba5
Compare
Yeah definitely, I should have opened this as a draft. I'd like to test this in prod before even considering to merge it. |
|
I've cleaned up the logic and added some very basic tests. I could add some assertions on the pool sizes, but I fear it may be a bit fragile on other arch? @peterzhu2118 if you think it shouldn't be flaky I can add them. |
d831669 to
c6ef500
Compare
|
How would users know which are the possible values of |
It's exposed via >> GC.stat_heap
=>
{0=>{:slot_size=>40, ...},
1=>{:slot_size=>80, ...},
2=>{:slot_size=>160, ...},
3=>{:slot_size=>320, ...},
4=>{:slot_size=>640, ...}} |
|
My question is more about where is this documented. With |
6914a92 to
5ad23a1
Compare
Ok, |
The old RUBY_GC_HEAP_INIT_SLOTS isn't really usable anymore as it initalize all the pools by the same factor, but it's unlikely that pools will need similar sizes. In production our 40B pool is 5 to 6 times bigger than our 80B pool.
5ad23a1 to
2e00076
Compare
|
@casperisfine I was wondering, are there any stats available for size pool occupation (i.e. live objects per pool?) I am not sure how one would now calculate total memory use. Previously this was just the 40B multiple of However, now objects are distributed over a number of pools, and Thank you! |
Yes, it's in |
|
You mean |
|
Yes. |
|
@byroot sorry for my ignorance, but would this actually give me actual memory consumed by the application? Was just looking over https://scoutapm.com/blog/copy-manage-ruby-memory-usage again, and the way I understand eden slots to work is that they may hold a live object, but may also be tagged free. Of course they still consume process memory, but that cannot be attributed to the application if it's unused? So this is still different from the original |
|
Asked differently: I am looking for the per-pool equivalent of: Are you saying |
|
This doesn't sound right @byroot. When booting into an irb: Total live slots across all heaps are about 1/3 of all reported eden slots in pools. So I would conclude these metrics measure different things? |
|
Yeah, sorry.
If that's the answer you are looking for, then slots aren't really what you should look for. You're better to use Now of course this is rather slow, so I don't know if you are trying to do this at runtime with a minimal overhead, in which case, I don't have a solution for you. Even if you had the proper number of slots in use, with their respective sizes, that would still overlook all the memory that is allocated via |
|
I see, thank you. Yes, we are doing this at runtime using an MRI patch that tracks per-thread heap allocations. Previously, it was then trivial (and cheap) to compute per-request memory use like so: The last component, malloc'ed bytes for objects that don't fit an RVALUE slot were tracked in the VM directly. However, this calculation is now wrong (it underestimates live memory), because we don't know anymore how |
Then presumably you should be capable of patching |
|
Presumably. |
The old RUBY_GC_HEAP_INIT_SLOTS isn't really usable anymore as it initialize all the pools by the same factor, but it's unlikely that pools will need similar sizes.
In production our 40B pool is 5 to 6 times bigger than our 80B pool.
cc @peterzhu2118 @eightbitraptor @jasonhl