Adopted lfsr_btree_commit, replacing all other btree operations.

Note this required changing the INLINED tag to REG in most of the tests,
because our mtree now explicitly requires some sort of NAME tag.

We can also finally see the impact on code and RAM from this restructure:

                                 code          stack
  before (push/set/pop/split):  21750           1928
  after (commit):               20970 (-3.7%)   1744 (-10.6%)

Not too shabby if I say so myself.
This commit is contained in:
Christopher Haster
2023-08-15 00:51:42 -05:00
parent a4c3a12f68
commit fb2fdb536c
3 changed files with 187 additions and 189 deletions
+25 -27
View File
@@ -5466,17 +5466,11 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir,
// Create a null entry in our btree first. Don't worry! Thanks // Create a null entry in our btree first. Don't worry! Thanks
// to inlining this doesn't allocate anything yet. // to inlining this doesn't allocate anything yet.
// //
// The reason for this is twofold: // This makes it so the split logic is the same whether or not
// // we're uninlining.
// 1. It makes it so the split logic is the same whether or not
// we're uninlining.
//
// 2. It makes it so we can actually split, lfsr_btree_split
// currently doesn't support an empty tree.
//
LFS_ASSERT(lfsr_btree_weight(&mtree_) == 0); LFS_ASSERT(lfsr_btree_weight(&mtree_) == 0);
int err = lfsr_btree_push(lfs, &mtree_, 0, LFSR_TAG_MDIR, 1, int err = lfsr_btree_commit(lfs, &mtree_, LFSR_ATTRS(
LFSR_DATA_NULL); LFSR_ATTR(0, MDIR, +1, NULL)));
if (err) { if (err) {
return err; return err;
} }
@@ -5534,7 +5528,8 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir,
msibling_.u.r.rbyd.trunk = 0; msibling_.u.r.rbyd.trunk = 0;
// update our mtree // update our mtree
int err = lfsr_btree_pop(lfs, &mtree_, mbid); int err = lfsr_btree_commit(lfs, &mtree_, LFSR_ATTRS(
LFSR_ATTR(mbid, RM, -1, NULL)));
if (err) { if (err) {
return err; return err;
} }
@@ -5556,8 +5551,9 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir,
return mdir_dsize; return mdir_dsize;
} }
int err = lfsr_btree_set(lfs, &mtree_, mbid, LFSR_TAG_MDIR, 1, int err = lfsr_btree_commit(lfs, &mtree_, LFSR_ATTRS(
LFSR_DATA(mdir_buf, mdir_dsize)); LFSR_ATTR(mbid, MDIR, 0,
BUF(mdir_buf, mdir_dsize))));
if (err) { if (err) {
return err; return err;
} }
@@ -5579,8 +5575,9 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir,
return msibling_dsize; return msibling_dsize;
} }
int err = lfsr_btree_set(lfs, &mtree_, mbid, LFSR_TAG_MDIR, 1, int err = lfsr_btree_commit(lfs, &mtree_, LFSR_ATTRS(
LFSR_DATA(msibling_buf, msibling_dsize)); LFSR_ATTR(mbid, MDIR, 0,
BUF(msibling_buf, msibling_dsize))));
if (err) { if (err) {
return err; return err;
} }
@@ -5599,8 +5596,8 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir,
// case they introduce a new name! // case they introduce a new name!
lfsr_tag_t stag; lfsr_tag_t stag;
lfsr_data_t sdata; lfsr_data_t sdata;
int err = lfsr_mdir_lookupnext(lfs, &msibling_, 0, LFSR_TAG_NAME, int err = lfsr_mdir_lookup(lfs, &msibling_, 0, LFSR_TAG_WIDE(NAME),
NULL, &stag, &sdata); &stag, &sdata);
if (err) { if (err) {
LFS_ASSERT(err != LFS_ERR_NOENT); LFS_ASSERT(err != LFS_ERR_NOENT);
return err; return err;
@@ -5619,12 +5616,12 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir,
return msibling_dsize; return msibling_dsize;
} }
err = lfsr_btree_split(lfs, &mtree_, mbid, err = lfsr_btree_commit(lfs, &mtree_, LFSR_ATTRS(
(lfsr_tag_suptype(stag) == LFSR_TAG_NAME LFSR_ATTR(mbid, MDIR, 0,
? sdata BUF(mdir_buf, mdir_dsize)),
: LFSR_DATA_NULL), LFSR_ATTR(mbid+1, BNAME, +1, DATA(sdata)),
LFSR_TAG_MDIR, 1, LFSR_DATA(mdir_buf, mdir_dsize), LFSR_ATTR(mbid+1, MDIR, 0,
LFSR_TAG_MDIR, 1, LFSR_DATA(msibling_buf, msibling_dsize)); BUF(msibling_buf, msibling_dsize))));
if (err) { if (err) {
return err; return err;
} }
@@ -5642,7 +5639,8 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir,
mdir_.u.r.rbyd.trunk = 0; mdir_.u.r.rbyd.trunk = 0;
// update our mtree // update our mtree
int err = lfsr_btree_pop(lfs, &mtree_, mdir->mid.bid); int err = lfsr_btree_commit(lfs, &mtree_, LFSR_ATTRS(
LFSR_ATTR(mdir->mid.bid, RM, -1, NULL)));
if (err) { if (err) {
return err; return err;
} }
@@ -5673,9 +5671,9 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir,
return mdir_dsize; return mdir_dsize;
} }
int err = lfsr_btree_set(lfs, &mtree_, int err = lfsr_btree_commit(lfs, &mtree_, LFSR_ATTRS(
mdir->mid.bid, LFSR_TAG_MDIR, 1, LFSR_ATTR(mdir->mid.bid, MDIR, 0,
LFSR_DATA(mdir_buf, mdir_dsize)); BUF(mdir_buf, mdir_dsize))));
if (err) { if (err) {
return err; return err;
} }
+3 -3
View File
@@ -123,7 +123,7 @@ code = '''
// keep creating new metadata entries until we run out of space // keep creating new metadata entries until we run out of space
int err = lfsr_mdir_commit(&lfs, &mdir, LFSR_ATTRS( int err = lfsr_mdir_commit(&lfs, &mdir, LFSR_ATTRS(
LFSR_ATTR(mdir.mid.rid, INLINED, +1, LFSR_ATTR(mdir.mid.rid, REG, +1,
BUF(&alphas[count % 26], 1)))); BUF(&alphas[count % 26], 1))));
assert(!err || err == LFS_ERR_NOSPC); assert(!err || err == LFS_ERR_NOSPC);
if (err == LFS_ERR_NOSPC) { if (err == LFS_ERR_NOSPC) {
@@ -131,7 +131,7 @@ code = '''
} }
uint8_t buffer[4]; uint8_t buffer[4];
lfsr_mdir_get(&lfs, &mdir, mdir.mid.rid, LFSR_TAG_INLINED, lfsr_mdir_get(&lfs, &mdir, mdir.mid.rid, LFSR_TAG_REG,
buffer, 4) => 1; buffer, 4) => 1;
assert(memcmp(buffer, &alphas[count % 26], 1) == 0); assert(memcmp(buffer, &alphas[count % 26], 1) == 0);
@@ -153,7 +153,7 @@ code = '''
mdir.mid.rid < (lfs_ssize_t)mdir.u.m.weight; mdir.mid.rid < (lfs_ssize_t)mdir.u.m.weight;
mdir.mid.rid++) { mdir.mid.rid++) {
uint8_t buffer[4]; uint8_t buffer[4];
lfsr_mdir_get(&lfs, &mdir, mdir.mid.rid, LFSR_TAG_INLINED, lfsr_mdir_get(&lfs, &mdir, mdir.mid.rid, LFSR_TAG_REG,
buffer, 4) => 1; buffer, 4) => 1;
assert(memcmp(buffer, &alphas[i % 26], 1) == 0); assert(memcmp(buffer, &alphas[i % 26], 1) == 0);
i += 1; i += 1;
+159 -159
View File
File diff suppressed because it is too large Load Diff