Allocation tracker: fix the live heap tracking#453
Conversation
Adjust the bench including absl examples The absl implementation seems to crash on concurrent access
This was causing memory contention for no reason
Use a single hash step for both chunk & slot
Benchmark results for collatzParameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 1 metrics, 0 unstable metrics. See unchanged results
|
Benchmark results for BadBoggleSolver_runParameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 1 metrics, 0 unstable metrics. See unchanged results
|
b2b2c94 to
623cd99
Compare
KowalskiThomas
left a comment
There was a problem hiding this comment.
Haven't reviewed tests yet, will do later!
| // Linear probing to find an empty/deleted slot or the address | ||
| for (unsigned probe = 0; probe < AddressTable::kMaxProbeDistance; ++probe) { |
There was a problem hiding this comment.
I remember yesterday Cursor said it would be smart to do quadratic probing and you seemed to agree, did you eventually decide against it?
There was a problem hiding this comment.
Yes, this was a pretty good suggestion. I will get back to testing this. Though I did want to secure a first fix.
| // Check if slot already contains our address | ||
| if (current == addr) { | ||
| return false; // Already tracked | ||
| } |
There was a problem hiding this comment.
If I understand correctly, we get here if either the current value is not empty/deleted or if CAS failed (and we reloaded the "actual" current value into current after the failed CAS).
What I don't understand is in what case current == addr may be true. From what I gather, it would mean either (1) the memory was previously added into the table before we even tried to insert it (but I don't understand when this would happen) (2) another thread tried to insert the same address we wanted to insert into the table at the same time as we did (but again, I would expect malloc to return each address only to one caller, so I don't understand when this would happen)
I'm definitely not saying this is wrong, I'm just curious to understand why we need it 😅
There was a problem hiding this comment.
I can kind of see a world where we mess up instrumenting a free, so malloc already freed this (but did not remove), then we try to re-add it on subsequent alloc.
I do not really see this as expected though.
So your point might be that we should be watching these more carefully, which is correct.
There was a problem hiding this comment.
Makes sense to me, it probably doesn't hurt (much) to account for this case anyway! Thanks for the explanation.
- Clean unused sampling strategy - Align on naming convention
| // Check if we reached max number of elements | ||
| // Clear elements if we reach too many | ||
| // todo: should we just stop new live tracking (like java) ? | ||
| if (IsDDResOK(push_clear_live_allocation(tl_state))) { |
There was a problem hiding this comment.
We would need to work on the clear strategy.
For now I have to remove this.
The fixed sizes might be too small. I expect some tables will be created with almost nothing, whereas other tables will quickly be filled. |
- Introduce a table for large allocations - Avoid creating tables on the free code path
I added a separate hashmap for mmap allocations. |
- cleanup notes with more accurate numbers on overhead. - cleanup duplicate variable
KowalskiThomas
left a comment
There was a problem hiding this comment.
What I'm seeing makes sense to me with my limited knowledge of ddprof
Approving (but maybe take it with a grain of salt) 🙈
| // Check if slot already contains our address | ||
| if (current == addr) { | ||
| return false; // Already tracked | ||
| } |
There was a problem hiding this comment.
Makes sense to me, it probably doesn't hurt (much) to account for this case anyway! Thanks for the explanation.
|
@nsavoire fyi, when you have some spare time to review 🙇 |
What does this PR do?
Replace the bitset data structure with something that will not suffer from collisions.
Please refer to the
allocation_tracker.mdfile for up to date notes.Motivation
Ensure that allocation tracking is correct.
Additional Notes
NA
How to test the change?
There are benchmarks in this PR. They are mostly generated through AI. I do have some doubts on some of the results.
I did some manual testing to check that overhead seems reasonable.
Next step is end to end testing on real workloads.