Presentation is loading. Please wait.

Presentation is loading. Please wait.

Memory Blocks in a Buddy System - Buddy Systems (2)

Similar presentations


Presentation on theme: "Memory Blocks in a Buddy System - Buddy Systems (2)"— Presentation transcript:

1 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.

2 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.

3 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.

4 Example of Buddy System - Buddy Systems (5)
1 Megabyte Block M Request 100K (A) A=128K 128K K K Request 240K (B) A=128K K B=256K K Request 256K (D) A=128K K B=256K D=256K K Release B A=128K K K D=256K K Release A K D=256K K Request 75K (E) E=128K 128K K D=256K K Release E K D=256K K Release D M

5 Tree Representation of Buddy System - Buddy Systems (6)
512K 256K 128K A=128K 128K B=256K D=256K K


Download ppt "Memory Blocks in a Buddy System - Buddy Systems (2)"

Similar presentations


Ads by Google