Mark-Sweep's Top Memory Fragmentation Pitfall
The Mark-and-Sweep garbage collection algorithm is notorious for causing memory fragmentation, where reachable objects become separated by many small, unused memory regions, potentially leading to 'OutOfMemory' errors even when sufficient total free memory exists, severely degrading performance in scarce memory environments.
The top 3
- External Fragmentation: Mark-Sweep's Primary Foe: Mark-Sweep garbage collection primarily suffers from *external fragmentation*, where free memory is scattered in small, non-contiguous blocks, preventing the allocation of large objects despite sufficient total free space.
- Fragmentation's Dual Performance Hit: Latency & Cache: Memory fragmentation in Mark-Sweep significantly impacts performance by increasing allocation latency as allocators search for suitable free blocks, and by degrading cache efficiency due to non-contiguous data access, potentially causing 50 ns hits for new RAM row access.
- Compaction: The Top Fix for Mark-Sweep Fragmentation: The leading solution to Mark-Sweep's memory fragmentation is *compaction* (Mark-Compact), which involves relocating live objects to contiguous memory blocks, thereby consolidating free space, although this phase is notably expensive in terms of time and resources.
Sources
Open the full topic