Shifted block_recycles so 0 => pure copy-on-write
This makes a bit more sense with the new block_recycles name. block_recycles=0 (previously block_recycles=1) requires 1 erase, but it doesn't really "recycle" the block. With this change, block_recycles=1 "recycles" the block once (2 erases in total) before relocating, which I think is a bit more intuitive. Note, this sort of messes with our power-of-2 rounding, as the block_recycles is technically rounded down to the nearest power-of-2 after adding 1: - block_recycles=1022 -> 512 erases - block_recycles=1023 -> 1024 erases - block_recycles=1024 -> 1024 erases - block_recycles=1025 -> 1024 erases But I'm going to keep the block_recycles description more-or-less as is for now, as I think this extra detail is more confusing than useful, powers-of-2 stay powers-of-2, and the <=block_recycles contraint is not violated.
This commit is contained in:
@@ -15286,9 +15286,6 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
|
||||
// // wear-leveling.
|
||||
// LFS_ASSERT(lfs->cfg->block_cycles != 0);
|
||||
|
||||
// block_recycles should not be zero, use -1 to disable
|
||||
LFS_ASSERT(lfs->cfg->block_recycles != 0);
|
||||
|
||||
// inline_size must be <= block_size/4
|
||||
LFS_ASSERT(lfs->cfg->inline_size <= lfs->cfg->block_size/4);
|
||||
// shrub_size must be <= block_size/4
|
||||
@@ -15375,12 +15372,13 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
|
||||
|
||||
// find the number of bits to use for recycle counters
|
||||
//
|
||||
// Multiply by 2, since we alternate which metadata block we erase each
|
||||
// compaction, and limit to 28-bits so we always have some bits to
|
||||
// determine the most recent revision.
|
||||
// Add 1, to include the initial erase, multiply by 2, since we
|
||||
// alternate which metadata block we erase each compaction, and limit
|
||||
// to 28-bits so we always have some bits to determine the most recent
|
||||
// revision.
|
||||
if (lfs->cfg->block_recycles != -1) {
|
||||
lfs->recycle_bits = lfs_min(
|
||||
lfs_nlog2(2*lfs->cfg->block_recycles+1)-1,
|
||||
lfs_nlog2(2*(lfs->cfg->block_recycles+1)+1)-1,
|
||||
28);
|
||||
} else {
|
||||
lfs->recycle_bits = -1;
|
||||
|
||||
Reference in New Issue
Block a user