gc: Added more tests over info flags, dropped gc_flags default

Since we dropped lfsr_gc_setflags/setsteps, it was no longer possible to
set gc_flags to zero (perfectly valid and useful for system bringup/
testing things). Supporting gc_flags=0 means it's not possible to
provide a default, but this is probably ok as users need to opt-in to
LFS_GC anyways.

Note that at least gc_steps=0 doesn't make sense, so the default there
is reasonable.

Fixing this also highlighted that gc_flags/steps are no longer mutable,
making the comment in lfs_init out-of-date. Dropping these saves a bit
of lfs_t size, so that's nice.

And then testing also revealed that LFS_GC_CKDATA implying LFS_GC_CKDATA
means it should probably clear the LFS_I_CKMETA flag as well.

---

And here I thought this was going to be just a simple test-writing
exercise!

Code changes:

                   code          stack          ctx
  default before: 37792           2608          620
  default after:  37792 (-0.0%)   2608 (+0.0%)  620 (+0.0%)

  gc before:      37896           2608          768
  gc after:       37848 (-0.1%)   2608 (+0.0%)  760 (-1.0%)
This commit is contained in:
Christopher Haster
2025-01-08 16:02:36 -06:00
parent bb4e6cca2c
commit 9ed9cf0ccd
5 changed files with 600 additions and 55 deletions
+6 -18
View File
@@ -9646,7 +9646,8 @@ eot:;
&& !lfsr_t_ismtreeonly(t->o.o.flags)
&& !lfsr_t_isdirty(t->o.o.flags)
&& !lfsr_t_ismutated(t->o.o.flags)) {
lfs->flags &= ~LFS_I_CKDATA;
// note ckdata implies ckmeta
lfs->flags &= ~LFS_I_CKDATA & ~LFS_I_CKMETA;
}
return LFS_ERR_NOENT;
@@ -13383,22 +13384,6 @@ static int lfs_init(lfs_t *lfs, uint32_t flags,
lfs_memset(lfs->grm_p, 0, LFSR_GRM_DSIZE);
lfs_memset(lfs->grm_d, 0, LFSR_GRM_DSIZE);
#ifdef LFS_GC
// setup gc state, this can be mutated which is why we need a copy
if (lfs->cfg->gc_flags) {
lfs->gc.flags = lfs->cfg->gc_flags;
} else {
lfs->gc.flags = LFS_GC_MKCONSISTENT
| LFS_GC_LOOKAHEAD
| LFS_GC_COMPACT;
}
if (lfs->cfg->gc_steps) {
lfs->gc.steps = lfs->cfg->gc_steps;
} else {
lfs->gc.steps = 1;
}
#endif
return 0;
failed:;
@@ -14542,7 +14527,10 @@ static int lfsr_fs_gc_(lfs_t *lfs, lfsr_traversal_t *t,
// perform any pending janitorial work
int lfsr_fs_gc(lfs_t *lfs) {
return lfsr_fs_gc_(lfs, &lfs->gc.t,
lfs->gc.flags, lfs->gc.steps);
lfs->cfg->gc_flags,
(lfs->cfg->gc_steps)
? lfs->cfg->gc_steps
: 1);
}
#endif