Skip to content

Commit

Permalink
Renamed lfs->cfg->shrub_size -> lfs->cfg->inline_size
Browse files Browse the repository at this point in the history
While I think shrub_size is probably the more correct name at a
technical level, inline_size is probably more what users expect and
doesn't require a deeper understanding of filesystem details.

The only risk is that users may think inline_size has no effect on large
files, when in fact it still controls how much of the btree root can be
inlined.

There's also the point that sticking with inline_size maintains
compatibility with both the upstream version and any future version that
has other file representations.

May revisit this, but renaming to lfs->cfg->inline_size for now.
  • Loading branch information
geky committed Feb 8, 2025
1 parent a9b061a commit c915fca
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 30 deletions.
20 changes: 10 additions & 10 deletions lfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -6276,7 +6276,7 @@ static int lfsr_bshrub_commit_(lfs_t *lfs, lfsr_bshrub_t *bshrub,
//
// Instead, we keep track of an estimate of how many bytes have
// been progged to the shrub since the last estimate, and recalculate
// the estimate when this overflows our shrub_size. This mirrors how
// the estimate when this overflows our inline_size. This mirrors how
// block_size and rbyds interact, and amortizes the estimate cost.

// figure out how much data this commit progs
Expand All @@ -6285,27 +6285,27 @@ static int lfsr_bshrub_commit_(lfs_t *lfs, lfsr_bshrub_t *bshrub,
commit_estimate += lfs->rat_estimate + lfsr_rat_size(rats[i]);
}

// does our estimate exceed our shrub_size? need to recalculate an
// does our estimate exceed our inline_size? need to recalculate an
// accurate estimate
lfs_ssize_t estimate = (alloc) ? (lfs_size_t)-1 : bshrub->shrub.eoff;
// this double condition avoids overflow issues
if ((lfs_size_t)estimate > lfs->cfg->shrub_size
|| estimate + commit_estimate > lfs->cfg->shrub_size) {
if ((lfs_size_t)estimate > lfs->cfg->inline_size
|| estimate + commit_estimate > lfs->cfg->inline_size) {
estimate = lfsr_bshrub_estimate(lfs, bshrub);
if (estimate < 0) {
return estimate;
}

// two cases where we evict:
// - overflow shrub_size/2 - don't penalize for commits here
// - overflow shrub_size - must include commits or we risk overflow
// - overflow inline_size/2 - don't penalize for commits here
// - overflow inline_size - must include commits or risk overflow
//
// the 1/2 here prevents runaway performance with the shrub is
// near full, but it's a heuristic, so including the commit would
// just be mean
//
if ((lfs_size_t)estimate > lfs->cfg->shrub_size/2
|| estimate + commit_estimate > lfs->cfg->shrub_size) {
if ((lfs_size_t)estimate > lfs->cfg->inline_size/2
|| estimate + commit_estimate > lfs->cfg->inline_size) {
goto relocate;
}
}
Expand Down Expand Up @@ -12823,8 +12823,8 @@ static int lfs_init(lfs_t *lfs, uint32_t flags,
LFS_ASSERT(lfs->cfg->gc_compact_thresh == (lfs_size_t)-1
|| lfs->cfg->gc_compact_thresh <= lfs->cfg->block_size);

// shrub_size must be <= block_size/4
LFS_ASSERT(lfs->cfg->shrub_size <= lfs->cfg->block_size/4);
// inline_size must be <= block_size/4
LFS_ASSERT(lfs->cfg->inline_size <= lfs->cfg->block_size/4);
// fragment_size must be <= block_size/4
LFS_ASSERT(lfs->cfg->fragment_size <= lfs->cfg->block_size/4);

Expand Down
2 changes: 1 addition & 1 deletion lfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ struct lfs_config {
// blocksize/4.
//
// 0 disables shrubs.
lfs_size_t shrub_size;
lfs_size_t inline_size;

// Maximum size of a non-block B-tree leaf in bytes. Smaller values may
// make small random-writes cheaper, but increase metadata overhead. Must
Expand Down
4 changes: 2 additions & 2 deletions runners/bench_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void bench_permutation(size_t i, uint32_t *buffer, size_t size);
BENCH_DEFINE(GC_FLAGS, 0 ) \
BENCH_DEFINE(GC_STEPS, 0 ) \
BENCH_DEFINE(GC_COMPACT_THRESH, 0 ) \
BENCH_DEFINE(SHRUB_SIZE, BLOCK_SIZE/4 ) \
BENCH_DEFINE(INLINE_SIZE, BLOCK_SIZE/4 ) \
BENCH_DEFINE(FRAGMENT_SIZE, BLOCK_SIZE/8 ) \
BENCH_DEFINE(CRYSTAL_THRESH, BLOCK_SIZE/8 ) \
BENCH_DEFINE(ERASE_VALUE, 0xff ) \
Expand Down Expand Up @@ -146,7 +146,7 @@ void bench_permutation(size_t i, uint32_t *buffer, size_t size);
.lookahead_size = LOOKAHEAD_SIZE, \
BENCH_GC_CFG \
.gc_compact_thresh = GC_COMPACT_THRESH, \
.shrub_size = SHRUB_SIZE, \
.inline_size = INLINE_SIZE, \
.fragment_size = FRAGMENT_SIZE, \
.crystal_thresh = CRYSTAL_THRESH,

Expand Down
4 changes: 2 additions & 2 deletions runners/test_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void test_permutation(size_t i, uint32_t *buffer, size_t size);
TEST_DEFINE(GC_FLAGS, 0 ) \
TEST_DEFINE(GC_STEPS, 0 ) \
TEST_DEFINE(GC_COMPACT_THRESH, 0 ) \
TEST_DEFINE(SHRUB_SIZE, BLOCK_SIZE/4 ) \
TEST_DEFINE(INLINE_SIZE, BLOCK_SIZE/4 ) \
TEST_DEFINE(FRAGMENT_SIZE, BLOCK_SIZE/8 ) \
TEST_DEFINE(CRYSTAL_THRESH, BLOCK_SIZE/8 ) \
TEST_DEFINE(ERASE_VALUE, 0xff ) \
Expand Down Expand Up @@ -137,7 +137,7 @@ void test_permutation(size_t i, uint32_t *buffer, size_t size);
.lookahead_size = LOOKAHEAD_SIZE, \
TEST_GC_CFG \
.gc_compact_thresh = GC_COMPACT_THRESH, \
.shrub_size = SHRUB_SIZE, \
.inline_size = INLINE_SIZE, \
.fragment_size = FRAGMENT_SIZE, \
.crystal_thresh = CRYSTAL_THRESH

Expand Down
6 changes: 3 additions & 3 deletions tests/test_ck.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,7 @@ code = '''
defines.BADBIT = -1
defines.BADBLOCK_BEHAVIOR = 'LFS_EMUBD_BADBLOCK_PROGFLIP'
# force the file to create a btree
defines.SHRUB_SIZE = 0
defines.INLINE_SIZE = 0
defines.CRYSTAL_THRESH = -1
defines.FRAGMENT_SIZE = 'BLOCK_SIZE/8'
defines.SIZE = '2*FRAGMENT_SIZE'
Expand Down Expand Up @@ -1956,7 +1956,7 @@ code = '''
[cases.test_ck_ckfetches_btree]
defines.BADBIT = -1
# force the file to create a btree
defines.SHRUB_SIZE = 0
defines.INLINE_SIZE = 0
defines.CRYSTAL_THRESH = -1
defines.FRAGMENT_SIZE = 'BLOCK_SIZE/8'
defines.SIZE = '2*FRAGMENT_SIZE'
Expand Down Expand Up @@ -2213,7 +2213,7 @@ defines.BADBLOCK_BEHAVIOR = [
'LFS_EMUBD_BADBLOCK_READFLIP',
]
# force the file to create a btree
defines.SHRUB_SIZE = 0
defines.INLINE_SIZE = 0
defines.CRYSTAL_THRESH = -1
defines.FRAGMENT_SIZE = 'BLOCK_SIZE/8'
defines.SIZE = '2*FRAGMENT_SIZE'
Expand Down
4 changes: 2 additions & 2 deletions tests/test_fwrite.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ code = '''
defines.N = [0, 1, 2, 3, 4]
defines.SIZE = 'N*FRAGMENT_SIZE'
# force a btree node
defines.SHRUB_SIZE = 0
defines.INLINE_SIZE = 0
defines.CRYSTAL_THRESH = -1
defines.SYNC = [false, true]
in = 'lfs.c'
Expand Down Expand Up @@ -487,7 +487,7 @@ defines.N = [0, 1, 2, 3, 4]
defines.SIZE = 'N*FRAGMENT_SIZE'
defines.CHUNK = [32, 8, 1]
# force a btree node
defines.SHRUB_SIZE = 0
defines.INLINE_SIZE = 0
defines.CRYSTAL_THRESH = -1
defines.SYNC = [false, true]
defines.REMOUNT = [false, true]
Expand Down
6 changes: 3 additions & 3 deletions tests/test_powerloss.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ defines.POWERLOSS_BEHAVIOR = [
]
defines.MKCONSISTENT = [false, true]
# inlining has a tendency to hide sync issues, so try without
defines.SHRUB_SIZE = ['BLOCK_SIZE/4', '0']
defines.INLINE_SIZE = ['BLOCK_SIZE/4', '0']
defines.N = [1, 2, 4, 8, 16, 32, 64]
defines.SIZE = [
'0',
Expand Down Expand Up @@ -228,7 +228,7 @@ defines.POWERLOSS_BEHAVIOR = [
]
defines.MKCONSISTENT = [false, true]
# inlining has a tendency to hide sync issues, so try without
defines.SHRUB_SIZE = ['BLOCK_SIZE/4', '0']
defines.INLINE_SIZE = ['BLOCK_SIZE/4', '0']
defines.N = [1, 2, 4, 8, 16, 32, 64]
defines.OPS = 256
defines.SIZE = [
Expand Down Expand Up @@ -458,7 +458,7 @@ defines.POWERLOSS_BEHAVIOR = [
]
defines.MKCONSISTENT = [false, true]
# inlining has a tendency to hide sync issues, so try without
defines.SHRUB_SIZE = ['BLOCK_SIZE/4', '0']
defines.INLINE_SIZE = ['BLOCK_SIZE/4', '0']
# note dirs x files grows O(n^2)
defines.N = [1, 2, 4, 8]
defines.M = 'N'
Expand Down
14 changes: 7 additions & 7 deletions tests/test_traversal.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2286,7 +2286,7 @@ defines.LOOKAHEAD = [false, true]
defines.CKMETA = [false, true]
defines.CKDATA = [false, true]
defines.SIZE = '2*BLOCK_SIZE'
defines.SHRUB_SIZE = 0
defines.INLINE_SIZE = 0
defines.TRUNC = [false, true]
code = '''
lfs_t lfs;
Expand Down Expand Up @@ -2569,7 +2569,7 @@ defines.LOOKAHEAD = [false, true]
defines.CKMETA = [false, true]
defines.CKDATA = [false, true]
defines.SIZE = '2*BLOCK_SIZE'
defines.SHRUB_SIZE = 0
defines.INLINE_SIZE = 0
code = '''
lfs_t lfs;
lfsr_format(&lfs, LFS_F_RDWR, CFG) => 0;
Expand Down Expand Up @@ -2858,7 +2858,7 @@ defines.LOOKAHEAD = [false, true]
defines.CKMETA = [false, true]
defines.CKDATA = [false, true]
defines.SIZE = '2*BLOCK_SIZE'
defines.SHRUB_SIZE = 0
defines.INLINE_SIZE = 0
defines.DESYNC = [false, true]
code = '''
lfs_t lfs;
Expand Down Expand Up @@ -6652,7 +6652,7 @@ defines.LOOKAHEAD = [false, true]
defines.CKMETA = [false, true]
defines.CKDATA = [false, true]
# limit files to very simple btrees
defines.SHRUB_SIZE = 0
defines.INLINE_SIZE = 0
defines.CRYSTAL_THRESH = -1
defines.FRAGMENT_SIZE = 'BLOCK_SIZE/8'
defines.SIZE = '2*FRAGMENT_SIZE'
Expand Down Expand Up @@ -6812,7 +6812,7 @@ defines.LOOKAHEAD = [false, true]
defines.CKMETA = [false, true]
defines.CKDATA = [false, true]
# limit files to very simple btrees
defines.SHRUB_SIZE = 0
defines.INLINE_SIZE = 0
defines.CRYSTAL_THRESH = -1
defines.FRAGMENT_SIZE = 'BLOCK_SIZE/8'
defines.SIZE = '2*FRAGMENT_SIZE'
Expand Down Expand Up @@ -6971,7 +6971,7 @@ defines.CKMETA = [false, true]
defines.CKDATA = [false, true]
# this configuration should create a 2-layer bshrub, which may be
# a bit delicate
defines.SHRUB_SIZE = 'BLOCK_SIZE/4'
defines.INLINE_SIZE = 'BLOCK_SIZE/4'
defines.CRYSTAL_THRESH = -1
defines.FRAGMENT_SIZE = 'BLOCK_SIZE/8'
defines.SIZE = 'BLOCK_SIZE'
Expand Down Expand Up @@ -7140,7 +7140,7 @@ defines.CKMETA = [false, true]
defines.CKDATA = [false, true]
# this configuration should create a 2-layer bshrub, which may be
# a bit delicate
defines.SHRUB_SIZE = 'BLOCK_SIZE/4'
defines.INLINE_SIZE = 'BLOCK_SIZE/4'
defines.CRYSTAL_THRESH = -1
defines.FRAGMENT_SIZE = 'BLOCK_SIZE/8'
defines.SIZE = 'BLOCK_SIZE'
Expand Down

0 comments on commit c915fca

Please sign in to comment.