Skip to content

Commit 29855b4

Browse files
r2r0cfriedt
authored andcommitted
fs: allow to configure per-alloaction heap overhead
The size of overhead for each heap allocation can change after heap implementation change and such change impacts automatic calculation of heap size for littleFS. This patch allows per-alloaction overhead to be configurable and then automatic heap size calculation can be adjusted without code change. This is a temporary fix until per-alloaction overhead value will be available from kernel internals. Fixes #36962 Signed-off-by: Artur Lipowski <[email protected]>
1 parent 82fd59a commit 29855b4

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

subsys/fs/Kconfig.littlefs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,19 @@ config FS_LITTLEFS_FC_HEAP_SIZE
8989
support up to FS_LITTLE_FS_NUM_FILES blocks of
9090
FS_LITTLEFS_CACHE_SIZE bytes.
9191

92+
if FS_LITTLEFS_FC_HEAP_SIZE <= 0
93+
94+
config FS_LITTLEFS_HEAP_PER_ALLOC_OVERHEAD_SIZE
95+
int "Size of per-allocation overhead for littleFS heap in bytes"
96+
default 32
97+
help
98+
In case when total size of littleFS heap is automatically calculated
99+
we need to take into account overhead caused per block allocation.
100+
For the purpose of heap size calculation the size of each cache block
101+
will be increased by this value.
102+
NOTE: when your app fails to open pre-defined number of files, as set
103+
by FS_LITTLEFS_NUM_FILES, try to increase the value.
104+
105+
endif # FS_LITTLEFS_FC_HEAP_SIZE <= 0
106+
92107
endif # FILE_SYSTEM_LITTLEFS

subsys/fs/littlefs_fs.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@ static K_MEM_SLAB_DEFINE(lfs_dir_pool, sizeof(struct lfs_dir),
4141
* the filecache heap. This relates to the CHUNK_UNIT parameter in
4242
* the heap implementation, but that value is not visible outside the
4343
* kernel.
44+
* FIXME: value for this macro should be rather taken from the Kernel
45+
* internals than set by user, but we do not have a way to do so now.
4446
*/
45-
#define FC_HEAP_PER_ALLOC_OVERHEAD 24U
47+
#define FC_HEAP_PER_ALLOC_OVERHEAD CONFIG_FS_LITTLEFS_HEAP_PER_ALLOC_OVERHEAD_SIZE
4648

4749
#if (CONFIG_FS_LITTLEFS_FC_HEAP_SIZE - 0) <= 0
50+
BUILD_ASSERT((CONFIG_FS_LITTLEFS_HEAP_PER_ALLOC_OVERHEAD_SIZE % 8) == 0);
4851
/* Auto-generate heap size from cache size and number of files */
4952
#undef CONFIG_FS_LITTLEFS_FC_HEAP_SIZE
5053
#define CONFIG_FS_LITTLEFS_FC_HEAP_SIZE \

0 commit comments

Comments
 (0)