Skip to content

Commit fee5691

Browse files
committed
Artificially limited number of file ids per metadata block
This is an expirement to determine which field in the tag structure is the most critical: tag id or tag size. This came from looking at NAND storage and discussions around behaviour of large prog_sizes. Initial exploration indicates that prog_sizes around 2KiB are not _that_ uncommon, and the 1KiB limitation is surprising. It's possible to increase the lfs_tag size to 12-bits (4096), but at the cost of only 8-bit ids (256). [---- 32 ----] a [1|-3-|-- 8 --|-- 10 --|-- 10 --] b [1|-3-|-- 8 --|-- 8 --|-- 12 --] This requires more investigation, but in order to allow us to change the tag sizes with minimal impact I've artificially limited the number of file ids to 0xfe (255) different file ids per metadata pair. If 12-bit lengths turn out to be a bad idea, we can remove the artificial limit without backwards incompatible changes. To avoid breaking users already on v2-alpha, this change will refuse _creating_ file ids > 255, but should read file ids > 255 without issues.
1 parent 9603c20 commit fee5691

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lfs.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,8 +1437,10 @@ static int lfs_dir_compact(lfs_t *lfs,
14371437
// space is complicated, we need room for tail, crc, gstate,
14381438
// cleanup delete, and we cap at half a block to give room
14391439
// for metadata updates.
1440-
if (size <= lfs_min(lfs->cfg->block_size - 36,
1441-
lfs_alignup(lfs->cfg->block_size/2, lfs->cfg->prog_size))) {
1440+
if (end - begin < 0xff &&
1441+
size <= lfs_min(lfs->cfg->block_size - 36,
1442+
lfs_alignup(lfs->cfg->block_size/2,
1443+
lfs->cfg->prog_size))) {
14421444
break;
14431445
}
14441446

@@ -1711,7 +1713,7 @@ static int lfs_dir_commit(lfs_t *lfs, lfs_mdir_t *dir,
17111713
}
17121714
}
17131715

1714-
if (dir->erased) {
1716+
if (dir->erased || dir->count >= 0xff) {
17151717
// try to commit
17161718
struct lfs_commit commit = {
17171719
.block = dir->pair[0],

0 commit comments

Comments
 (0)