Skip to content

Commit

Permalink
fs: littlefs: Fix lookahead buffer sizing
Browse files Browse the repository at this point in the history
The lookahead buffer is a bitmap containing info on free blocks and does
not have a minimum size or an alignment requirement.

This fixes the arbitrary 4 * block_size requirement for block devices
and fixes Kconfig documentation to remove a reference to nonexistent
8 byte alignment requirement.

Signed-off-by: Djordje Nedic <nedic.djordje2@gmail.com>
  • Loading branch information
DNedic authored and kartben committed Jan 9, 2025
1 parent 2a206a0 commit 30bac03
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
3 changes: 1 addition & 2 deletions subsys/fs/Kconfig.littlefs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ config FS_LITTLEFS_LOOKAHEAD_SIZE
help
A larger lookahead buffer increases the number of blocks found
during an allocation pass. The lookahead buffer is stored as a
compact bitmap, so each byte of RAM can track 8 blocks. Must
be a multiple of 8.
compact bitmap, so each byte of RAM can track 8 blocks.

config FS_LITTLEFS_BLOCK_CYCLES
int "Number of erase cycles before moving data to another block"
Expand Down
9 changes: 1 addition & 8 deletions subsys/fs/littlefs_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -844,8 +844,6 @@ static int littlefs_init_cfg(struct fs_littlefs *fs, int flags)
lcp->context = fs->backend;
/* Set the validated/defaulted values. */
if (littlefs_on_blkdev(flags)) {
lfs_size_t new_lookahead_size = block_size * 4;

lcp->read = lfs_api_read_blk;
lcp->prog = lfs_api_prog_blk;
lcp->erase = lfs_api_erase_blk;
Expand All @@ -859,12 +857,7 @@ static int littlefs_init_cfg(struct fs_littlefs *fs, int flags)
}
lcp->cache_size = ROUND_DOWN(cache_size, block_size);

if (lookahead_size < new_lookahead_size) {
LOG_ERR("Configured lookahead size is too small: %d < %d",
lookahead_size, new_lookahead_size);
return -ENOMEM;
}
lcp->lookahead_size = new_lookahead_size;
lcp->lookahead_size = lookahead_size;

lcp->sync = lfs_api_sync_blk;

Expand Down

0 comments on commit 30bac03

Please sign in to comment.