#include <stdio.h>
#include <stdlib.h>
#include "buddy.h"
#include "list.h"
Go to the source code of this file.
◆ ADDR_TO_PAGE
| #define ADDR_TO_PAGE |
( |
|
addr | ) |
((unsigned long)((void *)addr - (void *)g_memory) / PAGE_SIZE) |
◆ BUDDY_ADDR
| #define BUDDY_ADDR |
( |
|
addr, |
|
|
|
o |
|
) |
| |
Value: (
void *)((((
unsigned long)addr - (
unsigned long)
g_memory) ^ (1<<o)) \
Definition at line 35 of file buddy.c.
◆ IFDEBUG
◆ MAX_ORDER
◆ MIN_ORDER
◆ PAGE_SIZE
◆ PAGE_TO_ADDR
◆ PDEBUG
| #define PDEBUG |
( |
|
fmt, |
|
|
|
... |
|
) |
| |
◆ USE_DEBUG
◆ buddy_alloc()
| 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.
- Parameters
-
- Returns
- memory block address
Definition at line 110 of file buddy.c.
◆ buddy_dump()
Print the buddy system status—order oriented
print free pages in each order.
Definition at line 135 of file buddy.c.
◆ buddy_free()
| 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.
- Parameters
-
| addr | memory block address to be freed |
Definition at line 125 of file buddy.c.
◆ buddy_init()
Initialize the buddy system
Definition at line 79 of file buddy.c.
◆ free_area
◆ g_memory
◆ g_pages