mmtk / mmtk-core

Memory Management ToolKit
https://www.mmtk.io
Other
379 stars 69 forks source link

PrepareChunkMap (mark-sweep) unnecessarily clearing mark bits of all chunks #1144

Closed wks closed 5 months ago

wks commented 5 months ago

https://github.com/mmtk/mmtk-core/blob/401803ce44d851c19e4d04f152b494095f9b71e6/src/policy/marksweepspace/native_ms/global.rs#L435-L437

Each PrepareChunkMap work packet for native_ms is supposed to initialize the chunk-level metadata for a single chunk. But the code shown above clears the side mark bits for all blocks. This is totally unnecessary, and is taking up a considerable amount of time during a GC.

image

The problem becomes more serious when I changed the native MarkSweepSpace to use BlockPageResource instead of the raw FreeListPageResource. The reason may be that BlockPageResource caches blocks in the block queue, and releases chunks lazily, resulting in a higher number of allocated chunks during each GC.

(p.s. ReleaseMutator becomes faster because BlockPageResource::release_block is lock-free, while FreeListPageResource::release_pages needs a mutex to work, which is bad for parallel GC. See: https://github.com/mmtk/mmtk-core/issues/1145)

image

It should only clear the side metadata for the single chunk that the work packet is responsible for.

qinsoon commented 5 months ago

Yeah. That code is a clear bug. I guess I simply moved the mark bit clearing code from the plan's prepare to PrepareChunkMap without realizing that PrepareChunkMap is per chunk.