Delayed appending any gdelta until the last mdir commit

It's not the most intuitive, but we always know if an mdir commit will
be the last commit/atomic before attempting the commit. This means we
can wait to append/flush gdelta until the last commit, which simplifies
handling of gdelta state in lfsr_mdir_commit a bit.

We were already doing this for the gcksum, this just changes the grm to
match.

This also results in gdeltas being pushed upwards when relocating, which
is probably a good thing? On one hand this encourages deduplication of
gdeltas, on the other hand it does result in gdeltas getting pushed into
mroots that don't need them (grm in mrootanchor?).

This ends up saving a bit of code, which is nice:

           code          stack          ctx
  before: 38612           2648          644
  after:  38588 (-0.1%)   2648 (+0.0%)  644 (+0.0%)
This commit is contained in:
Christopher Haster
2025-01-17 18:03:34 -06:00
parent fde3c537ea
commit 2ac9c0695b
+2 -16
View File
@@ -7753,7 +7753,7 @@ static int lfsr_mdir_commit__(lfs_t *lfs, lfsr_mdir_t *mdir,
}
// append any gstate?
if (start_rid <= -1) {
if (start_rid <= -2) {
int err = lfsr_rbyd_appendgdelta(lfs, &mdir->rbyd);
if (err) {
return err;
@@ -7793,17 +7793,6 @@ static int lfsr_mdir_commit__(lfs_t *lfs, lfsr_mdir_t *mdir,
// xor our new cksum
lfs->gcksum ^= mdir->rbyd.cksum;
// flush gstate?
if (start_rid <= -1) {
// TODO this is a hack
// we only flush gcksumdelta if rid == -2
uint32_t gcksum_d = lfs->gcksum_d;
lfsr_fs_flushgdelta(lfs);
if (start_rid > -2) {
lfs->gcksum_d = gcksum_d;
}
}
return 0;
}
@@ -8782,10 +8771,6 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir,
}
}
// gstate must have been committed by a lower-level function at this point
LFS_ASSERT(lfs->gcksum_d == 0);
LFS_ASSERT(lfsr_gdelta_iszero(lfs->grm_d, LFSR_GRM_DSIZE));
// sync on-disk state
err = lfsr_bd_sync(lfs);
if (err) {
@@ -8810,6 +8795,7 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir,
// update any gstate changes
lfsr_fs_commitgdelta(lfs);
lfsr_fs_flushgdelta(lfs);
// play out any rats that affect internal state
mid_ = mdir->mid;