Relates :
|
|
Relates :
|
In metaspace.cpp, ChunkManager keeps counters for the number of free chunks in all its free lists (_free_chunks_count) and combined size of all these chunks (_free_chunks_total). These counters are updated using Atomics. Supposedly because atomic updates are expensive, updates are delayed as much as possible. When returning chunks to the free list, instead of updating the counter for every returned chunk, the counter is updated for all chunks at once (~SpaceManager). This introduces time windows where the counters do not reflect the real state of the freelist, which makes it difficult to verify the internal state of the ChunkManager. The counters do not have to be updated atomically, because all accesses happen under lock protection. So the updates can be moved closer to the chunk return point and the window where counters are invalid almost disappears, making the code easier.