Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/littlefs-project/littlefs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Haster <chaster@utexas.edu>2019-01-15 02:53:41 +0300
committerChristopher Haster <chaster@utexas.edu>2019-01-23 06:02:39 +0300
commit916b30855878edb7d5af77d9cd2b661a3cd4f733 (patch)
tree9fbe7c23356a8ab86167aa637862cf600414022f
parente1f9d2bc09b194ef9a262b54513fb6cd7a626dee (diff)
Fixed excessive waste from overly large inline files
Before this, there were some safety limits, but there was no real default limit to the size of inline files other than the amount of RAM available. On PCs, this meant that inline files were free to fill up directory blocks to a little under the block size. However this is very wasteful in terms of storage space. Because of splitting limits to keep the compact runtime reasonable, each byte of an inline files uses 4x the amount. Fortunately we can find an optimal inline limit: Inline file waste for n bytes = 3n CTZ file waste for n bytes = B - n Where B = block size Solving for n = B/4 So the optimal inline limit is B/4. However, this assumes a perfect inline file and no metadata. We can decrease this to B/8 to give a bit more breathing room for directory+file metadata.
-rw-r--r--lfs.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/lfs.c b/lfs.c
index 08ba3f0..5d00d78 100644
--- a/lfs.c
+++ b/lfs.c
@@ -2710,7 +2710,8 @@ lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file,
if ((file->flags & LFS_F_INLINE) &&
lfs_max(file->pos+nsize, file->ctz.size) >
- lfs_min(lfs->cfg->cache_size, LFS_ATTR_MAX)) {
+ lfs_min(LFS_ATTR_MAX, lfs_min(
+ lfs->cfg->cache_size, lfs->cfg->block_size/8))) {
// inline file doesn't fit anymore
file->off = file->pos;
int err = lfs_file_relocate(lfs, file);