gc: Renamed lfsr_gc -> lfsr_fs_gc, keep lfsr_fs_unck in non-gc

- lfsr_gc -> lfsr_fs_gc
- lfsr_gc_unck -> lfsr_fs_unck

lfsr_fs_unck is surprisingly still useful in non-gc builds, since we
still have ckmeta/ckdata state. These flags can still be queried with
lfsr_fs_stat and cleared with lfsr_fs_ckmeta/ckdata/lfsr_traversal_t, so
it seems useful to keep this function around.

It's also a relatively cheap function.

Though this does mean it deserves a rename. Dropping the gc prefix
hopefully makes it clearer this function is not entirely gc-specific.

And since we no longer have lfsr_gc_setflags/setsteps, it makes sense to
rename lfsr_gc back to lfsr_fs_gc, to be consistent with the other
filesystem-wide utilities.

Code changes, apparently lfsr_fs_unck costs 12 bytes:

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

  gc before:      37938           2608          768
  gc after:       37940 (+0.0%)   2608 (+0.0%)  768 (+0.0%)
This commit is contained in:
Christopher Haster
2025-01-08 02:31:49 -06:00
parent 39d488a1ef
commit 9c9a23e27b
5 changed files with 126 additions and 131 deletions
+38 -40
View File
@@ -13952,7 +13952,7 @@ static int lfsr_mountinited(lfs_t *lfs) {
}
// needed in lfsr_mount
static int lfsr_fs_gc(lfs_t *lfs, lfsr_traversal_t *t,
static int lfsr_fs_gc_(lfs_t *lfs, lfsr_traversal_t *t,
uint32_t flags, lfs_soff_t steps);
int lfsr_mount(lfs_t *lfs, uint32_t flags,
@@ -14010,7 +14010,7 @@ int lfsr_mount(lfs_t *lfs, uint32_t flags,
| LFS_M_CKMETA
| LFS_M_CKDATA)) {
lfsr_traversal_t t;
err = lfsr_fs_gc(lfs, &t,
err = lfsr_fs_gc_(lfs, &t,
flags & (
LFS_M_MTREEONLY
| LFS_M_MKCONSISTENT
@@ -14189,7 +14189,7 @@ int lfsr_format(lfs_t *lfs, uint32_t flags,
| LFS_F_CKMETA
| LFS_F_CKDATA)) {
lfsr_traversal_t t;
err = lfsr_fs_gc(lfs, &t,
err = lfsr_fs_gc_(lfs, &t,
flags & (
LFS_F_MTREEONLY
| LFS_F_COMPACT
@@ -14449,7 +14449,7 @@ int lfsr_fs_ckdata(lfs_t *lfs) {
//
// runs the traversal until all work is completed, which may take
// multiple passes
static int lfsr_fs_gc(lfs_t *lfs, lfsr_traversal_t *t,
static int lfsr_fs_gc_(lfs_t *lfs, lfsr_traversal_t *t,
uint32_t flags, lfs_soff_t steps) {
// unknown gc flags?
//
@@ -14555,6 +14555,40 @@ static int lfsr_fs_gc(lfs_t *lfs, lfsr_traversal_t *t,
return 0;
}
#ifdef LFS_GC
// incremental filesystem gc
//
// 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);
}
#endif
// unperform janitorial work
int lfsr_fs_unck(lfs_t *lfs, uint32_t flags) {
// unknown flags?
LFS_ASSERT((flags & ~(
LFS_I_INCONSISTENT
| LFS_I_CANLOOKAHEAD
| LFS_I_UNCOMPACTED
| LFS_I_CANCKMETA
| LFS_I_CANCKDATA)) == 0);
// reset the requested flags
lfs->flags |= flags;
#ifdef LFS_GC
// and clear from any ongoing traversals
//
// lfsr_fs_gc will terminate early if it discovers it can no longer
// make progress
lfs->gc.t.o.o.flags &= ~flags;
#endif
return 0;
}
// attempt to grow the filesystem
int lfsr_fs_grow(lfs_t *lfs, lfs_size_t block_count_) {
@@ -14786,42 +14820,6 @@ int lfsr_traversal_rewind(lfs_t *lfs, lfsr_traversal_t *t) {
/// Incremental gc operations ///
#ifdef LFS_GC
// perform any pending janitorial work
int lfsr_gc(lfs_t *lfs) {
return lfsr_fs_gc(lfs, &lfs->gc.t,
lfs->gc.flags, lfs->gc.steps);
}
#endif
#ifdef LFS_GC
// unperform janitorial work
int lfsr_gc_unck(lfs_t *lfs, uint32_t flags) {
// unknown flags?
LFS_ASSERT((flags & ~(
LFS_I_INCONSISTENT
| LFS_I_CANLOOKAHEAD
| LFS_I_UNCOMPACTED
| LFS_I_CANCKMETA
| LFS_I_CANCKDATA)) == 0);
// reset the requested flags
lfs->flags |= flags;
// and clear from any ongoing traversals
//
// lfsr_fs_gc will terminate early if it discovers it can no longer
// make progress
lfs->gc.t.o.o.flags &= ~flags;
return 0;
}
#endif