Skip to content
Related Articles
Open in App
Not now

Related Articles

Buddy System – Memory allocation technique

Improve Article
Save Article
  • Difficulty Level : Medium
  • Last Updated : 01 Mar, 2023
Improve Article
Save Article

Prerequisite – Partition Allocation Methods Static partition schemes suffer from the limitation of having the fixed number of active processes and the usage of space may also not be optimal. The buddy system is a memory allocation and management algorithm that manages memory in power of two increments. Assume the memory size is 2U, suppose a size of S is required.

  • If 2U-1<S<=2U: Allocate the whole block
  • Else: Recursively divide the block equally and test the condition at each time, when it satisfies, allocate the block and get out the loop.

System also keep the record of all the unallocated blocks each and can merge these different size blocks to make one big chunk. Advantage –

  • Easy to implement a buddy system
  • Allocates block of correct size
  • It is easy to merge adjacent holes
  • Fast to allocate memory and de-allocating memory
  • Provides good memory utilization as it allocates memory blocks of the correct size and prevents unnecessary memory wastage, unlike other allocation techniques that allocate memory blocks larger than required.
  • Offers a relatively simple and efficient way to manage memory allocation in systems that require dynamic memory allocation, such as embedded systems and operating systems.
  • Can handle a large number of small memory allocations efficiently due to its block division mechanism, which helps prevent fragmentation and maintains system performance.
  • Can prevent memory leaks by ensuring that all allocated memory is deallocated when it’s no longer in use, which can improve system stability and reliability.
    Provides a high level of flexibility in managing memory allocation and usage, which is particularly useful in systems that require frequent memory allocation and deallocation, such as real-time systems.

Disadvantage –

  • It requires all allocation unit to be powers of two
  • It leads to internal fragmentation

Example – Consider a system having buddy system with physical address space 128 KB.Calculate the size of partition for 18 KB process. Solution – So, size of partition for 18 KB process = 32 KB. It divides by 2, till possible to get minimum block to fit 18 KB.

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!