Buddy Allocator  0.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
buddy.h File Reference

Go to the source code of this file.


void buddy_init ()
void * buddy_alloc (int size)
void buddy_free (void *addr)
void buddy_dump ()

Function Documentation

void* buddy_alloc ( int  size)

Allocate a memory block.

On a memory request, the allocator returns the head of a free-list of the matching size (i.e., smallest block that satisfies the request). If the free-list of the matching block size is empty, then a larger block size will be selected. The selected (large) block is then splitted into two smaller blocks. Among the two blocks, left block will be used for allocation or be further splitted while the right block will be added to the appropriate free-list.

sizesize in bytes
memory block address

Definition at line 110 of file buddy.c.

void buddy_dump ( )

Print the buddy system status—order oriented

print free pages in each order.

Definition at line 135 of file buddy.c.

void buddy_free ( void *  addr)

Free an allocated memory block.

Whenever a block is freed, the allocator checks its buddy. If the buddy is free as well, then the two buddies are combined to form a bigger block. This process continues until one of the buddies is not free.

addrmemory block address to be freed

Definition at line 125 of file buddy.c.

void buddy_init ( )

Initialize the buddy system

Definition at line 79 of file buddy.c.