19 #define B_TOTAL_EXP 16U
20 #define B_BLOCK_EXP 6U
22 #define next_exp_of_2(i) (sizeof(i) * CHAR_BIT - intrinsics_clz(i))
23 #define buddy_allocation_block_compute(req_size) next_exp_of_2(max(req_size, 1U << B_BLOCK_EXP) - 1);
25 #define buddy_left_child(i) (((i) << 1U) + 1U)
26 #define buddy_right_child(i) (((i) << 1U) + 2U)
27 #define buddy_parent(i) ((((i) + 1) >> 1U) - 1U)
33 alignas(16) uint8_t
longest[(1U << (B_TOTAL_EXP - B_BLOCK_EXP + 1))];
35 alignas(16)
unsigned char base_mem[1U << B_TOTAL_EXP];
40 (1 << (B_TOTAL_EXP - 2 * B_BLOCK_EXP + 1)) +
42 (1 << (B_TOTAL_EXP - B_BLOCK_EXP))
51 "longest and base_mem are not contiguous, this will break incremental checkpointing");
54 extern void *buddy_malloc(
struct buddy_state *
self, uint_fast8_t req_blks_exp);
55 extern uint_fast32_t buddy_free(
struct buddy_state *
self,
void *ptr);
60 int_fast32_t variation;
61 uint_fast32_t original;
65 extern void buddy_dirty_mark(
struct buddy_state *
self,
const void *ptr,
size_t s);
unsigned char block_bitmap
The type of a generic bitmap.
Definition: bitmap.h:22
#define bitmap_required_size(requested_bits)
Computes the required size of a bitmap.
Definition: bitmap.h:63
The checkpointable memory context of a single buddy system.
Definition: buddy.h:30
block_bitmap dirty[bitmap_required_size((1<<(B_TOTAL_EXP - 2 *B_BLOCK_EXP+1))+(1<<(B_TOTAL_EXP - B_BLOCK_EXP)))]
Keeps track of memory blocks which have been dirtied by a write.
Definition: buddy.h:44
uint8_t longest[(1U<<(B_TOTAL_EXP - B_BLOCK_EXP+1))]
The checkpointed binary tree representing the buddy system.
Definition: buddy.h:33
unsigned char base_mem[1U<< B_TOTAL_EXP]
The memory buffer served to the model.
Definition: buddy.h:35