Dropped the generalized lfs3_file_crystallize_ API

Eventually the generalized crystallize API may be useful again for the
"eager crystallization" write strategy, but the codebase has drifted
apart enough already that this will require some reimplementation
anyways (review the commit history!).

Might as well clean up API weirdness we're not using.

Saves surprisingly little code. I guess the compiler was able to
optimize out the duplicated args once the logic was a bit simpler?

           code          stack          ctx
  before: 37588           2472          656
  after:  37580 (-0.0%)   2472 (+0.0%)  656 (+0.0%)
This commit is contained in:
Christopher Haster
2025-07-03 15:11:36 -05:00
parent a85f08cfe3
commit d6f332fa9f
+9 -18
View File
@@ -12503,16 +12503,13 @@ failed:;
// hot-path // hot-path
LFS3_NOINLINE LFS3_NOINLINE
static int lfs3_file_crystallize__(lfs3_t *lfs3, lfs3_file_t *file, static int lfs3_file_crystallize__(lfs3_t *lfs3, lfs3_file_t *file,
lfs3_off_t block_pos, lfs3_off_t block_pos, lfs3_ssize_t crystal_size,
// TODO do we really need to keep crystal_min around? rename
// to crystal_size?
lfs3_ssize_t crystal_min, lfs3_ssize_t crystal_max,
lfs3_off_t pos, const uint8_t *buffer, lfs3_size_t size) { lfs3_off_t pos, const uint8_t *buffer, lfs3_size_t size) {
// align to prog_size, limit to block_size and theoretical file size // align to prog_size, limit to block_size and theoretical file size
lfs3_off_t crystal_limit = lfs3_min( lfs3_off_t crystal_limit = lfs3_min(
block_pos + lfs3_min( block_pos + lfs3_min(
lfs3_aligndown( lfs3_aligndown(
(lfs3_off_t)crystal_max, (lfs3_off_t)crystal_size,
lfs3->cfg->prog_size), lfs3->cfg->prog_size),
lfs3->cfg->block_size), lfs3->cfg->block_size),
lfs3_max( lfs3_max(
@@ -12610,7 +12607,7 @@ static int lfs3_file_crystallize__(lfs3_t *lfs3, lfs3_file_t *file,
// but make sure to include all of the requested // but make sure to include all of the requested
// crystal if explicit, otherwise above loops // crystal if explicit, otherwise above loops
// may never terminate // may never terminate
&& (lfs3_soff_t)(pos_ - block_pos) >= crystal_min) { && (lfs3_soff_t)(pos_ - block_pos) >= crystal_size) {
// if we hit this condition, mark as crystallized, // if we hit this condition, mark as crystallized,
// attempting resume crystallization will not make // attempting resume crystallization will not make
// progress // progress
@@ -12741,13 +12738,13 @@ static int lfs3_file_crystallize__(lfs3_t *lfs3, lfs3_file_t *file,
#if !defined(LFS3_RDONLY) && !defined(LFS3_KVONLY) && !defined(LFS3_2BONLY) #if !defined(LFS3_RDONLY) && !defined(LFS3_KVONLY) && !defined(LFS3_2BONLY)
static int lfs3_file_crystallize_(lfs3_t *lfs3, lfs3_file_t *file, static int lfs3_file_crystallize_(lfs3_t *lfs3, lfs3_file_t *file,
lfs3_off_t block_pos, lfs3_soff_t crystal_min, lfs3_soff_t crystal_max, lfs3_off_t block_pos, lfs3_ssize_t crystal_size,
lfs3_off_t pos, const uint8_t *buffer, lfs3_size_t size) { lfs3_off_t pos, const uint8_t *buffer, lfs3_size_t size) {
// this is split into two functions to try to minimize stack usage // this is split into two functions to try to minimize stack usage
// crystallize // crystallize
int err = lfs3_file_crystallize__(lfs3, file, int err = lfs3_file_crystallize__(lfs3, file,
block_pos, crystal_min, crystal_max, block_pos, crystal_size,
pos, buffer, size); pos, buffer, size);
if (err) { if (err) {
goto failed; goto failed;
@@ -12792,7 +12789,7 @@ static int lfs3_file_crystallize(lfs3_t *lfs3, lfs3_file_t *file) {
lfs3_alloc_ckpoint(lfs3); lfs3_alloc_ckpoint(lfs3);
// finish crystallizing // finish crystallizing
int err = lfs3_file_crystallize_(lfs3, file, int err = lfs3_file_crystallize_(lfs3, file,
file->leaf.pos - lfs3_bptr_off(&file->leaf.bptr), -1, -1, file->leaf.pos - lfs3_bptr_off(&file->leaf.bptr), -1,
file->cache.pos, file->cache.buffer, file->cache.size); file->cache.pos, file->cache.buffer, file->cache.size);
if (err) { if (err) {
return err; return err;
@@ -12942,9 +12939,7 @@ static int lfs3_file_flush_(lfs3_t *lfs3, lfs3_file_t *file,
file->b.o.flags |= LFS3_o_UNCRYST; file->b.o.flags |= LFS3_o_UNCRYST;
// crystallize // crystallize
int err = lfs3_file_crystallize_(lfs3, file, int err = lfs3_file_crystallize_(lfs3, file,
block_start, block_start, (pos + size) - block_start,
(pos + size) - block_start,
(pos + size) - block_start,
pos, buffer, size); pos, buffer, size);
if (err) { if (err) {
return err; return err;
@@ -13073,9 +13068,7 @@ static int lfs3_file_flush_(lfs3_t *lfs3, lfs3_file_t *file,
file->b.o.flags |= LFS3_o_UNCRYST; file->b.o.flags |= LFS3_o_UNCRYST;
// crystallize // crystallize
int err = lfs3_file_crystallize_(lfs3, file, int err = lfs3_file_crystallize_(lfs3, file,
block_start, block_start, crystal_end - block_start,
crystal_end - block_start,
crystal_end - block_start,
pos, buffer, size); pos, buffer, size);
if (err) { if (err) {
return err; return err;
@@ -13140,9 +13133,7 @@ static int lfs3_file_flush_(lfs3_t *lfs3, lfs3_file_t *file,
// //
// lfs3_file_crystallize_ handles block allocation/relocation // lfs3_file_crystallize_ handles block allocation/relocation
err = lfs3_file_crystallize_(lfs3, file, err = lfs3_file_crystallize_(lfs3, file,
crystal_start, crystal_start, crystal_end - crystal_start,
crystal_end - crystal_start,
crystal_end - crystal_start,
pos, buffer, size); pos, buffer, size);
if (err) { if (err) {
return err; return err;