Add test and remove code comments

This commit is contained in:
2024-04-20 20:41:06 +02:00
parent 3acc0a80a8
commit 457bc24019
5 changed files with 91 additions and 99 deletions
+17 -15
View File
@@ -1,23 +1,25 @@
#include <stddef.h>
#include <stdint.h>
#define BUDDY_ALLOC_MAX_BLOCK_LOG2 12
#define BUDDY_ALLOC_MIN_BLOCK_LOG2 8
#define BUDDY_ALLOC_MAX_BLOCK_LOG2 13
#define BUDDY_ALLOC_MIN_BLOCK_LOG2 3
_Static_assert(BUDDY_ALLOC_MIN_BLOCK_LOG2 <= BUDDY_ALLOC_MAX_BLOCK_LOG2);
_Static_assert(BUDDY_ALLOC_MIN_BLOCK_LOG2 > 2);
#define BUDDY_ALLOC_NUM_LISTS (BUDDY_ALLOC_MAX_BLOCK_LOG2 - BUDDY_ALLOC_MIN_BLOCK_LOG2 + 1)
/*
* To keep track of the allocation state of a page,
* we need one bit for each possible block that can
* be made out of it. For instance, if the page can
* only be allocated in its entirety, 1 bit is required.
* If the blocks halfs can be allocated too, 3 bits
* are required: 1 for the page, 1 for the frist half
* and 1 for the second half. Allowing the allocation
* of page quarters requires 4 more bits, for a total
* of 7. In general, if we allow splitting a page N
* times (N=0 means only the entire page can be allocated),
* then 2^(N+1)-1 bits are necessary.
*/
// To keep track of the allocation state of a page,
// we need one bit for each possible block that can
// be made out of it. For instance, if the page can
// only be allocated in its entirety, 1 bit is required.
// If the blocks halfs can be allocated too, 3 bits
// are required: 1 for the page, 1 for the frist half
// and 1 for the second half. Allowing the allocation
// of page quarters requires 4 more bits, for a total
// of 7. In general, if we allow splitting a page N
// times (N=0 means only the entire page can be allocated),
// then 2^(N+1)-1 bits are necessary.
#define BUDDY_ALLOC_BITS_PER_PAGE ((1U << (BUDDY_ALLOC_NUM_LISTS)) - 1)
#define BUDDY_ALLOC_WORDS_PER_PAGE ((BUDDY_ALLOC_BITS_PER_PAGE + 31) / 32)