Buddy memory management

from Wikipedia, the free encyclopedia

The buddy memory management ( Buddy . Engl for "buddy") refers to the buddy method by Donald Ervin Knuth , a technique for allocation of memory to processes . The process is simple and easy to implement.

function

The memory is divided into areas with a length of 2 k . At the beginning there is only one block that covers the entire memory if possible; if the size of the memory cannot be expressed as a power of two, it can also be several blocks of different sizes. If a process requests a certain amount of memory, it is rounded up to the next higher power of two and a corresponding block is sought. If a block of this size does not yet exist, a double-size block is searched for, which is then split into two halves (or buddies ), and one of these blocks is assigned to the process. If there is also no block of double size, a block of four times the size is searched for, etc. As soon as memory is released again, a check is made whether two buddies of the same size resulting from the division can be combined again into a larger block.

Advantages and disadvantages

The advantage of this memory management is that it is easy to implement. It does not require any special hardware support, such as B. is the case when paging current operating systems .

The disadvantage is that there can be both internal and external fragmentation . The type of allocation can also waste memory, but this can be limited by specifying the smallest block size.

Extensions

The weighted buddy memory management is an extension. This is not always divided in a ratio of 1: 1, but for example in a ratio of 1: 3, with the second branch then being divided in a ratio of 1: 2. This results in more different buddy sizes. In return, however, the administrative effort becomes higher and the address calculation becomes more difficult.

literature