Skip to main content
Engineering LibreTexts

7.4.3: Buddy System

  • Page ID
    48688
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Buddy System – Memory allocation technique

    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

    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 

    Capture-34.png
    Figure \(\PageIndex{1}\): Buddy System Partitioning
    ("Buddy System Partitioning" by Samit MandalGeeks for Geeks is licensed under CC BY-SA 4.0)


    So, size of partition for 18 KB process = 32 KB. It divides by 2, till possible to get minimum block to fit 18 KB.

    Adapted from:
    "Buddy System – Memory allocation technique" by Samit MandalGeeks for Geeks is licensed under CC BY-SA 4.0


    7.4.3: Buddy System is shared under a not declared license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?