gc: Tweaked lfs3_fs_gc_ to rely on lfs3_mtree_gc for fixgrms

This does two things:

- Deduplicates another fixgrm call, now all fixgrm cleanup (outside of
  mkdir/remove) goes through lfs3_mtree_gc.

- Predicates fixgrm on if lookahead work is complete.

Code changes:

                 code          stack          ctx
  before:       35128           2136          660
  after:        35116 (-0.0%)   2136 (+0.0%)  660 (+0.0%)

                 code          stack          ctx
  gbmap before: 38052           2136          776
  gbmap after:  38040 (-0.0%)   2136 (+0.0%)  776 (+0.0%)
This commit is contained in:
Christopher Haster
2025-12-06 16:01:04 -06:00
parent 07ba12fb20
commit f05be19d0e
+40 -52
View File
@@ -16128,34 +16128,29 @@ failed:;
// note lfs3_fs_stat should never go to disk // note lfs3_fs_stat should never go to disk
int lfs3_fs_stat(lfs3_t *lfs3, struct lfs3_fsinfo *fsinfo) { int lfs3_fs_stat(lfs3_t *lfs3, struct lfs3_fsinfo *fsinfo) {
// return various filesystem flags // return various filesystem flags
uint32_t flags = lfs3->flags & ( fsinfo->flags = (lfs3->flags & (
LFS3_I_RDONLY LFS3_I_RDONLY
| LFS3_I_FLUSH | LFS3_I_FLUSH
| LFS3_I_SYNC | LFS3_I_SYNC
| LFS3_IFDEF_REVDBG(LFS3_I_REVDBG, 0) | LFS3_IFDEF_REVDBG(LFS3_I_REVDBG, 0)
| LFS3_IFDEF_REVNOISE(LFS3_I_REVNOISE, 0) | LFS3_IFDEF_REVNOISE(LFS3_I_REVNOISE, 0)
| LFS3_IFDEF_CKPROGS(LFS3_I_CKPROGS, 0) | LFS3_IFDEF_CKPROGS(LFS3_I_CKPROGS, 0)
| LFS3_IFDEF_CKFETCHES(LFS3_I_CKFETCHES, 0) | LFS3_IFDEF_CKFETCHES(LFS3_I_CKFETCHES, 0)
| LFS3_IFDEF_CKMETAPARITY(LFS3_I_CKMETAPARITY, 0) | LFS3_IFDEF_CKMETAPARITY(LFS3_I_CKMETAPARITY, 0)
| LFS3_IFDEF_CKDATACKSUMS(LFS3_I_CKDATACKSUMS, 0) | LFS3_IFDEF_CKDATACKSUMS(LFS3_I_CKDATACKSUMS, 0)
| LFS3_IFDEF_RDONLY(0, LFS3_I_MKCONSISTENT) | LFS3_IFDEF_RDONLY(0, LFS3_I_MKCONSISTENT)
| LFS3_IFDEF_RDONLY(0, LFS3_I_LOOKAHEAD) | LFS3_IFDEF_RDONLY(0, LFS3_I_LOOKAHEAD)
| LFS3_IFDEF_RDONLY(0, LFS3_I_COMPACT) | LFS3_IFDEF_RDONLY(0, LFS3_I_COMPACT)
| LFS3_I_CKMETA | LFS3_I_CKMETA
| LFS3_I_CKDATA | LFS3_I_CKDATA
| LFS3_IFDEF_GBMAP(LFS3_I_GBMAP, 0)); | LFS3_IFDEF_GBMAP(LFS3_I_GBMAP, 0)))
// LFS3_I_MKCONSISTENT is a bit of a special case,
// some flags we calculate on demand // internally it strictly indicates untracked orphans, but
// externally it also includes any pending grms
// internally, LFS3_I_MKCONSISTENT just means we may have orphaned | LFS3_IFDEF_RDONLY(0,
// stickynotes, need to also include any grms (lfs3_grm_count(lfs3) > 0)
#ifndef LFS3_RDONLY ? LFS3_I_MKCONSISTENT
if (lfs3_t_ismkconsistent(lfs3->flags) || lfs3_grm_count(lfs3) > 0) { : 0);
flags |= LFS3_I_MKCONSISTENT;
}
#endif
fsinfo->flags = flags;
// return filesystem config, this may come from disk // return filesystem config, this may come from disk
fsinfo->block_size = lfs3->cfg->block_size; fsinfo->block_size = lfs3->cfg->block_size;
@@ -16358,26 +16353,20 @@ int lfs3_fs_mkconsistent(lfs3_t *lfs3) {
// multiple passes // multiple passes
static int lfs3_fs_gc_(lfs3_t *lfs3, lfs3_mgc_t *mgc, static int lfs3_fs_gc_(lfs3_t *lfs3, lfs3_mgc_t *mgc,
uint32_t flags, lfs3_soff_t steps) { uint32_t flags, lfs3_soff_t steps) {
// fix pending grms if requested
#ifndef LFS3_RDONLY
if (lfs3_t_ismkconsistent(flags)
&& lfs3_grm_count(lfs3) > 0) {
int err = lfs3_fs_fixgrm(lfs3);
if (err) {
return err;
}
}
#endif
while ((lfs3_off_t)steps > 0) { while ((lfs3_off_t)steps > 0) {
// do we have any pending work? // do we have any pending work?
uint32_t pending = flags & ( uint32_t pending = flags & (
(LFS3_IFDEF_RDONLY(0, LFS3_GC_MKCONSISTENT) (lfs3->flags & (
| LFS3_IFDEF_RDONLY(0, LFS3_GC_LOOKAHEAD) LFS3_IFDEF_RDONLY(0, LFS3_GC_MKCONSISTENT)
| LFS3_IFDEF_RDONLY(0, LFS3_GC_COMPACT) | LFS3_IFDEF_RDONLY(0, LFS3_GC_LOOKAHEAD)
| LFS3_GC_CKMETA | LFS3_IFDEF_RDONLY(0, LFS3_GC_COMPACT)
| LFS3_GC_CKDATA) | LFS3_GC_CKMETA
& lfs3->flags); | LFS3_GC_CKDATA))
// including any pending grms
| LFS3_IFDEF_RDONLY(0,
(lfs3_grm_count(lfs3) > 0)
? LFS3_GC_MKCONSISTENT
: 0));
if (!pending) { if (!pending) {
break; break;
} }
@@ -16401,13 +16390,12 @@ static int lfs3_fs_gc_(lfs3_t *lfs3, lfs3_mgc_t *mgc,
// note that even though our current API prevents flags from // note that even though our current API prevents flags from
// changing mid-traversal, lfs3->flags can be updated by other // changing mid-traversal, lfs3->flags can be updated by other
// operations // operations
mgc->t.h.flags &= ~( mgc->t.h.flags &= ~(pending ^ (
(LFS3_IFDEF_RDONLY(0, LFS3_GC_MKCONSISTENT) LFS3_IFDEF_RDONLY(0, LFS3_GC_MKCONSISTENT)
| LFS3_IFDEF_RDONLY(0, LFS3_GC_LOOKAHEAD) | LFS3_IFDEF_RDONLY(0, LFS3_GC_LOOKAHEAD)
| LFS3_IFDEF_RDONLY(0, LFS3_GC_COMPACT) | LFS3_IFDEF_RDONLY(0, LFS3_GC_COMPACT)
| LFS3_GC_CKMETA | LFS3_GC_CKMETA
| LFS3_GC_CKDATA) | LFS3_GC_CKDATA));
^ pending);
// will this traversal still make progress? no? start over // will this traversal still make progress? no? start over
if (!(mgc->t.h.flags if (!(mgc->t.h.flags