Adopted lfsr_bshrub_t in LFSR_TAG_SHRUBCOMMIT/SHRUBTRUNK

This makes a bit less sense than adopting lfsr_bshrub_t in lfsr_bshrub_*
functions, but it gives LFSR_TAG_SHRUBCOMMIT/SHRUBTRUNK direct access to
the staging shrub without needing the shrub + 1 hack.

The whole shrub vs bshrub distinction is already a bit broken anyways,
with us relying on the opened-mdir list to correctly stage all shrubs in
the filesystem.

---

Curiously, this again ends up with net negative impact on code cost:

           code          stack          ctx
  before: 36484           2608          640
  after:  36492 (+0.0%)   2608 (+0.0%)  640 (+0.0%)
This commit is contained in:
Christopher Haster
2025-02-04 02:22:01 -06:00
parent bc639b03f2
commit aaae25243b
2 changed files with 23 additions and 24 deletions
+20 -21
View File
@@ -2148,17 +2148,17 @@ static inline lfs_size_t lfsr_rat_size(lfsr_rat_t rat) {
// writing to an unrelated trunk in the rbyd // writing to an unrelated trunk in the rbyd
typedef struct lfsr_shrubcommit lfsr_shrubcommit_t; typedef struct lfsr_shrubcommit lfsr_shrubcommit_t;
#define LFSR_RAT_SHRUBCOMMIT(_tag, _weight, \ #define LFSR_RAT_SHRUBCOMMIT(_tag, _weight, \
_shrub, _rid, _rats, _rat_count) \ _bshrub, _rid, _rats, _rat_count) \
LFSR_RAT_(_tag, _weight, \ LFSR_RAT_(_tag, _weight, \
(&(const lfsr_shrubcommit_t){ \ (&(const lfsr_shrubcommit_t){ \
.shrub=_shrub, \ .bshrub=_bshrub, \
.rid=_rid, \ .rid=_rid, \
.rats=_rats, \ .rats=_rats, \
.rat_count=_rat_count}), \ .rat_count=_rat_count}), \
0) 0)
#define LFSR_RAT_SHRUBTRUNK(_tag, _weight, _shrub) \ #define LFSR_RAT_SHRUBTRUNK(_tag, _weight, _bshrub) \
LFSR_RAT_(_tag, _weight, (const lfsr_shrub_t*){_shrub}, 0) LFSR_RAT_(_tag, _weight, (const lfsr_bshrub_t*){_bshrub}, 0)
// operations on custom attribute lists // operations on custom attribute lists
@@ -6091,7 +6091,7 @@ static int lfsr_shrub_compact(lfs_t *lfs, lfsr_rbyd_t *rbyd_,
// this is needed to sneak shrub commits into mdir commits // this is needed to sneak shrub commits into mdir commits
struct lfsr_shrubcommit { struct lfsr_shrubcommit {
lfsr_shrub_t *shrub; lfsr_bshrub_t *bshrub;
lfsr_srid_t rid; lfsr_srid_t rid;
const lfsr_rat_t *rats; const lfsr_rat_t *rats;
lfs_size_t rat_count; lfs_size_t rat_count;
@@ -6374,7 +6374,7 @@ static int lfsr_bshrub_commit_(lfs_t *lfs, lfsr_bshrub_t *bshrub,
int err = lfsr_mdir_commit(lfs, &bshrub->o.mdir, LFSR_RATS( int err = lfsr_mdir_commit(lfs, &bshrub->o.mdir, LFSR_RATS(
LFSR_RAT_SHRUBCOMMIT( LFSR_RAT_SHRUBCOMMIT(
LFSR_TAG_SHRUBCOMMIT, 0, LFSR_TAG_SHRUBCOMMIT, 0,
&bshrub->shrub, bid, rats, rat_count))); bshrub, bid, rats, rat_count)));
if (err) { if (err) {
return err; return err;
} }
@@ -7417,22 +7417,23 @@ static int lfsr_mdir_commit__(lfs_t *lfs, lfsr_mdir_t *mdir,
// in our rbyd // in our rbyd
} else if (rats[i].tag == LFSR_TAG_SHRUBCOMMIT) { } else if (rats[i].tag == LFSR_TAG_SHRUBCOMMIT) {
const lfsr_shrubcommit_t *shrubcommit = rats[i].cat; const lfsr_shrubcommit_t *shrubcommit = rats[i].cat;
// find the staging shrub lfsr_bshrub_t *bshrub_ = shrubcommit->bshrub;
lfsr_shrub_t *shrub = shrubcommit->shrub; lfsr_srid_t rid_ = shrubcommit->rid;
lfsr_shrub_t *shrub_ = shrub + 1; const lfsr_rat_t *rats_ = shrubcommit->rats;
lfs_size_t rat_count_ = shrubcommit->rat_count;
// reset shrub if it doesn't live in our block, this happens // reset shrub if it doesn't live in our block, this happens
// when converting from a btree // when converting from a btree
if (!lfsr_shrub_isshrub(shrub)) { if (!lfsr_bshrub_isbshrub(bshrub_)) {
shrub_->blocks[0] = mdir->rbyd.blocks[0]; bshrub_->shrub_.blocks[0] = mdir->rbyd.blocks[0];
shrub_->trunk = LFSR_RBYD_ISSHRUB | 0; bshrub_->shrub_.trunk = LFSR_RBYD_ISSHRUB | 0;
shrub_->weight = 0; bshrub_->shrub_.weight = 0;
} }
// commit to shrub // commit to shrub
int err = lfsr_shrub_commit(lfs, &mdir->rbyd, int err = lfsr_shrub_commit(lfs,
shrub_, shrubcommit->rid, &mdir->rbyd, &bshrub_->shrub_,
shrubcommit->rats, shrubcommit->rat_count); rid_, rats_, rat_count_);
if (err) { if (err) {
return err; return err;
} }
@@ -7442,9 +7443,7 @@ static int lfsr_mdir_commit__(lfs_t *lfs, lfsr_mdir_t *mdir,
// //
// TODO should we preserve mode for all of these? // TODO should we preserve mode for all of these?
} else if (lfsr_tag_key(rats[i].tag) == LFSR_TAG_SHRUBTRUNK) { } else if (lfsr_tag_key(rats[i].tag) == LFSR_TAG_SHRUBTRUNK) {
// find the staging shrub lfsr_bshrub_t *bshrub_ = (lfsr_bshrub_t*)rats[i].cat;
lfsr_shrub_t *shrub = (lfsr_shrub_t*)rats[i].cat;
lfsr_shrub_t *shrub_ = shrub + 1;
uint8_t shrub_buf[LFSR_SHRUB_DSIZE]; uint8_t shrub_buf[LFSR_SHRUB_DSIZE];
int err = lfsr_rbyd_appendrat(lfs, &mdir->rbyd, int err = lfsr_rbyd_appendrat(lfs, &mdir->rbyd,
@@ -7453,7 +7452,7 @@ static int lfsr_mdir_commit__(lfs_t *lfs, lfsr_mdir_t *mdir,
lfsr_tag_mode(rats[i].tag) | LFSR_TAG_BSHRUB, lfsr_tag_mode(rats[i].tag) | LFSR_TAG_BSHRUB,
rats[i].weight, rats[i].weight,
// note we use the staged trunk here // note we use the staged trunk here
LFSR_DATA_SHRUB(shrub_, shrub_buf))); LFSR_DATA_SHRUB(&bshrub_->shrub_, shrub_buf)));
if (err) { if (err) {
return err; return err;
} }
@@ -12351,7 +12350,7 @@ int lfsr_file_sync(lfs_t *lfs, lfsr_file_t *file) {
} else if (lfsr_bshrub_isbshrub(&file->b)) { } else if (lfsr_bshrub_isbshrub(&file->b)) {
rats[rat_count++] = LFSR_RAT_SHRUBTRUNK( rats[rat_count++] = LFSR_RAT_SHRUBTRUNK(
LFSR_TAG_SUB | LFSR_TAG_SHRUBTRUNK, 0, LFSR_TAG_SUB | LFSR_TAG_SHRUBTRUNK, 0,
&file->b.shrub); &file->b);
// btree? // btree?
} else if (lfsr_bshrub_isbtree(&file->b)) { } else if (lfsr_bshrub_isbtree(&file->b)) {
rats[rat_count++] = LFSR_RAT( rats[rat_count++] = LFSR_RAT(
+3 -3
View File
@@ -1097,19 +1097,19 @@ code = '''
lfsr_mdir_commit(&lfs, &file.b.o.mdir, LFSR_RATS( lfsr_mdir_commit(&lfs, &file.b.o.mdir, LFSR_RATS(
LFSR_RAT_SHRUBCOMMIT( LFSR_RAT_SHRUBCOMMIT(
LFSR_TAG_SHRUBCOMMIT, 0, LFSR_TAG_SHRUBCOMMIT, 0,
&file.b.shrub, 0, ((lfsr_rat_t[]){ &file.b, 0, ((lfsr_rat_t[]){
LFSR_RAT(LFSR_TAG_DATA, +1, LFSR_DATA_BUF("?", 1))}), LFSR_RAT(LFSR_TAG_DATA, +1, LFSR_DATA_BUF("?", 1))}),
1))) => 0; 1))) => 0;
lfsr_mdir_commit(&lfs, &file.b.o.mdir, LFSR_RATS( lfsr_mdir_commit(&lfs, &file.b.o.mdir, LFSR_RATS(
LFSR_RAT_SHRUBCOMMIT( LFSR_RAT_SHRUBCOMMIT(
LFSR_TAG_SHRUBCOMMIT, 0, LFSR_TAG_SHRUBCOMMIT, 0,
&file.b.shrub, 0, ((lfsr_rat_t[]){ &file.b, 0, ((lfsr_rat_t[]){
LFSR_RAT(LFSR_TAG_RM, -1, LFSR_DATA_NULL())}), LFSR_RAT(LFSR_TAG_RM, -1, LFSR_DATA_NULL())}),
1))) => 0; 1))) => 0;
lfsr_mdir_commit(&lfs, &file.b.o.mdir, LFSR_RATS( lfsr_mdir_commit(&lfs, &file.b.o.mdir, LFSR_RATS(
LFSR_RAT_SHRUBTRUNK( LFSR_RAT_SHRUBTRUNK(
LFSR_TAG_SUB | LFSR_TAG_SHRUBTRUNK, 0, LFSR_TAG_SUB | LFSR_TAG_SHRUBTRUNK, 0,
&file.b.shrub))) => 0; &file.b))) => 0;
lfsr_file_close(&lfs, &file) => 0; lfsr_file_close(&lfs, &file) => 0;