Tweaked some crystallization comments

- Trying to prefer crystal over compact verbiage to try to avoid
  confusion with metadata/rbyd compaction

- crystal_thresh >= block_size implying a fully-fragmented file was a
  mistake, it should be crystal_thresh > block_size.

  crystal_thresh == block_size has the behavior of waiting until the
  last moment to crystallize a block, but this still breaks the
  fully-fragmented random-write guarantee.

  This changed during development, so the comment was probably just
  outdated.
This commit is contained in:
Christopher Haster
2025-04-19 15:39:15 -05:00
parent a73f221317
commit 385199d4b5
2 changed files with 22 additions and 19 deletions
+17 -14
View File
@@ -11829,7 +11829,7 @@ static int lfsr_file_flush_(lfs_t *lfs, lfsr_file_t *file,
off = bptr.data.u.disk.off; off = bptr.data.u.disk.off;
eoff = lfsr_bptr_cksize(&bptr); eoff = lfsr_bptr_cksize(&bptr);
cksum = lfsr_bptr_cksum(&bptr); cksum = lfsr_bptr_cksum(&bptr);
goto compact; goto crystallize;
} }
} }
} }
@@ -11873,11 +11873,12 @@ static int lfsr_file_flush_(lfs_t *lfs, lfsr_file_t *file,
goto fragment; goto fragment;
} }
// exceeded our crystallization threshold? compact into a new block // exceeded our crystallization threshold? crystallize into a
// new block
// before we can compact we need to figure out the best block // before we can crystallize we need to figure out the best
// alignment, we use the entry immediately to the left of our // block alignment, we use the entry immediately to the left of
// crystal for this // our crystal for this
block_start = crystal_start; block_start = crystal_start;
if (crystal_start > 0 if (crystal_start > 0
&& file->b.shrub.weight > 0 && file->b.shrub.weight > 0
@@ -11920,7 +11921,7 @@ static int lfsr_file_flush_(lfs_t *lfs, lfsr_file_t *file,
off = bptr.data.u.disk.off; off = bptr.data.u.disk.off;
eoff = lfsr_bptr_cksize(&bptr); eoff = lfsr_bptr_cksize(&bptr);
cksum = lfsr_bptr_cksum(&bptr); cksum = lfsr_bptr_cksum(&bptr);
goto compact; goto crystallize;
} }
// no? is our left neighbor at least our left block neighbor? // no? is our left neighbor at least our left block neighbor?
@@ -11947,8 +11948,8 @@ static int lfsr_file_flush_(lfs_t *lfs, lfsr_file_t *file,
eoff = 0; eoff = 0;
cksum = 0; cksum = 0;
compact:; crystallize:;
// compact data into our block // crystallize data into our block
// //
// eagerly merge any right neighbors we see unless that would // eagerly merge any right neighbors we see unless that would
// put us over our block size // put us over our block size
@@ -12083,10 +12084,12 @@ static int lfsr_file_flush_(lfs_t *lfs, lfsr_file_t *file,
eoff += d; eoff += d;
} }
// A bit of a hack here, we need to truncate our block to prog_size // a bit of a hack here, we need to truncate our block to
// alignment to avoid padding issues. Doing this retroactively to // prog_size alignment to avoid padding issues
// the pcache greatly simplifies the above loop, though we may end //
// up reading more than is strictly necessary. // doing this retroactively to the pcache greatly simplifies the
// above loop, though we may end up reading more than is
// strictly necessary
lfs_ssize_t d = eoff % lfs->cfg->prog_size; lfs_ssize_t d = eoff % lfs->cfg->prog_size;
lfs->pcache.size -= d; lfs->pcache.size -= d;
block_end -= d; block_end -= d;
@@ -12130,8 +12133,8 @@ static int lfsr_file_flush_(lfs_t *lfs, lfsr_file_t *file,
file->eoff = eoff; file->eoff = eoff;
} }
// note compacting fragments -> blocks may not actually make any // note crystallizing fragments -> blocks may not actually make
// progress on flushing the buffer on the first pass // any progress on flushing the buffer on the first pass
d = lfs_max(pos, block_end) - pos; d = lfs_max(pos, block_end) - pos;
pos += d; pos += d;
buffer += lfs_min(d, size); buffer += lfs_min(d, size);
+5 -5
View File
@@ -446,16 +446,16 @@ struct lfs_config {
lfs_size_t fragment_size; lfs_size_t fragment_size;
// Threshold for compacting multiple fragments into a block. Smaller // Threshold for compacting multiple fragments into a block. Smaller
// values will compact more eagerly, reducing disk usage, but increasing // values will crystallize more eagerly, reducing disk usage, but
// the cost of random-writes. // increasing the cost of random-writes.
// //
// 0 only writes blocks, minimizing disk usage, while -1 or any value >= // 0 only writes blocks, minimizing disk usage, while -1 or any value >
// block_size only writes fragments, minimizing random-write cost. // block_size only writes fragments, minimizing random-write cost.
lfs_size_t crystal_thresh; lfs_size_t crystal_thresh;
// Threshold for breaking a block into fragments. Smaller values will // Threshold for breaking a block into fragments. Smaller values will
// break more lazily, reducing random-write cost, but risk leaving blocks // fragment more lazily, reducing random-write cost, but risk higher
// around with wasted storage. // disk usage.
// //
// This can be set lower than crystal_thresh to prevent repeated // This can be set lower than crystal_thresh to prevent repeated
// compact/break operations in files with heavy random writes, at a // compact/break operations in files with heavy random writes, at a