|
L4Re Operating System Framework
Interface and Usage Documentation
|
Buddy allocator backed by a perfect binary tree. More...
#include <buddy_alloc>
Public Member Functions | |
| void | init (l4_addr_t min_addr, l4_addr_t max_addr, unsigned char *metadata_addr, size_t metadata_size) |
| Initialize the allocator. | |
| void | add_mem (void *mem, size_t size) |
| Add memory to the allocator. | |
| void * | alloc (size_t size, size_t align, l4_addr_t lower=0, l4_addr_t upper=~0UL) |
| Allocate a memory block. | |
| void * | alloc_max (size_t min, size_t *max, size_t align, size_t granularity, l4_addr_t lower=0, l4_addr_t upper=~0UL) |
| Allocate a memory block of min <= size <= max. | |
| void | free (void *block, size_t size) |
| Return a free memory block to the allocator. | |
| size_t | avail () const |
| Get the amount of available memory. | |
Static Public Member Functions | |
| static constexpr size_t | metadata_bytes (l4_addr_t min_addr, l4_addr_t max_addr) |
| Return metadata size in bytes required by the buddy allocator. | |
Buddy allocator backed by a perfect binary tree.
The root node of the tree spans the entire memory area managed by the allocator and represents the largest block size supported by the allocator. Each subsequent level of the tree halves the block size until reaching the minimum block size.
Each node in the tree stores the largest order of block that can be allocated at or underneath it:
An completely unallocated tree with four levels would look like:
After allocating a block of 2 * Min_size:
Definition at line 56 of file buddy_alloc.
|
inline |
Add memory to the allocator.
| mem | Pointer to the memory. |
| size | Size of the memory. |
Definition at line 1307 of file buddy_alloc.
References L4_UNLIKELY.
|
inline |
Allocate a memory block.
| size | Size of the memory block. |
| align | Alignment constraint (must be a power of two). |
| lower | Lower bound of the physical region the memory block should be allocated from. |
| upper | Upper bound of the physical region the memory block should be allocated from, value is inclusive. |
| nullptr | Allocation failed. |
Definition at line 1351 of file buddy_alloc.
References L4_LIKELY, and L4_UNLIKELY.
|
inline |
Allocate a memory block of min <= size <= max.
| min | Minimal size to allocate (in bytes). | |
| [in,out] | max | Maximum size to allocate (in bytes). The actual allocated size is returned here. |
| align | Alignment constraint (must be a power of two). | |
| granularity | Granularity to use for the allocation (power of 2). | |
| lower | Lower bound of the physical region the memory block should be allocated from. | |
| upper | Upper bound of the physical region the memory block should be allocated from, value is inclusive. |
| nullptr | Allocation failed. |
Definition at line 1404 of file buddy_alloc.
References L4_LIKELY, and L4_UNLIKELY.
|
inline |
Get the amount of available memory.
Definition at line 1611 of file buddy_alloc.
References avail(), and L4_UNLIKELY.
Referenced by avail().
|
inline |
Return a free memory block to the allocator.
| block | Pointer to memory block. |
| size | Size of memory block. |
Definition at line 1500 of file buddy_alloc.
References L4_UNLIKELY.
|
inline |
Initialize the allocator.
| min_addr | Minimum address covered by the allocator. |
| max_addr | Maximum address covered by the allocator (inclusive). |
| metadata_addr | Pointer to metadata memory chunk for the allocator. |
| metadata_size | Size of the metadata memory chunk. |
Definition at line 139 of file buddy_alloc.
References metadata_bytes().
|
inlinestaticconstexpr |
Return metadata size in bytes required by the buddy allocator.
| min_addr | Minimum address covered by the allocator. |
| max_addr | Maximum address covered by the allocator (inclusive). |
Definition at line 124 of file buddy_alloc.
Referenced by init().