Cleaned up rbyd rebalance implementation, optimized things

- Since both trunks emit altle tags now, reworked the trunk merging to
  reuse more code.

- Changed lfsr_mdir_fetch to rely on trunk=0 to detect the no-commit
  state. This is purely for consistency.

  This actually broke some tests that committed nothing, resulting in
  trunk-less rbyds, which is a bit concerning, but I don't think
  trunk-less rbyds will ever be valid in our system?

- Simplified lfsr_rbyd_estimate calculation, merged lfsr_rbyd_bisect
  since this is almost always needed after an estimated failure, and
  that way dependent function have to call fewer things to implement
  rbyd splitting.

- Dropped vestigial names for now, though need to revisit this later.

After these changes the code size difference between rebalancing and
appending is a bit smaller at ~392 bytes: 16208 -> 16600 (+2.4%). It's
interesting to note this is mostly because the conservative overhead
calculation is easier with rebalancing.

In theory this also saves some stack usage, but since I'm measuring
maximum stack usage it doesn't show up since it's not on the deepest
path.
This commit is contained in:
Christopher Haster
2023-06-25 15:42:27 -05:00
parent 43dc3a5c8d
commit f311d1102c
2 changed files with 242 additions and 313 deletions
-60
View File
@@ -28,12 +28,6 @@ code = '''
};
lfsr_rbyd_t rbyd;
// try an empty commit
rbyd = init_rbyd;
lfs_bd_erase(&lfs, rbyd.block) => 0;
lfsr_rbyd_commit(&lfs, &rbyd, NULL, 0) => 0;
lfsr_rbyd_fetch(&lfs, &rbyd, rbyd.block, 0) => 0;
// commit with one attribute
rbyd = init_rbyd;
lfs_bd_erase(&lfs, rbyd.block) => 0;
@@ -65,12 +59,6 @@ code = '''
};
lfsr_rbyd_t rbyd;
// try an empty commit
rbyd = init_rbyd;
lfs_bd_erase(&lfs, rbyd.block) => 0;
lfsr_rbyd_commit(&lfs, &rbyd, NULL, 0) => 0;
lfsr_rbyd_fetch(&lfs, &rbyd, rbyd.block, 0) => 0;
// commit with one attribute
rbyd = init_rbyd;
lfs_bd_erase(&lfs, rbyd.block) => 0;
@@ -139,18 +127,6 @@ code = '''
lfs_ssize_t id_;
lfsr_data_t data_;
// try an empty commit
rbyd = init_rbyd;
lfs_bd_erase(&lfs, rbyd.block) => 0;
lfsr_rbyd_commit(&lfs, &rbyd, NULL, 0) => 0;
lfsr_rbyd_lookupnext(&lfs, &rbyd, -1, LFSR_TAG_UATTR(1),
&id_, &tag_, NULL, &data_) => LFS_ERR_NOENT;
lfsr_rbyd_fetch(&lfs, &rbyd, rbyd.block, 0) => 0;
lfsr_rbyd_lookupnext(&lfs, &rbyd, -1, LFSR_TAG_UATTR(1),
&id_, &tag_, NULL, &data_) => LFS_ERR_NOENT;
// commit with one attribute
rbyd = init_rbyd;
lfs_bd_erase(&lfs, rbyd.block) => 0;
@@ -261,18 +237,6 @@ code = '''
lfs_ssize_t id_;
lfsr_data_t data_;
// try an empty commit
rbyd = init_rbyd;
lfs_bd_erase(&lfs, rbyd.block) => 0;
lfsr_rbyd_commit(&lfs, &rbyd, NULL, 0) => 0;
lfsr_rbyd_lookupnext(&lfs, &rbyd, -1, LFSR_TAG_UATTR(1),
&id_, &tag_, NULL, &data_) => LFS_ERR_NOENT;
lfsr_rbyd_fetch(&lfs, &rbyd, rbyd.block, 0) => 0;
lfsr_rbyd_lookupnext(&lfs, &rbyd, -1, LFSR_TAG_UATTR(1),
&id_, &tag_, NULL, &data_) => LFS_ERR_NOENT;
// commit with one attribute
rbyd = init_rbyd;
lfs_bd_erase(&lfs, rbyd.block) => 0;
@@ -383,18 +347,6 @@ code = '''
lfsr_rbyd_t rbyd;
uint8_t buffer[4];
// try an empty commit
rbyd = init_rbyd;
lfs_bd_erase(&lfs, rbyd.block) => 0;
lfsr_rbyd_commit(&lfs, &rbyd, NULL, 0) => 0;
lfsr_rbyd_get(&lfs, &rbyd, -1, LFSR_TAG_UATTR(1), buffer, 4)
=> LFS_ERR_NOENT;
lfsr_rbyd_fetch(&lfs, &rbyd, rbyd.block, 0) => 0;
lfsr_rbyd_get(&lfs, &rbyd, -1, LFSR_TAG_UATTR(1), buffer, 4)
=> LFS_ERR_NOENT;
// commit with one attribute
rbyd = init_rbyd;
lfs_bd_erase(&lfs, rbyd.block) => 0;
@@ -474,18 +426,6 @@ code = '''
lfsr_rbyd_t rbyd;
uint8_t buffer[4];
// try an empty commit
rbyd = init_rbyd;
lfs_bd_erase(&lfs, rbyd.block) => 0;
lfsr_rbyd_commit(&lfs, &rbyd, NULL, 0) => 0;
lfsr_rbyd_get(&lfs, &rbyd, -1, LFSR_TAG_UATTR(1), buffer, 4)
=> LFS_ERR_NOENT;
lfsr_rbyd_fetch(&lfs, &rbyd, rbyd.block, 0) => 0;
lfsr_rbyd_get(&lfs, &rbyd, -1, LFSR_TAG_UATTR(1), buffer, 4)
=> LFS_ERR_NOENT;
// commit with one attribute
rbyd = init_rbyd;
lfs_bd_erase(&lfs, rbyd.block) => 0;