Download presentation
Presentation is loading. Please wait.
Published byBerniece Oliver Modified over 9 years ago
1
The buddy memory allocation algorithm Παρουσίαση 11.02.2009: Δρ. Αναγνωστό π ουλος Χρήστος
2
1963, H. Markowitz Easy implementation (80286, …) Little external fragmentation (enough memory is free to satisfy a request, but it is split into chunks none of which is big enough to satisfy the request) Moderate internal fragmentation (the requested memory is a little larger than a small block, but a lot smaller than a large block) Example: Request of 66K of memory would be allocated 128K (waste: 62K memory) Memory allocation in powers of 2, i.e., 2 k, k > 0. The programmer decides on: The upper limit ( u ) of k The lower limit ( l ) of k Example: Memory of 2000K. The u is k = 10, i.e., 2 10 = 1024K –the biggest “allocatable” block. The l is k = 2, i.e., 2 2 = 4K –the smallest “allocatable” block minimizing internal fragmentation and large enough to avoid overhead.
3
Algorithm buddy ( l, u, request) Begin If (memory.request == allocation) Then Lock memory m of size as the minimal 2 k block that is larger than request. size If m is available Then allocate() Else Split free memory m larger than the request. size into half If m.size is the minimal 2 k block and not lower than l Then allocate() Goto::Lock Repeat until m is found Else If (memory.request == free) Then Free memory m While neighbor( m ) == free or m < u Do m = merge( m, neighbor( m )) /* #compaction = log 2 ( u / l )*/ End While End If End.
4
Running Example I: l = 6 that is 2 6 = 64K u = 10 that is 2 10 = 1024K Requests: 0. Program A: 64K 1. Program B: 128K 2. Program C: 64K 3. Program D: 128K 4. Program C: ends 5. Program A: ends 6. Program B: ends 7. Program D: ends ΑΑΒΑ C Β ABDBDD ACBD split freeallocated 1024K ?. Program D: 130K ?. Program C: 503K ?. Program C: 260K
5
Running Example II: l = 6 that is 2 6 = 64K u = 10 that is 2 10 = 1024K Requests: 0. Program A: 100K 1. Program B: 240K 2. Program C: 64K 3. Program D: 256K 4. Program B: ends 5. Program A: ends 6. Request E: 75K 7. Program C: ends 8. Program E: ends 8. Program D: ends Α Α B Α C A AC D freeallocated 1024K B B C C D D C ED ED D
6
The buddy memory allocation algorithm Bib: D. Knuth, “The Art of Computer Programming”, vol. 1, Fundamental Algorithms, 2 nd Ed., 1997, pp. 435-455
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.