ROSS
Data Structures | Macros | Typedefs | Enumerations | Functions
buddy.h File Reference

Buddy-system memory allocator. More...

#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_tcreate_buddy_table (unsigned int power_of_two)
 
void * buddy_alloc (unsigned size)
 
void buddy_free (void *ptr)
 

Macro Definition Documentation

#define BUDDY_ALIGN_PREF   (32 - 2 * sizeof(void*) - sizeof(uint32_t) - sizeof(purpose_t))

Definition at line 13 of file buddy.h.

Typedef Documentation

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.

typedef enum purpose purpose_t
typedef enum valid valid_t

Enumeration Type Documentation

enum purpose
Enumerator
FREE 
USED 

Definition at line 11 of file buddy.h.

enum valid
Enumerator
VALID 
INVALID 

Definition at line 30 of file buddy.h.

Function Documentation

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.

Parameters
sizeThe 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().

Here is the call graph for this function:

Here is the caller graph for this function:

void buddy_free ( void *  ptr)

Free the given pointer (and coalesce it with its buddy if possible).

Parameters
ptrThe 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().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
power_of_twoThe 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().

Here is the call graph for this function:

Here is the caller graph for this function: