Tighten DLE array sizing

We should do this right and not over-allocate, this is just confusing.
parent e112b51f
......@@ -4037,7 +4037,7 @@ fdr_compar(const void *aa, const void *bb)
static void
fellow_busy_log_submit(const struct fellow_busy *fbo)
{
unsigned r = 0, ndle = (fbo->nregion / DLE_REG_NREGION) + 2;
unsigned r = 0, ndle = DLE_N_REG(fbo->nregion) + 1;
struct fellow_dle *e, dle_obj[1], dles[ndle];
struct fellow_cache_obj *fco;
const struct fellow_disk_obj *fdo;
......@@ -4058,11 +4058,13 @@ fellow_busy_log_submit(const struct fellow_busy *fbo)
r = fellow_dle_reg_fill(dles, ndle, fbo->region, fbo->nregion,
DLE_REG_ADD, dle_obj->u.obj.hash);
assert(r < ndle);
e = &dles[r++];
e->type = DLEDSK(DLE_OBJ_ADD);
memcpy(&e->u.obj, &dle_obj->u.obj, sizeof e->u.obj);
e->u.obj.start = fbo->fco->fdb;
assert(r <= ndle);
fellow_log_dle_submit(fbo->fc->ffd, dles, r);
#ifdef XXXDEBUG
......@@ -4517,7 +4519,7 @@ fellow_disk_obj_delete_submit(struct fellow_fd *ffd,
fellow_disk_block start, const uint8_t hash[DIGEST_LEN],
const struct buddy_off_extent region[FCO_MAX_REGIONS], unsigned n)
{
unsigned r, ndle = (n / DLE_REG_NREGION) + 2;
unsigned r, ndle = DLE_N_REG(n) + 1;
struct fellow_dle *e, dles[ndle];
fellow_dle_init(dles, ndle);
......@@ -4527,11 +4529,13 @@ fellow_disk_obj_delete_submit(struct fellow_fd *ffd,
else
r = 0;
assert(r < ndle);
e = &dles[r++];
e->type = DLEDSK(DLE_OBJ_DEL_ALLOCED);
memcpy(e->u.obj.hash, hash, (size_t)DIGEST_LEN);
e->u.obj.start = start;
assert(r <= ndle);
fellow_log_dle_submit(ffd, dles, r);
}
......
......@@ -3506,7 +3506,7 @@ static void
fellow_log_dle_ban_imm(struct fellow_fd *ffd, enum dle_type type,
const uint8_t *bans, uint16_t len, vtim_real t)
{
static const unsigned nentries = FELLOW_DISK_LOG_BLOCK_ENTRIES + 1;
static const unsigned nentries = FELLOW_DISK_LOG_BLOCK_ENTRIES;
struct fellow_dle dle[nentries], *e;
int8_t n, cont;
uint8_t *ban;
......@@ -3561,6 +3561,7 @@ fellow_log_dle_ban_imm(struct fellow_fd *ffd, enum dle_type type,
AZ(len);
AZ(cont);
assert(n > 0);
assert((uint8_t)n <= nentries);
fellow_log_dle_submit(ffd, dle, (uint8_t)n);
}
......
......@@ -81,6 +81,9 @@ DLE_TYPE_LIM
- (sizeof(int8_t) + sizeof(uint16_t) + sizeof(vtim_real)))
#define DLE_BAN_REG_NREGION 3
// roundup number of DLEs needed for x regions
#define DLE_N_REG(x) ((x + (DLE_REG_NREGION)) / DLE_REG_NREGION)
struct fellow_dle_reg {
// 4 - for sanity check
uint8_t hashpfx[DLE_REG_HASHPFXSZ];
......
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