Fixed never fully fragmenting bptrs

Bit of a silly, but problematic, bug, probably introduced during the
various lfsr_bptr_t/lfsr_data_t reworks, but basically we never actually
fragmented the last fragment in a bptr.

We were fragmenting all fragments in a bptr _above_ fragment_size, but
then we'd stop at the last fragment and keep it around as a bptr,
completely wasting all of the work to fragment the block. The reason for
the different behavior being that we can combine the last fragment with
the carved data to avoid an additional commit.

Fortunately the solution is pretty non-invasive. We can just assume any
bptrs <= fragment_size should be written out as fragments.

Added test_fwrite_truncate_litmus_fragment and
test_fwrite_fruncate_litmus_fragment to catch this in the future.

Code changes:

           code          stack          ctx
  before: 35588           2448          640
  after:  35600 (+0.0%)   2448 (+0.0%)  640 (+0.0%)
This commit is contained in:
Christopher Haster
2025-04-19 12:29:35 -05:00
parent 6d97398efc
commit fc095af472
2 changed files with 293 additions and 2 deletions
+4 -2
View File
@@ -11642,7 +11642,8 @@ static int lfsr_file_carve(lfs_t *lfs, lfsr_file_t *file,
LFSR_TAG_GROW, -(bid+1 - pos));
// carve fragment?
} else if (!lfsr_bptr_isbptr(&bptr_)) {
} else if (!lfsr_bptr_isbptr(&bptr_)
|| lfsr_data_size(l.data) <= lfs->cfg->fragment_size) {
rattrs[rattr_count++] = LFSR_RATTR_DATA(
LFSR_TAG_GROW | LFSR_TAG_MASK8 | LFSR_TAG_DATA,
-(bid+1 - pos),
@@ -11688,7 +11689,8 @@ static int lfsr_file_carve(lfs_t *lfs, lfsr_file_t *file,
rattr.weight += bid+1 - (pos+weight);
// carve fragment?
} else if (!lfsr_bptr_isbptr(&bptr_)) {
} else if (!lfsr_bptr_isbptr(&bptr_)
|| lfsr_data_size(r.data) <= lfs->cfg->fragment_size) {
r_rattr_ = LFSR_RATTR_DATA(
LFSR_TAG_DATA, bid+1 - (pos+weight),
&r.data);