fellow_cache: refactor fcs extension elements

parent a294a4da
......@@ -346,6 +346,20 @@ static inline uint16_t \
return (uint16_t)sz; \
}
/* type specific union elements of cache segs */
struct fellow_cache_seg_fcs {
size_t len; // FCS_* used size
};
struct fellow_cache_seg_fco {
struct fellow_disk_obj *fdo; // FCO_* ptr to fdo
};
union fellow_cache_seg_ext {
struct fellow_cache_seg_fcs fcs;
struct fellow_cache_seg_fco fco;
};
SEGLIST_FIT_FUNC(disk)
struct fellow_cache_obj;
......@@ -376,10 +390,7 @@ struct fellow_cache_seg {
struct buddy_ptr_extent alloc;
struct fellow_disk_seg *disk_seg;
union {
size_t fcs_len; // FCS_* used size
struct fellow_disk_obj *fco_fdo; // FCO_* ptr to fdo
} u;
union fellow_cache_seg_ext u;
};
/*
......@@ -1196,8 +1207,8 @@ fellow_disk_obj(const struct fellow_cache_seg *fcs)
CHECK_OBJ_NOTNULL(fcs, FELLOW_CACHE_SEG_MAGIC);
assert(FCOS_HIGH(fcs->state) == FCO_HIGH);
if (fcs->alloc.ptr != NULL)
assert(fcs->alloc.ptr == fcs->u.fco_fdo);
return (fcs->u.fco_fdo);
assert(fcs->alloc.ptr == fcs->u.fco.fdo);
return (fcs->u.fco.fdo);
}
static const char *
......@@ -1312,7 +1323,7 @@ fellow_disk_obj_trim(const struct fellow_cache *fc,
buddy_return1_ptr_extent(fc->membuddy,
&fcs->alloc);
fcs->alloc = mem;
fcs->u.fco_fdo = mem.ptr;
fcs->u.fco.fdo = mem.ptr;
break;
}
}
......@@ -1526,7 +1537,7 @@ assert_cache_seg_consistency(const struct fellow_cache_seg *fcs)
#define FCOSA_NOMEM do { \
AZ(fcs->alloc.ptr); \
AZ(fcs->alloc.size); \
AZ(fcs->u.fcs_len); \
AZ(fcs->u.fcs.len); \
} while(0)
#define FCSA_MEM do { \
AN(fcs->alloc.ptr); \
......@@ -1536,7 +1547,7 @@ assert_cache_seg_consistency(const struct fellow_cache_seg *fcs)
/* can be NULL for embedded fdo */ \
if (fcs->alloc.ptr != NULL) { \
AN(fcs->alloc.size); \
assert(fcs->alloc.ptr == fcs->u.fco_fdo); \
assert(fcs->alloc.ptr == fcs->u.fco.fdo); \
} \
} while(0)
#define FDSA_NULL AZ(fcs->disk_seg)
......@@ -1633,7 +1644,7 @@ fellow_cache_seg_free(struct buddy_returns *memret,
AZ(fcs->fcs_onlru);
assert(fcs->refcnt == deref);
fcs->refcnt = 0;
fcs->u.fcs_len = 0;
fcs->u.fcs.len = 0;
/*
* at this point, the fcs is not consistent in all cases, e.g. FCS_EVICT
* has no memory - but this is the point where it does no longer exist
......@@ -2462,7 +2473,7 @@ fellow_cache_obj_new(
fellow_cache_seg_init(fcs, fco, FCO_INIT);
fcs->alloc = fdo_mem;
fcs->u.fco_fdo = fdo;
fcs->u.fco.fdo = fdo;
return (fellow_cache_obj_res(fc, fco, FCR_OK(fco)));
}
......@@ -3130,10 +3141,10 @@ fellow_cache_seg_fini(const struct fellow_cache_seg *fcs)
CHECK_OBJ_NOTNULL(fds, FELLOW_DISK_SEG_MAGIC);
AN(fcs->alloc.ptr);
AN(fcs->u.fcs_len);
assert(fcs->u.fcs_len <= fds->seg.size);
fds->seg.size = fcs->u.fcs_len;
fh(fds->fht, fds->fh, fcs->alloc.ptr, fcs->u.fcs_len);
AN(fcs->u.fcs.len);
assert(fcs->u.fcs.len <= fds->seg.size);
fds->seg.size = fcs->u.fcs.len;
fh(fds->fht, fds->fh, fcs->alloc.ptr, fcs->u.fcs.len);
}
static inline void
......@@ -3257,7 +3268,7 @@ fellow_cache_seg_unbusy(struct fellow_busy *fbo, struct fellow_cache_seg *fcs){
CHECK_OBJ_NOTNULL(fco, FELLOW_CACHE_OBJ_MAGIC);
assert(fco == fbo->fco);
AN(fcs->refcnt);
AN(fcs->u.fcs_len);
AN(fcs->u.fcs.len);
assert_fcos_transition(from, to);
struct fellow_lru_chgbatch lcb[1] =
......@@ -3654,9 +3665,9 @@ fellow_cache_seg_io_check(const struct fellow_cache *fc,
assert(fcs->alloc.size == asz);
AN(fds->seg.off);
AN(fds->seg.size);
assert(fds->seg.size >= fcs->u.fcs_len);
assert(fds->seg.size >= fcs->u.fcs.len);
assert(fds->seg.size <= asz);
fcs->u.fcs_len = fds->seg.size;
fcs->u.fcs.len = fds->seg.size;
// O_DIRECT alignment on 4K
AZ((uintptr_t) fcs->alloc.ptr & FELLOW_BLOCK_ALIGN);
......@@ -3763,7 +3774,7 @@ fellow_cache_seg_evict_locked(
assert(fcs->state == FCS_INCORE);
*alloc = fcs->alloc;
fcs->alloc = buddy_ptr_extent_nil;
fcs->u.fcs_len = 0;
fcs->u.fcs.len = 0;
fcs->state = FCS_DISK;
}
......@@ -4406,7 +4417,7 @@ fellow_cache_seg_check(struct fellow_cache_seg *fcs)
CHECK_OBJ_NOTNULL(fds, FELLOW_DISK_SEG_MAGIC);
#ifdef TODO_READ_ERR
if ((fds->segnum % 16 == 0 && FC_INJ) ||
fhcmp(fds->fht, fds->fh, fcs->alloc.ptr, fcs->u.fcs_len)) {
fhcmp(fds->fht, fds->fh, fcs->alloc.ptr, fcs->u.fcs.len)) {
err = "segment checksum error";
to = FCS_READFAIL;
}
......@@ -5164,16 +5175,16 @@ fellow_busy_obj_getspace(struct fellow_busy *fbo, size_t *sz, uint8_t **ptr)
fcs = fbo->body_seg;
if (fcs != NULL && fcs->state == FCS_BUSY) {
AN(fcs->alloc.size);
if (fcs->u.fcs_len < fcs->alloc.size) {
spc = fcs->alloc.size - fcs->u.fcs_len;
if (fcs->u.fcs.len < fcs->alloc.size) {
spc = fcs->alloc.size - fcs->u.fcs.len;
assert(spc > 0);
if (spc < *sz)
*sz = spc;
*ptr = (uint8_t *)fcs->alloc.ptr + fcs->u.fcs_len;
*ptr = (uint8_t *)fcs->alloc.ptr + fcs->u.fcs.len;
return (FCR_OK(fbo));
}
assert(fcs->u.fcs_len == fcs->alloc.size);
assert(fcs->u.fcs.len == fcs->alloc.size);
unbusy = fcs;
fcs = NULL;
}
......@@ -5241,9 +5252,9 @@ fellow_busy_obj_extend(struct fellow_busy *fbo, size_t l)
fcs = fbo->body_seg;
CHECK_OBJ_NOTNULL(fcs, FELLOW_CACHE_SEG_MAGIC);
assert(fcs->state == FCS_BUSY);
fcs->u.fcs_len += l;
fcs->u.fcs.len += l;
fbo->sz_returned += l;
assert(fcs->u.fcs_len <= fcs->alloc.size);
assert(fcs->u.fcs.len <= fcs->alloc.size);
}
static void
......@@ -5345,7 +5356,7 @@ fellow_busy_obj_trimstore(struct fellow_busy *fbo)
assert_cache_seg_consistency(fcs);
if (fcs->state == FCS_BUSY) {
assert(fcs->u.fcs_len <= fcs->alloc.size);
assert(fcs->u.fcs.len <= fcs->alloc.size);
AN(fdr);
/*
......@@ -5359,7 +5370,7 @@ fellow_busy_obj_trimstore(struct fellow_busy *fbo)
} else {
assert(fcs->state == FCS_USABLE);
AZ(fcs->alloc.size);
AZ(fcs->u.fcs_len);
AZ(fcs->u.fcs.len);
}
if (fdr) {
......@@ -5367,7 +5378,7 @@ fellow_busy_obj_trimstore(struct fellow_busy *fbo)
// fbr offset where fcs starts
base = fbr->len - fcs->alloc.size;
nsz = base + fcs->u.fcs_len;
nsz = base + fcs->u.fcs.len;
if (nsz == 0)
fellow_busy_region_free(fbo, fdr);
......@@ -5394,8 +5405,8 @@ fellow_busy_obj_trimstore(struct fellow_busy *fbo)
// dsk/membuddy aligment must match
assert(nsz == fcs->alloc.size);
fcs->disk_seg->seg.size = fcs->alloc.size;
assert(fcs->u.fcs_len <= fcs->alloc.size);
if (fcs->u.fcs_len == 0) {
assert(fcs->u.fcs.len <= fcs->alloc.size);
if (fcs->u.fcs.len == 0) {
fcs->alloc.ptr = NULL;
AZ(fcs->disk_seg->seg.size);
fcs->disk_seg->seg.off = 0;
......@@ -5937,7 +5948,7 @@ struct objcore **ocp, uintptr_t priv2, unsigned crit)
if (spc >= sz) {
memcpy(ptr, fdo, sz);
fdo = fcs->u.fco_fdo = (void *)ptr;
fdo = fcs->u.fco.fdo = (void *)ptr;
AN(buddy_return_ptr_extent(rets, &fcs->alloc));
nsz += sz;
......@@ -6304,7 +6315,7 @@ fellow_cache_seg_panic(struct vsb *vsb, const struct fellow_cache_seg *fcs,
fellow_disk_seg_panic(vsb, fcs->disk_seg, "disk_seg");
fellow_cache_buddy_ptr_extent_panic(vsb, fcs->alloc, "alloc");
VSB_printf(vsb, "union { .fcs_len = %zu, .fco_fdo = %p },\n",
fcs->u.fcs_len, fcs->u.fco_fdo);
fcs->u.fcs.len, fcs->u.fco.fdo);
VSB_indent(vsb, -2);
VSB_cat(vsb, "},\n");
}
......@@ -6487,7 +6498,7 @@ fellow_cache_obj_getattr(struct fellow_cache *fc,
fcr = FCR_IOFAIL(err); \
break; \
} \
*len = fcs->u.fcs_len; \
*len = fcs->u.fcs.len; \
fcr = FCR_OK(fcs->alloc.ptr); \
break; \
}
......@@ -6568,8 +6579,8 @@ fellow_busy_setattr(struct fellow_busy *fbo, enum obj_attr attr,
if (! fellow_busy_seg_alloc(fbo, fcs, len)) \
break; \
assert(fcs->alloc.size >= len); \
AZ(fcs->u.fcs_len); \
fcs->u.fcs_len = len; \
AZ(fcs->u.fcs.len); \
fcs->u.fcs.len = len; \
retval = fcs->alloc.ptr; \
memcpy(retval, ptr, len); \
fellow_cache_seg_unbusy(fbo, fcs); \
......
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