t: (Re)implemented gc_compact_thresh, at least over mdirs

lfs_fs_gc is still not reimplemented, but this is accessible through the
traversal API with LFS_T_COMPACT.

This is also the first traversal operation that can mutate the
filesystem, which brings its own set of problems:

- We need to set LFS_F_DIRTY in lfsr_mtree_gc now, which really
  highlights how much of a mess having two flag fields is...

  We do _not_ clobber in this case, since we assume lfsr_mtree_gc knows
  what it's doing.

- We can now commit to an mroot in the mroot chain outside of the normal
  mroot chain update logic.

  This is a bit scary, but should just work.

  The only issue so far is that we need to allow mdirs to follow the
  mroot during mroot splits if mid=-1, even if they aren't lfs_t's mroot
  mdir.

  This should now be decently tested with the new
  test_traversal_compact_* tests.

- It's easy for mtraversal's mdir and mtinfo's mdir to fall out of sync
  when mutating... Why do we have two of these?

The actual compaction itself is pretty straightforward: just mark as
unerased, eoff=-1, and call lfsr_mdir_commit with an empty commit. This
is now wrapped up in lfsr_mdir_compact.

Code changes:

           code          stack
  before: 34528           2640
  after:  34652 (+0.4%)   2640 (+0.0%)

Though the real hard part will be implementing gc_compact_thresh over
btree nodes...
This commit is contained in:
Christopher Haster
2024-06-24 16:21:38 -05:00
parent ff0271ecbe
commit 4d06fc2e0e
5 changed files with 875 additions and 31 deletions
+11
View File
@@ -268,6 +268,17 @@ struct lfs_config {
// can track 8 blocks.
lfs_size_t lookahead_size;
// Threshold for metadata compaction during gc in bytes. Metadata logs
// that exceed this threshold will be compacted during gc operations.
// Defaults to ~88% block_size when zero, though this default may change
// in the future.
//
// Note this only affects explicit gc operations. Otherwise metadata is
// only compacted when full.
//
// Set to -1 to disable metadata compaction during gc.
lfs_size_t gc_compact_thresh;
// Optional statically allocated read buffer. Must be rcache_size. By
// default lfs_malloc is used to allocate this buffer.
void *rcache_buffer;