From "The Art of Computer Programming"
🎧 Listen to Summary
Free 10-min PreviewLiberation Strategies and Coalescing
Key Insight
The inverse problem to reservation is liberation: returning unused blocks to the available space list. Simply using garbage collection, which only acts when space runs out, is often not recommended. This is because it requires stringent pointer discipline, can be slow when memory is nearly full, and crucially, perpetuates memory fragmentation. If two adjacent memory areas become free, but are not immediately merged, garbage collection can leave memory more broken up than it should be, hindering the allocation of larger contiguous blocks later.
To counter fragmentation, a preferred strategy is to return blocks to the AVAIL list as soon as they become free and immediately coalesce adjacent available areas. When a block is freed, the system must determine if the areas on either side are also available. If they are, all three areas should be merged into a single, larger available block. This collapsing problem is key to maintaining a good balance in memory over time. Algorithm B addresses this by maintaining the AVAIL list in order of increasing memory locations. When block 'P0' of size 'N' is freed, the algorithm searches for its insertion point and then checks adjacent blocks for merging based on their memory addresses and sizes.
While Algorithm B improves search efficiency, extensive searching can still be slow for long AVAIL lists. Algorithm C (Liberation with boundary tags) offers a significant improvement by virtually eliminating search time during liberation. It assumes each block has a TAG field at both ends and a SIZE field at its beginning. Available blocks are doubly linked for efficient deletion. When block 'P0' is freed, the system checks TAG(P0-1) and TAG(P0+SIZE(P0)). If adjacent blocks are available, they are removed from their respective available lists, their sizes are added to 'P0''s size, and 'P0' is updated to represent the merged larger block, which is then added to the doubly linked available list, ensuring rapid coalescing.
📚 Continue Your Learning Journey — No Payment Required
Access the complete The Art of Computer Programming summary with audio narration, key takeaways, and actionable insights from Donald E. Knuth.