Renamed/tweaked crystal_size -> crystal_thresh

Our crystallization threshold doesn't really describe the bounds of an
object, and I think it's a bit easier to think of it as a threshold for
block compaction.

Heck I've already been calling this the crystallization threshold all
over the code base.

An important change is this bumps the value by 1 bytes, so
crystal_thresh now describes the smallest size of a block our write
strategy will attempt to write.

Heuristically:
- data >= crystal_thresh => compacted into blocks
- data <  crystal_thresh => stored as fragments
This commit is contained in:
Christopher Haster
2023-12-14 12:49:43 -06:00
parent 02d2919130
commit c2e3a391ff
4 changed files with 18 additions and 18 deletions
+9 -9
View File
@@ -9505,7 +9505,7 @@ static int lfsr_ftree_carve(lfs_t *lfs,
// crystallization threshold? break into fragments
while (tag_ == LFSR_TAG_BLOCK
&& lfsr_data_size(&left_slice_) > lfs->cfg->fragment_size
&& lfsr_data_size(&left_slice_) <= lfs->cfg->crystal_size) {
&& lfsr_data_size(&left_slice_) < lfs->cfg->crystal_thresh) {
bptr_.data = lfsr_data_slice(bptr_.data,
lfs->cfg->fragment_size,
-1);
@@ -9533,7 +9533,7 @@ static int lfsr_ftree_carve(lfs_t *lfs,
// crystallization threshold? break into fragments
while (tag_ == LFSR_TAG_BLOCK
&& lfsr_data_size(&right_slice_) > lfs->cfg->fragment_size
&& lfsr_data_size(&right_slice_) <= lfs->cfg->crystal_size) {
&& lfsr_data_size(&right_slice_) < lfs->cfg->crystal_thresh) {
bptr_.data = lfsr_data_truncate(bptr_.data,
lfsr_data_size(&bptr_.data) - lfs->cfg->fragment_size);
@@ -9735,7 +9735,8 @@ static int lfsr_ftree_flush(lfs_t *lfs,
// within our tree? find left crystal neighbor
if (pos > 0
&& (lfs_soff_t)(pos - lfs->cfg->crystal_size)
&& lfs->cfg->crystal_thresh > 0
&& (lfs_soff_t)(pos - (lfs->cfg->crystal_thresh-1))
< (lfs_soff_t)lfsr_ftree_size(ftree)
&& lfsr_ftree_size(ftree) > 0
// don't bother to lookup left after the first block
@@ -9745,7 +9746,7 @@ static int lfsr_ftree_flush(lfs_t *lfs,
lfsr_bid_t weight;
lfsr_ecksum_t becksum;
int err = lfsr_ftree_lookupnext(lfs, mdir, ftree,
lfs_smax32(pos - lfs->cfg->crystal_size, 0),
lfs_smax32(pos - (lfs->cfg->crystal_thresh-1), 0),
&bid, &tag, &weight, &bptr, &becksum);
if (err) {
LFS_ASSERT(err != LFS_ERR_NOENT);
@@ -9757,7 +9758,7 @@ static int lfsr_ftree_flush(lfs_t *lfs,
// of our crystal
if (tag == LFSR_TAG_DATA
&& bid-(weight-1)+lfsr_data_size(&bptr.data)
>= pos - lfs->cfg->crystal_size) {
>= pos - (lfs->cfg->crystal_thresh-1)) {
crystal_start = bid-(weight-1);
// otherwise our neighbor determines our crystal boundary
@@ -9791,14 +9792,14 @@ static int lfsr_ftree_flush(lfs_t *lfs,
// if we haven't already exceeded our crystallization threshold,
// find right crystal neighbor
if (crystal_end - crystal_start <= lfs->cfg->crystal_size
if (crystal_end - crystal_start < lfs->cfg->crystal_thresh
&& lfsr_ftree_size(ftree) > 0) {
lfsr_bid_t bid;
lfsr_tag_t tag;
lfsr_bid_t weight;
int err = lfsr_ftree_lookupnext(lfs, mdir, ftree,
lfs_min32(
crystal_start + lfs->cfg->crystal_size,
crystal_start + (lfs->cfg->crystal_thresh-1),
lfsr_ftree_size(ftree)-1),
&bid, &tag, &weight, &bptr, NULL);
if (err) {
@@ -9822,7 +9823,7 @@ static int lfsr_ftree_flush(lfs_t *lfs,
}
// below our crystallization threshold? fallback to writing fragments
if (crystal_end - crystal_start <= lfs->cfg->crystal_size) {
if (crystal_end - crystal_start < lfs->cfg->crystal_thresh) {
break;
}
@@ -10042,7 +10043,6 @@ static int lfsr_ftree_flush(lfs_t *lfs,
// prepare our block pointer
LFS_ASSERT(bptr.cksize > 0);
LFS_ASSERT(bptr.cksize >= lfs->cfg->crystal_size);
LFS_ASSERT(bptr.cksize <= lfs->cfg->block_size);
bptr.data = LFSR_DATA_DISK(
bptr.data.u.disk.block,
+1 -1
View File
@@ -295,7 +295,7 @@ struct lfs_config {
lfs_size_t inline_size;
lfs_size_t shrub_size;
lfs_size_t fragment_size;
lfs_size_t crystal_size;
lfs_size_t crystal_thresh;
};
// File info structure
+4 -4
View File
@@ -121,7 +121,7 @@ intmax_t bench_define(size_t define);
#define INLINE_SIZE_i 6
#define SHRUB_SIZE_i 7
#define FRAGMENT_SIZE_i 8
#define CRYSTAL_SIZE_i 9
#define CRYSTAL_THRESH_i 9
#define LOOKAHEAD_SIZE_i 10
#define BLOCK_CYCLES_i 11
#define ERASE_VALUE_i 12
@@ -140,7 +140,7 @@ intmax_t bench_define(size_t define);
#define INLINE_SIZE bench_define(INLINE_SIZE_i)
#define SHRUB_SIZE bench_define(SHRUB_SIZE_i)
#define FRAGMENT_SIZE bench_define(FRAGMENT_SIZE_i)
#define CRYSTAL_SIZE bench_define(CRYSTAL_SIZE_i)
#define CRYSTAL_THRESH bench_define(CRYSTAL_THRESH_i)
#define LOOKAHEAD_SIZE bench_define(LOOKAHEAD_SIZE_i)
#define BLOCK_CYCLES bench_define(BLOCK_CYCLES_i)
#define ERASE_VALUE bench_define(ERASE_VALUE_i)
@@ -159,7 +159,7 @@ intmax_t bench_define(size_t define);
BENCH_DEF(INLINE_SIZE, BLOCK_SIZE/8 ) \
BENCH_DEF(SHRUB_SIZE, INLINE_SIZE ) \
BENCH_DEF(FRAGMENT_SIZE, CACHE_SIZE ) \
BENCH_DEF(CRYSTAL_SIZE, BLOCK_SIZE/8 ) \
BENCH_DEF(CRYSTAL_THRESH, BLOCK_SIZE/8 ) \
BENCH_DEF(LOOKAHEAD_SIZE, 16 ) \
BENCH_DEF(BLOCK_CYCLES, -1 ) \
BENCH_DEF(ERASE_VALUE, 0xff ) \
@@ -177,7 +177,7 @@ intmax_t bench_define(size_t define);
.inline_size = INLINE_SIZE, \
.shrub_size = SHRUB_SIZE, \
.fragment_size = FRAGMENT_SIZE, \
.crystal_size = CRYSTAL_SIZE, \
.crystal_thresh = CRYSTAL_THRESH, \
.lookahead_size = LOOKAHEAD_SIZE,
#define BENCH_BDCFG \
+4 -4
View File
@@ -107,7 +107,7 @@ intmax_t test_define(size_t define);
#define INLINE_SIZE_i 6
#define SHRUB_SIZE_i 7
#define FRAGMENT_SIZE_i 8
#define CRYSTAL_SIZE_i 9
#define CRYSTAL_THRESH_i 9
#define LOOKAHEAD_SIZE_i 10
#define BLOCK_CYCLES_i 11
#define ERASE_VALUE_i 12
@@ -126,7 +126,7 @@ intmax_t test_define(size_t define);
#define INLINE_SIZE TEST_DEFINE(INLINE_SIZE_i)
#define SHRUB_SIZE TEST_DEFINE(SHRUB_SIZE_i)
#define FRAGMENT_SIZE TEST_DEFINE(FRAGMENT_SIZE_i)
#define CRYSTAL_SIZE TEST_DEFINE(CRYSTAL_SIZE_i)
#define CRYSTAL_THRESH TEST_DEFINE(CRYSTAL_THRESH_i)
#define LOOKAHEAD_SIZE TEST_DEFINE(LOOKAHEAD_SIZE_i)
#define BLOCK_CYCLES TEST_DEFINE(BLOCK_CYCLES_i)
#define ERASE_VALUE TEST_DEFINE(ERASE_VALUE_i)
@@ -145,7 +145,7 @@ intmax_t test_define(size_t define);
TEST_DEF(INLINE_SIZE, BLOCK_SIZE/8 ) \
TEST_DEF(SHRUB_SIZE, INLINE_SIZE ) \
TEST_DEF(FRAGMENT_SIZE, CACHE_SIZE ) \
TEST_DEF(CRYSTAL_SIZE, BLOCK_SIZE/8 ) \
TEST_DEF(CRYSTAL_THRESH, BLOCK_SIZE/8 ) \
TEST_DEF(LOOKAHEAD_SIZE, 16 ) \
TEST_DEF(BLOCK_CYCLES, -1 ) \
TEST_DEF(ERASE_VALUE, 0xff ) \
@@ -163,7 +163,7 @@ intmax_t test_define(size_t define);
.inline_size = INLINE_SIZE, \
.shrub_size = SHRUB_SIZE, \
.fragment_size = FRAGMENT_SIZE, \
.crystal_size = CRYSTAL_SIZE, \
.crystal_thresh = CRYSTAL_THRESH, \
.lookahead_size = LOOKAHEAD_SIZE,
#define TEST_BDCFG \