Simplify allocation in fellow_cache_obj_new()

the disk object is always a multiple of 4K, and for higher values (like
12K), rounding up to the next power of two does not make sense.

So, just use two allocations for FCO and FDO always.
parent eb6bd99e
......@@ -1893,8 +1893,6 @@ fellow_cache_seglists_load(const struct fellow_cache *fc,
* second part fits in the same LOG2UP or not
*
* XXX
* - use two allocations always?
* - use struct reqs?
* - collapse allocation with fellow_budy_obj_alloc?
*/
......@@ -1906,10 +1904,10 @@ fellow_cache_obj_new(struct fellow_cache *fc,
struct fellow_cache_obj *fco;
struct fellow_cache_res fcr;
struct fellow_cache_seg *fcs;
struct buddy_reqs *reqs;
struct buddy_ptr_page fco_mem = buddy_ptr_page_nil;
struct buddy_ptr_extent fdo_mem = buddy_ptr_extent_nil;
size_t asz, mem_sz, ssz;
uint8_t bits;
unsigned u;
DBG("arg dsk_sz %zu nseg_guess %u", dsk_sz, nseg_guess);
......@@ -1926,40 +1924,30 @@ fellow_cache_obj_new(struct fellow_cache *fc,
}
mem_sz = sizeof *fco + nseg_guess * sizeof *fcs;
asz = (size_t)1 << log2up(dsk_sz);
// DBG("dsk_sz %zu nseg_guess %u mem_sz %zu asz %zu",
// dsk_sz, nseg_guess, mem_sz, asz);
reqs = BUDDY_REQS_STK(fc->membuddy, 2);
BUDDY_REQS_PRI(reqs, pri);
AN(buddy_req_page(reqs, log2up(mem_sz), 0));
AN(buddy_req_extent(reqs, asz, 0));
fco = NULL;
if (dsk_sz + mem_sz > asz) {
// fco etc in extra allocation
u = log2up(mem_sz);
assert(u <= UINT8_MAX);
bits = (uint8_t)u;
fco_mem = buddy_alloc1_ptr_page_wait(fc->membuddy,
pri, bits, 0);
if (FC_INJ || fco_mem.ptr == NULL) {
fcr = FCR_ALLOCFAIL("fco_mem alloc failed");
goto err;
}
fco = fco_mem.ptr;
asz = dsk_sz;
u = buddy_alloc_wait(reqs);
if (FC_INJ || u != 2) {
buddy_alloc_wait_done(reqs);
fcr = FCR_ALLOCFAIL("fellow_cache_obj_new alloc failed");
goto err;
}
fdo_mem = buddy_alloc1_ptr_extent_wait(fc->membuddy,
pri, asz, 0);
fco_mem = buddy_get_ptr_page(reqs, 0);
fdo_mem = buddy_get_ptr_extent(reqs, 1);
if (FC_INJ || fdo_mem.ptr == NULL) {
fcr = FCR_ALLOCFAIL("fdo_mem alloc failed");
goto err;
}
buddy_alloc_wait_done(reqs);
fdo = fdo_mem.ptr;
AN(fdo);
if (fco == NULL)
fco = (void *)((unsigned char *)fdo + dsk_sz);
fco = fco_mem.ptr;
AN(fco);
INIT_OBJ(fco, FELLOW_CACHE_OBJ_MAGIC);
DBG("fco %p", fco);
......@@ -1969,16 +1957,7 @@ fellow_cache_obj_new(struct fellow_cache *fc,
AZ(pthread_mutex_init(&fco->mtx, &fc_mtxattr_errorcheck));
AZ(pthread_cond_init(&fco->cond, NULL));
if (fco_mem.bits) {
ssz = ((size_t)1 << fco_mem.bits) - sizeof *fco;
}
else {
ssz = fdo_mem.size;
assert(ssz > dsk_sz);
ssz -= dsk_sz;
assert(ssz > sizeof *fco);
ssz -= sizeof *fco;
}
ssz = ((size_t)1 << fco_mem.bits) - sizeof *fco;
fellow_cache_seglist_init(&fco->seglist, ssz, fco);
......@@ -1993,10 +1972,8 @@ fellow_cache_obj_new(struct fellow_cache *fc,
return (FCR_OK(fco));
err:
if (fco_mem.ptr != NULL)
buddy_return1_ptr_page(fc->membuddy, &fco_mem);
if (fdo_mem.ptr != NULL)
buddy_return1_ptr_extent(fc->membuddy, &fdo_mem);
AZ(fco_mem.ptr);
AZ(fdo_mem.ptr);
fellow_cache_res_check(fc, fcr);
return (fcr);
......
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