60 likes | 263 Views
Memory Blocks in a Buddy System - Buddy Systems (2). In a buddy system, memory blocks are available of size 2 k , L <= K <= U, where: 2 L = smallest block that is allocated. 2 U = largest size block that is allocated.
E N D
Memory Blocks in a Buddy System- Buddy Systems (2) • In a buddy system, memory blocks are available of size 2k, L <= K <= U, where: 2L = smallest block that is allocated. 2U = largest size block that is allocated. • Generally, 2U is the size of the entire memory available for allocation.
Allocation Method - Buddy Systems (3) • To begin, the entire space available for allocation is treated as a single block of size 2U. If a request of size that 2 U-1 < s <= 2U is made, then the entire block is allocated. • Otherwise, the block is split into two equal buddies of size 2 U-1. If 2 U-2 < s<= 2U-1, then the request is allocated to one of the two buddies. • Otherwise, one of the buddies is split in half again. • This process continues until the smallest block greater than or equal to s is generated and allocated to the request.
Remove Unallocated Blocks - Buddy Systems (4) • At any time, the buddy system maintains a list of holes (unallocated blocks) of each size 2 i. • A hole may be removed from the (i + 1) list by splitting it in half to create two buddies of size 2i in the i list. • Whenever a pair of buddies on the i list both become unallocated, they are removed from that list and coalesced into a single block on the • (i + 1) list.
Example of Buddy System- Buddy Systems (5) 1 Megabyte Block 1M Request 100K (A) A=128K 128K 256K 512K Request 240K (B) A=128K 128K B=256K 512K Request 256K (D) A=128K 128K B=256KD=256K 256K Release B A=128K 128K 256K D=256K 256K Release A 512K D=256K 256K Request 75K (E) E=128K 128K 256K D=256K 256K Release E 512K D=256K 256K Release D 1M
Tree Representation of Buddy System- Buddy Systems (6) 1M 512K 256K 128K A=128K 128K B=256KD=256K 256K