Buddy-system memory allocator.
#include <stdint.h>#include <sys/queue.h>Go to the source code of this file.
Data Structures | |
| struct | buddy_list |
| struct | buddy_list_bucket |
Macros | |
| #define | BUDDY_ALIGN_PREF (32 - 2 * sizeof(void*) - sizeof(uint32_t) - sizeof(purpose_t)) |
Typedefs | |
| typedef enum purpose | purpose_t |
| typedef struct buddy_list | buddy_list_t |
| typedef enum valid | valid_t |
| typedef struct buddy_list_bucket | buddy_list_bucket_t |
Enumerations | |
| enum | purpose { FREE , USED } |
| enum | valid { VALID , INVALID } |
Functions | |
| buddy_list_bucket_t * | create_buddy_table (unsigned int power_of_two) |
| void * | buddy_alloc (unsigned size) |
| void | buddy_free (void *ptr) |
| #define BUDDY_ALIGN_PREF (32 - 2 * sizeof(void*) - sizeof(uint32_t) - sizeof(purpose_t)) |
| typedef struct buddy_list_bucket buddy_list_bucket_t |
Bucket of 2^order sized free memory blocks.
| typedef struct buddy_list buddy_list_t |
Metadata about this particular block (and stored at the beginning of this block). One per allocated block of memory. Should be 32 bytes to not screw up alignment.
| void * buddy_alloc | ( | unsigned | size | ) |
Find the smallest block that will contain size and return it. Note this returns the memory allocated and usable, not the entire buffer. This may involve breaking up larger blocks.
| size | The size of the data this allocation must be able to hold. |
Definition at line 234 of file buddy.c.
References buddy_split(), buddy_list_bucket::count, g_tw_buddy_master, INVALID, buddy_list_bucket::is_valid, next_power2(), buddy_list_bucket::order, tw_error(), TW_LOC, buddy_list::use, and USED.
Referenced by tw_snapshot_delta().
| void buddy_free | ( | void * | ptr | ) |
Free the given pointer (and coalesce it with its buddy if possible).
| ptr | The pointer to free. |
Definition at line 137 of file buddy.c.
References buddy_try_merge(), buddy_list_bucket::count, FREE, g_tw_buddy_master, buddy_list_bucket::order, buddy_list::size, TW_LOC, tw_printf(), buddy_list::use, and USED.
Referenced by tw_event_free(), tw_event_rollback(), and tw_eventq_push_list().
| buddy_list_bucket_t * create_buddy_table | ( | unsigned int | power_of_two | ) |
Pass in the power of two e.g., passing 5 will yield 2^5 = 32.
| power_of_two | The largest "order" this table will support. |
<Minimum block order
<Minimum block order
<Minimum block order
<Minimum block order
Definition at line 288 of file buddy.c.
References buddy_base_address, BUDDY_BLOCK_ORDER, buddy_list_bucket::count, FREE, INVALID, buddy_list_bucket::is_valid, buddy_list_bucket::order, buddy_list::size, tw_calloc(), TW_LOC, buddy_list::use, and VALID.
Referenced by setup_pes().