From 43270ed50f676683d205771bb3981994cc4bd719 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Wed, 6 Dec 2023 21:00:14 -0600 Subject: [PATCH] Moved post-compaction mdir commits into lfsr_mdir_compact__ Since we need access to the pending attr-list in lfsr_mdir_compact__ now, we might as well just do the pending commit. Worst case, a call to lfsr_mdir_compact__ can provide a NULL attr-list for the previous behavior (though we always follow up compaction with a commit). The only downside is that this behavior is now a bit different from lfsr_rbyd_compact. Need to revisit lfsr_rbyd_compact and see if it should do the same. This had a tiny improvement to code size, which I think is just the cost of two function calls: code stack before: 31716 2776 after: 31676 (-0.1%) 2776 (+0.0%) --- lfs.c | 48 +++++++++++++++++------------------------------- 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/lfs.c b/lfs.c index 3fbb4a73..180e5261 100644 --- a/lfs.c +++ b/lfs.c @@ -6007,6 +6007,17 @@ static int lfsr_mdir_compact__(lfs_t *lfs, lfsr_mdir_t *mdir_, } } + // once we've compacted, finish our commit + // + // upper layers should make sure this can't fail by limiting the + // maximum commit size + err = lfsr_mdir_commit__(lfs, mdir_, start_rid, end_rid, + attrs, attr_count); + if (err) { + LFS_ASSERT(err != LFS_ERR_RANGE); + return err; + } + return 0; } @@ -6050,25 +6061,14 @@ compact:; } // compact our mdir - err = lfsr_mdir_compact__(lfs, &mdir_, start_rid, end_rid, mdir, - attrs, attr_count); + err = lfsr_mdir_compact__(lfs, &mdir_, start_rid, end_rid, + mdir, attrs, attr_count); if (err) { LFS_ASSERT(err != LFS_ERR_RANGE); return err; } - // we've compacted, try to commit again - // - // upper layers should make sure this can't fail by limiting the - // maximum commit size *mdir = mdir_; - err = lfsr_mdir_commit__(lfs, mdir, start_rid, end_rid, - attrs, attr_count); - if (err) { - LFS_ASSERT(err != LFS_ERR_RANGE); - return err; - } - return 0; } @@ -6542,15 +6542,8 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir, return err; } - err = lfsr_mdir_compact__(lfs, &mdir_, 0, split_rid, mdir, - attrs, attr_count); - if (err) { - LFS_ASSERT(err != LFS_ERR_RANGE); - return err; - } - - err = lfsr_mdir_commit__(lfs, &mdir_, 0, split_rid, - attrs, attr_count); + err = lfsr_mdir_compact__(lfs, &mdir_, 0, split_rid, + mdir, attrs, attr_count); if (err) { LFS_ASSERT(err != LFS_ERR_RANGE); return err; @@ -6562,15 +6555,8 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir, return err; } - err = lfsr_mdir_compact__(lfs, &msibling_, split_rid, -1, mdir, - attrs, attr_count); - if (err) { - LFS_ASSERT(err != LFS_ERR_RANGE); - return err; - } - - err = lfsr_mdir_commit__(lfs, &msibling_, split_rid, -1, - attrs, attr_count); + err = lfsr_mdir_compact__(lfs, &msibling_, split_rid, -1, + mdir, attrs, attr_count); if (err) { LFS_ASSERT(err != LFS_ERR_RANGE); return err;