From cb9bda5a942a46a4b3f6c88df83490d0919b760d Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Tue, 7 Oct 2025 00:05:33 -0500 Subject: [PATCH] gbmap: Renamed gbmap_scan_thresh -> gbmap_rebuild_thresh I think a good rule of thumb is if you refer to some variable/config/ field with a different name in comments/writing/etc more often than not, you should just rename the variable/config/field to match. So yeah, gbmap_rebuild_thresh controls when the gbmap is rebuilt. Also touched up the doc comment a bit. --- lfs3.c | 2 +- lfs3.h | 13 +++--- runners/bench_runner.h | 92 +++++++++++++++++++++--------------------- runners/test_runner.h | 92 +++++++++++++++++++++--------------------- 4 files changed, 100 insertions(+), 99 deletions(-) diff --git a/lfs3.c b/lfs3.c index e920a9a2..89ecb1d8 100644 --- a/lfs3.c +++ b/lfs3.c @@ -10973,7 +10973,7 @@ static inline int lfs3_alloc_ckpoint(lfs3_t *lfs3) { // do we need to rebuild the gbmap? if (lfs3_f_isgbmap(lfs3->flags) && lfs3->lookahead.gbmapped < lfs3_min( - lfs3->cfg->gbmap_scan_thresh, + lfs3->cfg->gbmap_rebuild_thresh, lfs3->block_count)) { int err = lfs3_alloc_rebuildgbmap(lfs3); if (err) { diff --git a/lfs3.h b/lfs3.h index 9e8c855b..f2912840 100644 --- a/lfs3.h +++ b/lfs3.h @@ -546,15 +546,16 @@ struct lfs3_cfg { lfs3_size_t crystal_thresh; #endif - // Threshold for when to rebuild block-map information. littlefs - // will attempt to rebuild the block-map when fewer than this many - // blocks are known. Larger values rebuild the block-map more + // Threshold for when to rebuild the global on-disk block-map (gbmap). + // littlefs will attempt to rebuild the gbmap when fewer than this + // many blocks are known. Larger values rebuild the gbmap more // frequently, reducing the chance of falling back to a slower - // allocator at a performance cost. + // allocator at the cost of amortized allocator throughput. // - // 0 only rebuilds the block-map when empty. + // 0 only rebuilds the gbmap when empty, but note rebuilding the + // gbmap may require allocating blocks. #ifdef LFS3_GBMAP - lfs3_block_t gbmap_scan_thresh; + lfs3_block_t gbmap_rebuild_thresh; #endif }; diff --git a/runners/bench_runner.h b/runners/bench_runner.h index a1cba4dd..ff57f25d 100644 --- a/runners/bench_runner.h +++ b/runners/bench_runner.h @@ -103,29 +103,29 @@ void bench_permutation(size_t i, uint32_t *buffer, size_t size); // a few preconfigured defines that control how benches run #define BENCH_IMPLICIT_DEFINES \ - /* name value (overridable) */ \ - BENCH_DEFINE(READ_SIZE, 1 ) \ - BENCH_DEFINE(PROG_SIZE, 1 ) \ - BENCH_DEFINE(BLOCK_SIZE, 4096 ) \ - BENCH_DEFINE(BLOCK_COUNT, DISK_SIZE/BLOCK_SIZE ) \ - BENCH_DEFINE(DISK_SIZE, 1024*1024 ) \ - BENCH_DEFINE(BLOCK_RECYCLES, -1 ) \ - BENCH_DEFINE(RCACHE_SIZE, LFS3_MAX(16, READ_SIZE) ) \ - BENCH_DEFINE(PCACHE_SIZE, LFS3_MAX(16, PROG_SIZE) ) \ - BENCH_DEFINE(FILE_CACHE_SIZE, 16 ) \ - BENCH_DEFINE(LOOKAHEAD_SIZE, 16 ) \ - BENCH_DEFINE(GC_FLAGS, 0 ) \ - BENCH_DEFINE(GC_STEPS, 0 ) \ - BENCH_DEFINE(GC_COMPACT_THRESH, 0 ) \ - BENCH_DEFINE(INLINE_SIZE, BLOCK_SIZE/4 ) \ - BENCH_DEFINE(FRAGMENT_SIZE, LFS3_MIN(BLOCK_SIZE/8, 512) ) \ - BENCH_DEFINE(CRYSTAL_THRESH, BLOCK_SIZE/8 ) \ - BENCH_DEFINE(GBMAP_SCAN_THRESH, BLOCK_COUNT/4 ) \ - BENCH_DEFINE(ERASE_VALUE, 0xff ) \ - BENCH_DEFINE(ERASE_CYCLES, 0 ) \ - BENCH_DEFINE(BADBLOCK_BEHAVIOR, LFS3_EMUBD_BADBLOCK_PROGERROR ) \ - BENCH_DEFINE(POWERLOSS_BEHAVIOR, LFS3_EMUBD_POWERLOSS_ATOMIC ) \ - BENCH_DEFINE(EMUBD_SEED, 0 ) + /* name value (overridable) */ \ + BENCH_DEFINE(READ_SIZE, 1 ) \ + BENCH_DEFINE(PROG_SIZE, 1 ) \ + BENCH_DEFINE(BLOCK_SIZE, 4096 ) \ + BENCH_DEFINE(BLOCK_COUNT, DISK_SIZE/BLOCK_SIZE ) \ + BENCH_DEFINE(DISK_SIZE, 1024*1024 ) \ + BENCH_DEFINE(BLOCK_RECYCLES, -1 ) \ + BENCH_DEFINE(RCACHE_SIZE, LFS3_MAX(16, READ_SIZE) ) \ + BENCH_DEFINE(PCACHE_SIZE, LFS3_MAX(16, PROG_SIZE) ) \ + BENCH_DEFINE(FILE_CACHE_SIZE, 16 ) \ + BENCH_DEFINE(LOOKAHEAD_SIZE, 16 ) \ + BENCH_DEFINE(GC_FLAGS, 0 ) \ + BENCH_DEFINE(GC_STEPS, 0 ) \ + BENCH_DEFINE(GC_COMPACT_THRESH, 0 ) \ + BENCH_DEFINE(INLINE_SIZE, BLOCK_SIZE/4 ) \ + BENCH_DEFINE(FRAGMENT_SIZE, LFS3_MIN(BLOCK_SIZE/8, 512) ) \ + BENCH_DEFINE(CRYSTAL_THRESH, BLOCK_SIZE/8 ) \ + BENCH_DEFINE(GBMAP_REBUILD_THRESH, BLOCK_COUNT/4 ) \ + BENCH_DEFINE(ERASE_VALUE, 0xff ) \ + BENCH_DEFINE(ERASE_CYCLES, 0 ) \ + BENCH_DEFINE(BADBLOCK_BEHAVIOR, LFS3_EMUBD_BADBLOCK_PROGERROR ) \ + BENCH_DEFINE(POWERLOSS_BEHAVIOR, LFS3_EMUBD_POWERLOSS_ATOMIC ) \ + BENCH_DEFINE(EMUBD_SEED, 0 ) // declare defines as global intmax_ts #define BENCH_DEFINE(k, v) \ @@ -136,43 +136,43 @@ void bench_permutation(size_t i, uint32_t *buffer, size_t size); // map defines to cfg struct fields #define BENCH_CFG \ - .read_size = READ_SIZE, \ - .prog_size = PROG_SIZE, \ - .block_size = BLOCK_SIZE, \ - .block_count = BLOCK_COUNT, \ - .block_recycles = BLOCK_RECYCLES, \ - .rcache_size = RCACHE_SIZE, \ - .pcache_size = PCACHE_SIZE, \ - .file_cache_size = FILE_CACHE_SIZE, \ - .lookahead_size = LOOKAHEAD_SIZE, \ - BENCH_GBMAP_CFG \ - BENCH_GC_CFG \ - .gc_compact_thresh = GC_COMPACT_THRESH, \ - .inline_size = INLINE_SIZE, \ - .fragment_size = FRAGMENT_SIZE, \ - .crystal_thresh = CRYSTAL_THRESH, + .read_size = READ_SIZE, \ + .prog_size = PROG_SIZE, \ + .block_size = BLOCK_SIZE, \ + .block_count = BLOCK_COUNT, \ + .block_recycles = BLOCK_RECYCLES, \ + .rcache_size = RCACHE_SIZE, \ + .pcache_size = PCACHE_SIZE, \ + .file_cache_size = FILE_CACHE_SIZE, \ + .lookahead_size = LOOKAHEAD_SIZE, \ + BENCH_GBMAP_CFG \ + BENCH_GC_CFG \ + .gc_compact_thresh = GC_COMPACT_THRESH, \ + .inline_size = INLINE_SIZE, \ + .fragment_size = FRAGMENT_SIZE, \ + .crystal_thresh = CRYSTAL_THRESH, #ifdef LFS3_GBMAP #define BENCH_GBMAP_CFG \ - .gbmap_scan_thresh = GBMAP_SCAN_THRESH, + .gbmap_rebuild_thresh = GBMAP_REBUILD_THRESH, #else #define BENCH_GBMAP_CFG #endif #ifdef LFS3_GC #define BENCH_GC_CFG \ - .gc_flags = GC_FLAGS, \ - .gc_steps = GC_STEPS, + .gc_flags = GC_FLAGS, \ + .gc_steps = GC_STEPS, #else #define BENCH_GC_CFG #endif #define BENCH_BDCFG \ - .erase_value = ERASE_VALUE, \ - .erase_cycles = ERASE_CYCLES, \ - .badblock_behavior = BADBLOCK_BEHAVIOR, \ - .powerloss_behavior = POWERLOSS_BEHAVIOR, \ - .seed = EMUBD_SEED, + .erase_value = ERASE_VALUE, \ + .erase_cycles = ERASE_CYCLES, \ + .badblock_behavior = BADBLOCK_BEHAVIOR, \ + .powerloss_behavior = POWERLOSS_BEHAVIOR, \ + .seed = EMUBD_SEED, #endif diff --git a/runners/test_runner.h b/runners/test_runner.h index c88bc58a..8a70bd94 100644 --- a/runners/test_runner.h +++ b/runners/test_runner.h @@ -94,29 +94,29 @@ void test_permutation(size_t i, uint32_t *buffer, size_t size); // a few preconfigured defines that control how tests run #define TEST_IMPLICIT_DEFINES \ - /* name value (overridable) */ \ - TEST_DEFINE(READ_SIZE, 1 ) \ - TEST_DEFINE(PROG_SIZE, 1 ) \ - TEST_DEFINE(BLOCK_SIZE, 4096 ) \ - TEST_DEFINE(BLOCK_COUNT, DISK_SIZE/BLOCK_SIZE ) \ - TEST_DEFINE(DISK_SIZE, 1024*1024 ) \ - TEST_DEFINE(BLOCK_RECYCLES, -1 ) \ - TEST_DEFINE(RCACHE_SIZE, LFS3_MAX(16, READ_SIZE) ) \ - TEST_DEFINE(PCACHE_SIZE, LFS3_MAX(16, PROG_SIZE) ) \ - TEST_DEFINE(FILE_CACHE_SIZE, 16 ) \ - TEST_DEFINE(LOOKAHEAD_SIZE, 16 ) \ - TEST_DEFINE(GC_FLAGS, 0 ) \ - TEST_DEFINE(GC_STEPS, 0 ) \ - TEST_DEFINE(GC_COMPACT_THRESH, 0 ) \ - TEST_DEFINE(INLINE_SIZE, BLOCK_SIZE/4 ) \ - TEST_DEFINE(FRAGMENT_SIZE, LFS3_MIN(BLOCK_SIZE/8, 512) ) \ - TEST_DEFINE(CRYSTAL_THRESH, BLOCK_SIZE/8 ) \ - TEST_DEFINE(GBMAP_SCAN_THRESH, BLOCK_COUNT/4 ) \ - TEST_DEFINE(ERASE_VALUE, 0xff ) \ - TEST_DEFINE(ERASE_CYCLES, 0 ) \ - TEST_DEFINE(BADBLOCK_BEHAVIOR, LFS3_EMUBD_BADBLOCK_PROGERROR ) \ - TEST_DEFINE(POWERLOSS_BEHAVIOR, LFS3_EMUBD_POWERLOSS_ATOMIC ) \ - TEST_DEFINE(EMUBD_SEED, 0 ) + /* name value (overridable) */ \ + TEST_DEFINE(READ_SIZE, 1 ) \ + TEST_DEFINE(PROG_SIZE, 1 ) \ + TEST_DEFINE(BLOCK_SIZE, 4096 ) \ + TEST_DEFINE(BLOCK_COUNT, DISK_SIZE/BLOCK_SIZE ) \ + TEST_DEFINE(DISK_SIZE, 1024*1024 ) \ + TEST_DEFINE(BLOCK_RECYCLES, -1 ) \ + TEST_DEFINE(RCACHE_SIZE, LFS3_MAX(16, READ_SIZE) ) \ + TEST_DEFINE(PCACHE_SIZE, LFS3_MAX(16, PROG_SIZE) ) \ + TEST_DEFINE(FILE_CACHE_SIZE, 16 ) \ + TEST_DEFINE(LOOKAHEAD_SIZE, 16 ) \ + TEST_DEFINE(GC_FLAGS, 0 ) \ + TEST_DEFINE(GC_STEPS, 0 ) \ + TEST_DEFINE(GC_COMPACT_THRESH, 0 ) \ + TEST_DEFINE(INLINE_SIZE, BLOCK_SIZE/4 ) \ + TEST_DEFINE(FRAGMENT_SIZE, LFS3_MIN(BLOCK_SIZE/8, 512) ) \ + TEST_DEFINE(CRYSTAL_THRESH, BLOCK_SIZE/8 ) \ + TEST_DEFINE(GBMAP_REBUILD_THRESH, BLOCK_COUNT/4 ) \ + TEST_DEFINE(ERASE_VALUE, 0xff ) \ + TEST_DEFINE(ERASE_CYCLES, 0 ) \ + TEST_DEFINE(BADBLOCK_BEHAVIOR, LFS3_EMUBD_BADBLOCK_PROGERROR ) \ + TEST_DEFINE(POWERLOSS_BEHAVIOR, LFS3_EMUBD_POWERLOSS_ATOMIC ) \ + TEST_DEFINE(EMUBD_SEED, 0 ) // declare defines as global intmax_ts #define TEST_DEFINE(k, v) \ @@ -127,43 +127,43 @@ void test_permutation(size_t i, uint32_t *buffer, size_t size); // map defines to cfg struct fields #define TEST_CFG \ - .read_size = READ_SIZE, \ - .prog_size = PROG_SIZE, \ - .block_size = BLOCK_SIZE, \ - .block_count = BLOCK_COUNT, \ - .block_recycles = BLOCK_RECYCLES, \ - .rcache_size = RCACHE_SIZE, \ - .pcache_size = PCACHE_SIZE, \ - .file_cache_size = FILE_CACHE_SIZE, \ - .lookahead_size = LOOKAHEAD_SIZE, \ - TEST_GBMAP_CFG \ - TEST_GC_CFG \ - .gc_compact_thresh = GC_COMPACT_THRESH, \ - .inline_size = INLINE_SIZE, \ - .fragment_size = FRAGMENT_SIZE, \ - .crystal_thresh = CRYSTAL_THRESH, + .read_size = READ_SIZE, \ + .prog_size = PROG_SIZE, \ + .block_size = BLOCK_SIZE, \ + .block_count = BLOCK_COUNT, \ + .block_recycles = BLOCK_RECYCLES, \ + .rcache_size = RCACHE_SIZE, \ + .pcache_size = PCACHE_SIZE, \ + .file_cache_size = FILE_CACHE_SIZE, \ + .lookahead_size = LOOKAHEAD_SIZE, \ + TEST_GBMAP_CFG \ + TEST_GC_CFG \ + .gc_compact_thresh = GC_COMPACT_THRESH, \ + .inline_size = INLINE_SIZE, \ + .fragment_size = FRAGMENT_SIZE, \ + .crystal_thresh = CRYSTAL_THRESH, #ifdef LFS3_GBMAP #define TEST_GBMAP_CFG \ - .gbmap_scan_thresh = GBMAP_SCAN_THRESH, + .gbmap_rebuild_thresh = GBMAP_REBUILD_THRESH, #else #define TEST_GBMAP_CFG #endif #ifdef LFS3_GC #define TEST_GC_CFG \ - .gc_flags = GC_FLAGS, \ - .gc_steps = GC_STEPS, + .gc_flags = GC_FLAGS, \ + .gc_steps = GC_STEPS, #else #define TEST_GC_CFG #endif #define TEST_BDCFG \ - .erase_value = ERASE_VALUE, \ - .erase_cycles = ERASE_CYCLES, \ - .badblock_behavior = BADBLOCK_BEHAVIOR, \ - .powerloss_behavior = POWERLOSS_BEHAVIOR, \ - .seed = EMUBD_SEED, + .erase_value = ERASE_VALUE, \ + .erase_cycles = ERASE_CYCLES, \ + .badblock_behavior = BADBLOCK_BEHAVIOR, \ + .powerloss_behavior = POWERLOSS_BEHAVIOR, \ + .seed = EMUBD_SEED, #endif