Reverted second resume-crystallization check
Gah! I'm not sure why I thought this code was so useless... Without it
we risk immediate recrystallization if the crystal heuristic pushes
crystal_start such that it overlaps the crystallizing block.
We may not make progress on our buffer, but triggering recrystallization
isn't great.
Considering this really doesn't add _that_ much code, I think this is a
case where we are better safe than sorry:
code stack ctx
before: 37092 2304 636
after: 37140 (+0.1%) 2304 (+0.0%) 636 (+0.0%)
This logic only gets hit after we decide to allocate a new block, so
there's no risk of losing erased-state to potential fragments.
---
In benchmarking it also looks like this recoups most of the extra disk
usage introduced by lazy rewrite crystallization. So that's a good
thing... I think...
This commit is contained in:
@@ -12585,6 +12585,39 @@ static int lfsr_file_flush_(lfs_t *lfs, lfsr_file_t *file,
|
||||
// exceeded crystallization threshold? we need to allocate a
|
||||
// new block
|
||||
|
||||
// can we resume crystallizing with the fragments on disk?
|
||||
block_start = file->leaf.pos
|
||||
- lfsr_bptr_off(&file->leaf.bptr);
|
||||
block_end = file->leaf.pos
|
||||
+ lfsr_bptr_size(&file->leaf.bptr);
|
||||
if (lfsr_bptr_isbptr(&file->leaf.bptr)
|
||||
&& lfsr_bptr_iserased(&file->leaf.bptr)
|
||||
&& crystal_start >= block_end
|
||||
&& crystal_start < block_start + lfs->cfg->block_size) {
|
||||
int err = lfsr_file_crystallize_(lfs, file,
|
||||
file->leaf.pos - lfsr_bptr_off(&file->leaf.bptr),
|
||||
crystal_end
|
||||
- (file->leaf.pos - lfsr_bptr_off(&file->leaf.bptr)),
|
||||
crystal_end
|
||||
- (file->leaf.pos - lfsr_bptr_off(&file->leaf.bptr)),
|
||||
pos, buffer, size);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// update buffer state, this may or may not make progress
|
||||
lfs_soff_t d = lfs_max(
|
||||
file->leaf.pos + lfsr_bptr_size(&file->leaf.bptr),
|
||||
pos) - pos;
|
||||
pos += d;
|
||||
buffer += lfs_min(d, size);
|
||||
size -= lfs_min(d, size);
|
||||
|
||||
// we should be aligned now
|
||||
aligned = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
// if we're mid-crystallization, finish crystallizing the block
|
||||
// and graft it into our bshrub/btree
|
||||
int err = lfsr_file_crystallize(lfs, file);
|
||||
|
||||
Reference in New Issue
Block a user