Fixed incorrect condition preventing left fragment coalescing
The condition for checking if the left fragment could be coalesced was wrong, preventing a common coalescing chance in linear rewrites, and leaving a weird 1-flush-sized alignment issue in the fragments: Was: lfsr_data_size(&bptr.data) < lfs->cfg->fragment_size Should be: fragment_end - (bid-(weight-1)) <= lfs->cfg->fragment_size This was correct for the right fragment coalescing, not sure how the left ended up messed up. (Actually I do know why, the math here is dense, complex, and subtle, a nasty combo.)
This commit is contained in:
@@ -10380,10 +10380,9 @@ static int lfsr_ftree_flush(lfs_t *lfs, lfsr_ftree_t *ftree,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// can we coalesce?
|
// can we coalesce?
|
||||||
if (bid-(weight-1) + lfsr_data_size(&bptr.data)
|
if (bid-(weight-1) + lfsr_data_size(&bptr.data) >= fragment_start
|
||||||
>= fragment_start
|
&& fragment_end - (bid-(weight-1))
|
||||||
&& lfsr_data_size(&bptr.data)
|
<= lfs->cfg->fragment_size) {
|
||||||
< lfs->cfg->fragment_size) {
|
|
||||||
// coalesce, but truncate to our fragment size
|
// coalesce, but truncate to our fragment size
|
||||||
// TODO this is a bit of a hacky way to prepend data...
|
// TODO this is a bit of a hacky way to prepend data...
|
||||||
LFS_ASSERT(data_count == 1);
|
LFS_ASSERT(data_count == 1);
|
||||||
@@ -10405,8 +10404,7 @@ static int lfsr_ftree_flush(lfs_t *lfs, lfsr_ftree_t *ftree,
|
|||||||
// note this may the same as our left sibling
|
// note this may the same as our left sibling
|
||||||
if (fragment_end < lfsr_ftree_size(ftree)
|
if (fragment_end < lfsr_ftree_size(ftree)
|
||||||
// don't bother to lookup right if fragment is already full
|
// don't bother to lookup right if fragment is already full
|
||||||
&& fragment_end - fragment_start
|
&& fragment_end - fragment_start < lfs->cfg->fragment_size) {
|
||||||
< lfs->cfg->fragment_size) {
|
|
||||||
lfsr_bid_t bid;
|
lfsr_bid_t bid;
|
||||||
lfsr_tag_t tag;
|
lfsr_tag_t tag;
|
||||||
lfsr_bid_t weight;
|
lfsr_bid_t weight;
|
||||||
@@ -10420,8 +10418,7 @@ static int lfsr_ftree_flush(lfs_t *lfs, lfsr_ftree_t *ftree,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// can we coalesce?
|
// can we coalesce?
|
||||||
if (fragment_end < bid-(weight-1)
|
if (fragment_end < bid-(weight-1) + lfsr_data_size(&bptr.data)
|
||||||
+ lfsr_data_size(&bptr.data)
|
|
||||||
&& bid-(weight-1) + lfsr_data_size(&bptr.data)
|
&& bid-(weight-1) + lfsr_data_size(&bptr.data)
|
||||||
- fragment_start
|
- fragment_start
|
||||||
<= lfs->cfg->fragment_size) {
|
<= lfs->cfg->fragment_size) {
|
||||||
|
|||||||
Reference in New Issue
Block a user