Regionlist overhaul: Refactor regionlist cram calculation

parent 47ae3641
......@@ -103,29 +103,45 @@ do { \
regionlist_onlystk_add(name, o, s); \
} while(0)
static struct regl *
regl_alloc_bits(buddy_t *membuddy, const uint8_t bits, int8_t cram,
struct regionlist **rlp)
static uint8_t regl_minbits;
static void __attribute__((constructor))
init_regl(void)
{
struct buddy_ptr_page alloc;
struct regionlist *rl;
struct regl *r;
int8_t c;
size_t sz, b;
unsigned b =
log2up(2 * sizeof(struct regl) + sizeof(struct regionlist));
assert(b <= UINT8_MAX);
regl_minbits = (typeof(regl_minbits))b;
}
sz = 2 * sizeof *r + sizeof *rl;
b = log2up(sz);
assert(bits >= b);
static int8_t
regl_cram(const uint8_t bits, int8_t cram)
{
int8_t c;
assert(bits > regl_minbits);
// should we also support negative cram?
assert(cram >= 0);
assert(bits < INT8_MAX);
c = (int8_t)(bits - (typeof(bits))b);
c = (int8_t)(bits - regl_minbits);
assert(c >= 0);
if (cram > c)
cram = c;
alloc = buddy_alloc1_ptr_page_wait(membuddy, FEP_MEM_FREE, bits, cram);
return (cram);
}
static struct regl *
regl_alloc_bits(buddy_t *membuddy, const uint8_t bits, int8_t cram,
struct regionlist **rlp)
{
struct buddy_ptr_page alloc;
struct regionlist *rl;
struct regl *r;
size_t sz, b;
alloc = buddy_alloc1_ptr_page_wait(membuddy, FEP_MEM_FREE, bits,
regl_cram(bits, cram));
AN(alloc.ptr);
sz = (size_t)1 << alloc.bits;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment