Integrate fellow_busy allocation in fellow_cache_obj_new()

It does not make sense to use up memory for busy objects if we can not
create their cache and disk counterparts in memory.

Motivated by #41
parent ad5d7d0b
......@@ -1919,8 +1919,11 @@ fellow_cache_seglists_load(const struct fellow_cache *fc,
*/
static struct fellow_cache_res
fellow_cache_obj_new(struct fellow_cache *fc,
size_t dsk_sz, unsigned nseg_guess, uint8_t pri)
fellow_cache_obj_new(
struct fellow_cache *fc,
size_t dsk_sz, unsigned nseg_guess,
struct buddy_ptr_extent *fbo_mem,
uint8_t pri)
{
struct fellow_disk_obj *fdo;
struct fellow_cache_obj *fco;
......@@ -1948,13 +1951,15 @@ fellow_cache_obj_new(struct fellow_cache *fc,
mem_sz = sizeof *fco + nseg_guess * sizeof *fcs;
asz = (size_t)1 << log2up(dsk_sz);
reqs = BUDDY_REQS_STK(fc->membuddy, 2);
reqs = BUDDY_REQS_STK(fc->membuddy, 3);
BUDDY_REQS_PRI(reqs, pri);
AN(buddy_req_page(reqs, log2up(mem_sz), 0));
AN(buddy_req_extent(reqs, asz, 0));
if (fbo_mem != NULL)
AN(buddy_req_extent(reqs, sizeof(struct fellow_busy), 0));
u = buddy_alloc_wait(reqs);
if (FC_INJ || u != 2) {
if (FC_INJ || u != (fbo_mem == NULL ? 2 : 3)) {
buddy_alloc_wait_done(reqs);
fcr = FCR_ALLOCFAIL("fellow_cache_obj_new alloc failed");
goto err;
......@@ -1962,6 +1967,8 @@ fellow_cache_obj_new(struct fellow_cache *fc,
fco_mem = buddy_get_ptr_page(reqs, 0);
fdo_mem = buddy_get_ptr_extent(reqs, 1);
if (fbo_mem != NULL)
*fbo_mem = buddy_get_ptr_extent(reqs, 2);
buddy_alloc_wait_done(reqs);
......@@ -2018,17 +2025,6 @@ fellow_busy_obj_alloc(struct fellow_cache *fc,
size_t sz, asz, dsk_sz;
uint16_t ldsegs;
fbo_mem = buddy_alloc1_ptr_extent_wait(fc->membuddy, FEP_NEW,
sizeof *fbo, 0);
fbo = fbo_mem.ptr;
if (fbo == NULL) {
fcr = FCR_ALLOCFAIL("fbo_mem");
fellow_cache_res_check(fc, fcr);
return (fcr);
}
INIT_OBJ(fbo, FELLOW_BUSY_MAGIC);
fbo->fbo_mem = fbo_mem;
// XXX peek for known content-length=
// round up to disk block such that there
......@@ -2062,15 +2058,13 @@ fellow_busy_obj_alloc(struct fellow_cache *fc,
if (fds_seg.off < 0) {
fcr = FCR_ALLOCFAIL("fds region");
fellow_cache_res_check(fc, fcr);
buddy_return1_ptr_extent(fc->membuddy, &fbo->fbo_mem);
return (fcr);
}
fcr = fellow_cache_obj_new(fc, dsk_sz, ldsegs, FEP_NEW);
fcr = fellow_cache_obj_new(fc, dsk_sz, ldsegs, &fbo_mem, FEP_NEW);
if (fcr.status != fcr_ok) {
fellow_cache_res_check(fc, fcr);
fellow_region_free(fc->ffd, &fds_seg);
buddy_return1_ptr_extent(fc->membuddy, &fbo->fbo_mem);
return (fcr);
}
fco = fcr.r.ptr;
......@@ -2079,6 +2073,11 @@ fellow_busy_obj_alloc(struct fellow_cache *fc,
fcs = &fco->fdo_fcs;
CHECK_OBJ(fcs, FELLOW_CACHE_SEG_MAGIC);
fbo = fbo_mem.ptr;
AN(fbo);
INIT_OBJ(fbo, FELLOW_BUSY_MAGIC);
fbo->fbo_mem = fbo_mem;
// disk object in memory
fdo = fcs->alloc.ptr;
memset(fdo, 0, fcs->alloc.size);
......@@ -4623,7 +4622,7 @@ fellow_cache_obj_prepread(struct fellow_cache *fc, fellow_disk_block fdba,
if (! PAOK(sz))
return (FCR_IOFAIL("bad size"));
fcr = fellow_cache_obj_new(fc, sz, 0, crit ? FEP_ITER : FEP_GET);
fcr = fellow_cache_obj_new(fc, sz, 0, NULL, crit ? FEP_ITER : FEP_GET);
if (fcr.status != fcr_ok)
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