fellow_disk_obj: trim memory objects

Conflicts:
	src/fellow_cache.c
parent 0c4182ed
......@@ -596,6 +596,10 @@ struct fellow_disk_obj {
#define fellow_disk_obj_fdsl(fdo) \
(void *)((uint8_t *)fdo + sizeof *fdo + fdo->va_data_len)
#define fellow_disk_obj_size(fdo, fdsl) \
(sizeof *fdo + fdo->va_data_len + \
sizeof *fdsl + fdsl->lsegs * sizeof *fdsl->segs)
// shaved off one pointer...
#define FCO_FCS(fco) (&(fco)->fdo_fcs)
#define FCO_FDO(fco) fellow_disk_obj(FCO_FCS(fco))
......@@ -649,6 +653,9 @@ struct fellow_cache_obj {
struct fellow_cache_seglist seglist;
};
#define fellow_cache_obj_size(fco) \
(sizeof *fco + (fco)->seglist.lsegs * sizeof *(fco)->seglist.segs)
#define FCR_OK(p)\
(struct fellow_cache_res){.r.ptr = (p), .status = fcr_ok}
#define FCR_ALLOCERR(str)\
......@@ -1080,6 +1087,29 @@ fellow_disk_obj_check(const struct fellow_disk_obj *fdo,
return (NULL);
}
static void
fellow_disk_obj_trim(const struct fellow_cache *fc,
struct fellow_cache_seg *fcs)
{
struct fellow_disk_seglist *fdsl;
struct fellow_disk_obj *fdo;
CHECK_OBJ_NOTNULL(fc, FELLOW_CACHE_MAGIC);
CHECK_OBJ_NOTNULL(fcs, FELLOW_CACHE_SEG_MAGIC);
fdo = fellow_disk_obj(fcs);
CHECK_OBJ_NOTNULL(fdo, FELLOW_DISK_OBJ_MAGIC);
fdsl = fellow_disk_obj_fdsl(fdo);
CHECK_OBJ(fdsl, FELLOW_DISK_SEGLIST_MAGIC);
assert(fdsl->lsegs >= fdsl->nsegs);
fdsl->lsegs = fdsl->nsegs;
buddy_trim1_ptr_extent(fc->membuddy, &fcs->alloc,
fellow_disk_obj_size(fdo, fdsl));
}
/* ============================================================
* cache obj
*/
......@@ -2803,6 +2833,29 @@ fellow_cache_seg_unbusy(struct fellow_busy *fbo, struct fellow_cache_seg *fcs){
fellow_busy_io_submit(fbio);
}
static void
fellow_cache_obj_trim(const struct fellow_cache *fc,
struct fellow_cache_obj *fco)
{
struct fellow_cache_seglist *fcsl;
struct fellow_disk_seglist *fdsl;
CHECK_OBJ_NOTNULL(fc, FELLOW_CACHE_MAGIC);
CHECK_OBJ_NOTNULL(fco, FELLOW_CACHE_OBJ_MAGIC);
fcsl = &fco->seglist;
CHECK_OBJ(fcsl, FELLOW_CACHE_SEGLIST_MAGIC);
fdsl = fcsl->fdsl;
CHECK_OBJ_NOTNULL(fdsl, FELLOW_DISK_SEGLIST_MAGIC);
AZ(fcsl->fcsl_sz);
AZ(fcsl->fdsl_sz);
assert(fcsl->lsegs >= fdsl->nsegs);
fcsl->lsegs = fdsl->nsegs;
buddy_trim1_ptr_extent(fc->membuddy, &fco->fco_mem,
fellow_cache_obj_size(fco));
}
/* XXX can save some io for inlog == 0 */
static void
......@@ -2858,6 +2911,7 @@ fellow_cache_obj_unbusy(struct fellow_busy *fbo, enum fcol_state wantlog)
AZ(pthread_mutex_unlock(&fco->mtx));
fellow_cache_obj_fini(fco);
fellow_cache_obj_trim(fc, fco);
AN(fbio);
fbio->type = FBIO_SEG;
......@@ -2979,6 +3033,9 @@ fellow_cache_async_write_complete(struct fellow_cache *fc,
fcos_next = (typeof(fcos_next))
(FCOS_HIGH(fcs->state) | FCOS_INCORE);
assert_fcos_transition(fcs->state, fcos_next);
if (fcs->state == FCO_WRITING)
fellow_disk_obj_trim(fc, fcs);
} else {
assert(type == FBIO_SEGLIST);
if (result < (int32_t)fbio->u.seglist.reg.size) {
......@@ -5293,6 +5350,8 @@ struct objcore **ocp, uintptr_t priv2, unsigned crit)
if (err != NULL)
goto err;
fellow_disk_obj_trim(fc, fcs);
#define FDO_AUXATTR(U, l) \
fellow_cache_seg_associate(&fco->aa_##l##_seg, \
&fdo->aa_##l##_seg, fdo->aa_##l##_seg.seg.size == 0 ? \
......@@ -5322,6 +5381,7 @@ struct objcore **ocp, uintptr_t priv2, unsigned crit)
if (dowry.bits)
buddy_return1_ptr_page(fc->membuddy, &dowry);
fellow_cache_obj_trim(fc, fco);
return (FCR_OK(fco));
err:
if (ocp) {
......
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