Regionlist overhaul: Refactor regionlist cram calculation

parent 47ae3641
...@@ -103,29 +103,45 @@ do { \ ...@@ -103,29 +103,45 @@ do { \
regionlist_onlystk_add(name, o, s); \ regionlist_onlystk_add(name, o, s); \
} while(0) } while(0)
static struct regl * static uint8_t regl_minbits;
regl_alloc_bits(buddy_t *membuddy, const uint8_t bits, int8_t cram, static void __attribute__((constructor))
struct regionlist **rlp) init_regl(void)
{ {
struct buddy_ptr_page alloc; unsigned b =
struct regionlist *rl; log2up(2 * sizeof(struct regl) + sizeof(struct regionlist));
struct regl *r;
int8_t c; assert(b <= UINT8_MAX);
size_t sz, b; regl_minbits = (typeof(regl_minbits))b;
}
sz = 2 * sizeof *r + sizeof *rl; static int8_t
b = log2up(sz); regl_cram(const uint8_t bits, int8_t cram)
assert(bits >= b); {
int8_t c;
assert(bits > regl_minbits);
// should we also support negative cram? // should we also support negative cram?
assert(cram >= 0); assert(cram >= 0);
assert(bits < INT8_MAX); assert(bits < INT8_MAX);
c = (int8_t)(bits - (typeof(bits))b); c = (int8_t)(bits - regl_minbits);
assert(c >= 0); assert(c >= 0);
if (cram > c) if (cram > c)
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); AN(alloc.ptr);
sz = (size_t)1 << alloc.bits; 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