Compare commits

..

1 Commits

Author SHA1 Message Date
Christopher Haster
ab59ab7f8d Bump default inline_max up to 1/4 block size
As noted by amgross, the current inline_max default (when littlefs
switches from inline files to CTZ skip-lists) does not match the
theoretical value in DESIGN.md.

The reason for this is 1/8 was chosen as a safer default during
development, due to concerns that 1/4 + mdirs splitting at 1/2 would
lead to poor distribution of large inline files in mdirs.

However, two things have happened since then:

1. Experiments have show "wasted" mdir space is less of a concern than
   initially thought. Extra mdir space contributes to logging, delays
   mdir compaction, and can overall lead to better performance.

2. inline_size was added as a configuration option, so if 1/4 is
   problematic users can always override it.

So bumping this back up to 1/4 may make sense.
2025-09-30 12:15:26 -05:00
3 changed files with 5 additions and 14 deletions

View File

@@ -267,11 +267,7 @@ License Identifiers that are here available: http://spdx.org/licenses/
to create images of the filesystem on your PC. Check if littlefs will fit
your needs, create images for a later download to the target memory or
inspect the content of a binary image of the target memory.
- [littlefs-toy] - A command-line tool for creating and working with littlefs
images. Uses syntax similar to tar command for ease of use. Supports working
on littlefs images embedded inside another file (firmware image, etc).
- [littlefs2-rust] - A Rust wrapper for littlefs. This project allows you
to use littlefs in a Rust-friendly API, reaping the benefits of Rust's memory
safety and other guarantees.
@@ -325,7 +321,6 @@ License Identifiers that are here available: http://spdx.org/licenses/
[littlefs-js]: https://github.com/geky/littlefs-js
[littlefs-js-demo]:http://littlefs.geky.net/demo.html
[littlefs-python]: https://pypi.org/project/littlefs-python/
[littlefs-toy]: https://github.com/tjko/littlefs-toy
[littlefs2-rust]: https://crates.io/crates/littlefs2
[nim-littlefs]: https://github.com/Graveflo/nim-littlefs
[chamelon]: https://github.com/yomimono/chamelon

10
lfs.c
View File

@@ -93,7 +93,6 @@ static int lfs_bd_read(lfs_t *lfs,
// bypass cache?
diff = lfs_aligndown(diff, lfs->cfg->read_size);
int err = lfs->cfg->read(lfs->cfg, block, off, data, diff);
LFS_ASSERT(err <= 0);
if (err) {
return err;
}
@@ -740,7 +739,6 @@ static lfs_stag_t lfs_dir_getslice(lfs_t *lfs, const lfs_mdir_t *dir,
int err = lfs_bd_read(lfs,
NULL, &lfs->rcache, sizeof(ntag),
dir->pair[0], off, &ntag, sizeof(ntag));
LFS_ASSERT(err <= 0);
if (err) {
return err;
}
@@ -769,7 +767,6 @@ static lfs_stag_t lfs_dir_getslice(lfs_t *lfs, const lfs_mdir_t *dir,
err = lfs_bd_read(lfs,
NULL, &lfs->rcache, diff,
dir->pair[0], off+sizeof(tag)+goff, gbuffer, diff);
LFS_ASSERT(err <= 0);
if (err) {
return err;
}
@@ -1282,7 +1279,6 @@ static lfs_stag_t lfs_dir_fetchmatch(lfs_t *lfs,
if (err == LFS_ERR_CORRUPT) {
break;
}
return err;
}
lfs_fcrc_fromle32(&fcrc);
@@ -2268,7 +2264,7 @@ static int lfs_dir_relocatingcommit(lfs_t *lfs, lfs_mdir_t *dir,
}
}
if (dir->erased && dir->count < 0xff) {
if (dir->erased) {
// try to commit
struct lfs_commit commit = {
.block = dir->pair[0],
@@ -4335,7 +4331,7 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
LFS_ASSERT(lfs->cfg->inline_max == (lfs_size_t)-1
|| lfs->cfg->inline_max <= ((lfs->cfg->metadata_max)
? lfs->cfg->metadata_max
: lfs->cfg->block_size)/8);
: lfs->cfg->block_size)/4);
lfs->inline_max = lfs->cfg->inline_max;
if (lfs->inline_max == (lfs_size_t)-1) {
lfs->inline_max = 0;
@@ -4346,7 +4342,7 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
lfs->attr_max,
((lfs->cfg->metadata_max)
? lfs->cfg->metadata_max
: lfs->cfg->block_size)/8));
: lfs->cfg->block_size)/4));
}
// setup default state

2
lfs.h
View File

@@ -277,7 +277,7 @@ struct lfs_config {
// Optional upper limit on inlined files in bytes. Inlined files live in
// metadata and decrease storage requirements, but may be limited to
// improve metadata-related performance. Must be <= cache_size, <=
// attr_max, and <= block_size/8. Defaults to the largest possible
// attr_max, and <= block_size/4. Defaults to the largest possible
// inline_max when zero.
//
// Set to -1 to disable inlined files.