rattrs: Attempted to merge mtree split commits

The idea here was to merge mtree split commits to try to minimize
redundant logic that only differs in whether or not we need to create
the initial mtree weight.

Surprisingly, this backfired, adding more code than it saved. I guess I
underestimated how effective the compiler is at deduplicating these two
paths of logic:

                 code          stack          ctx
  before:       35316           2176          660
  after:        35324 (+0.0%)   2176 (+0.0%)  660 (+0.0%)

                 code          stack          ctx
  gbmap before: 38168           2192          772
  gbmap after:  38172 (+0.0%)   2192 (+0.0%)  772 (+0.0%)
This commit is contained in:
Christopher Haster
2025-12-01 15:17:09 -06:00
parent b28b7c12aa
commit 90ba24787f
+18 -31
View File
@@ -9143,27 +9143,19 @@ static int lfs3_mdir_commit_(lfs3_t *lfs3, lfs3_mdir_t *mdir,
// new mtree?
if (lfs3->mtree.r.weight == 0) {
lfs3_btree_init(&mtree_);
err = lfs3_mtree_commit(lfs3, &mtree_,
0, LFS3_RATTRS(
LFS3_RATTR(3, LFS3_TAG_MDIR, -2, LFS3_FROM_MPTR),
LFS3_RATTR_WEIGHT(+(1 << lfs3->mbits)),
LFS3_RATTR_ARG(mdir_[0].r.blocks),
LFS3_RATTR(3, LFS3_TAG_MNAME, -2, LFS3_FROM_CAT, 1),
LFS3_RATTR_WEIGHT(+(1 << lfs3->mbits)),
LFS3_RATTR_ARG(&split_name),
LFS3_RATTR(2, LFS3_TAG_MDIR, 0, LFS3_FROM_MPTR),
LFS3_RATTR_ARG(mdir_[1].r.blocks),
LFS3_RATTR_NULL));
if (err) {
goto failed;
}
// update our mtree
} else {
err = lfs3_mtree_commit(lfs3, &mtree_,
lfs3_mbid(lfs3, mdir->mid), LFS3_RATTRS(
LFS3_RATTR(2, LFS3_TAG_MDIR, 0, LFS3_FROM_MPTR),
(lfs3->mtree.r.weight == 0)
? 0
: lfs3_mbid(lfs3, mdir->mid),
LFS3_RATTRS(
LFS3_RATTR(3, LFS3_TAG_MDIR, -2, LFS3_FROM_MPTR),
LFS3_RATTR_WEIGHT(
(lfs3->mtree.r.weight == 0)
? +(1 << lfs3->mbits)
: 0),
LFS3_RATTR_ARG(mdir_[0].r.blocks),
LFS3_RATTR(3, LFS3_TAG_MNAME, -2, LFS3_FROM_CAT, 1),
LFS3_RATTR_WEIGHT(+(1 << lfs3->mbits)),
@@ -9174,7 +9166,6 @@ static int lfs3_mdir_commit_(lfs3_t *lfs3, lfs3_mdir_t *mdir,
if (err) {
goto failed;
}
}
// need to drop?
} else if (err == LFS3_ERR_NOENT) {
@@ -9219,29 +9210,25 @@ static int lfs3_mdir_commit_(lfs3_t *lfs3, lfs3_mdir_t *mdir,
// new mtree?
if (lfs3->mtree.r.weight == 0) {
lfs3_btree_init(&mtree_);
err = lfs3_mtree_commit(lfs3, &mtree_,
0, LFS3_RATTRS(
LFS3_RATTR(3, LFS3_TAG_MDIR, -2, LFS3_FROM_MPTR),
LFS3_RATTR_WEIGHT(+(1 << lfs3->mbits)),
LFS3_RATTR_ARG(mdir_[0].r.blocks),
LFS3_RATTR_NULL));
if (err) {
goto failed;
}
// update our mtree
} else {
err = lfs3_mtree_commit(lfs3, &mtree_,
lfs3_mbid(lfs3, mdir->mid), LFS3_RATTRS(
LFS3_RATTR(2, LFS3_TAG_MDIR, 0, LFS3_FROM_MPTR),
(lfs3->mtree.r.weight == 0)
? 0
: lfs3_mbid(lfs3, mdir->mid),
LFS3_RATTRS(
LFS3_RATTR(3, LFS3_TAG_MDIR, -2, LFS3_FROM_MPTR),
LFS3_RATTR_WEIGHT(
(lfs3->mtree.r.weight == 0)
? +(1 << lfs3->mbits)
: 0),
LFS3_RATTR_ARG(mdir_[0].r.blocks),
LFS3_RATTR_NULL));
if (err) {
goto failed;
}
}
}
// patch any pending grms
for (int j = 0; j < 2; j++) {