mirror of
https://github.com/eledio-devices/thirdparty-littlefs.git
synced 2025-10-30 16:15:40 +01:00
Changed lfs_dir_alloc to maximize block cycles for new metadata pairs
Previously we only bumped the revision count if an eviction would occur immediately (and possibly corrupt littlefs). This works, but does risk an unoptimal superblock size if an almost-exhausted superblock was allocated during lfs_format. As pointed out by tim-nordell-nimbelink, we can align the revision count to maximize the number of block cycles without breaking the existing requirements of increasing revision counts. As an added benefit, littlefs's wear-leveling should behave more consistently after this change.
This commit is contained in:
10
lfs.c
10
lfs.c
@@ -1375,11 +1375,11 @@ static int lfs_dir_alloc(lfs_t *lfs, lfs_mdir_t *dir) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// make sure we don't immediately evict, see lfs_dir_compact for why
|
||||
// this check is so complicated
|
||||
if (lfs->cfg->block_cycles > 0 &&
|
||||
(dir->rev + 1) % ((lfs->cfg->block_cycles+1)|1) == 0) {
|
||||
dir->rev += 1;
|
||||
// to make sure we don't immediately evict, align the new revision count
|
||||
// to our block_cycles modulus, see lfs_dir_compact for why our modulus
|
||||
// is tweaked this way
|
||||
if (lfs->cfg->block_cycles > 0) {
|
||||
dir->rev = lfs_alignup(dir->rev, ((lfs->cfg->block_cycles+1)|1));
|
||||
}
|
||||
|
||||
// set defaults
|
||||
|
||||
Reference in New Issue
Block a user