Merge pull request #502 from mon/feature/meta_limits
Add metadata_max config to help performance on devices with large blocks
This commit is contained in:
@@ -1591,7 +1591,8 @@ static int lfs_dir_compact(lfs_t *lfs,
|
|||||||
// for metadata updates.
|
// for metadata updates.
|
||||||
if (end - begin < 0xff &&
|
if (end - begin < 0xff &&
|
||||||
size <= lfs_min(lfs->cfg->block_size - 36,
|
size <= lfs_min(lfs->cfg->block_size - 36,
|
||||||
lfs_alignup(lfs->cfg->block_size/2,
|
lfs_alignup((lfs->cfg->metadata_max ?
|
||||||
|
lfs->cfg->metadata_max : lfs->cfg->block_size)/2,
|
||||||
lfs->cfg->prog_size))) {
|
lfs->cfg->prog_size))) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1676,7 +1677,8 @@ static int lfs_dir_compact(lfs_t *lfs,
|
|||||||
.crc = 0xffffffff,
|
.crc = 0xffffffff,
|
||||||
|
|
||||||
.begin = 0,
|
.begin = 0,
|
||||||
.end = lfs->cfg->block_size - 8,
|
.end = (lfs->cfg->metadata_max ?
|
||||||
|
lfs->cfg->metadata_max : lfs->cfg->block_size) - 8,
|
||||||
};
|
};
|
||||||
|
|
||||||
// erase block to write to
|
// erase block to write to
|
||||||
@@ -1886,7 +1888,8 @@ static int lfs_dir_commit(lfs_t *lfs, lfs_mdir_t *dir,
|
|||||||
.crc = 0xffffffff,
|
.crc = 0xffffffff,
|
||||||
|
|
||||||
.begin = dir->off,
|
.begin = dir->off,
|
||||||
.end = lfs->cfg->block_size - 8,
|
.end = (lfs->cfg->metadata_max ?
|
||||||
|
lfs->cfg->metadata_max : lfs->cfg->block_size) - 8,
|
||||||
};
|
};
|
||||||
|
|
||||||
// traverse attrs that need to be written out
|
// traverse attrs that need to be written out
|
||||||
@@ -2968,7 +2971,9 @@ static lfs_ssize_t lfs_file_rawwrite(lfs_t *lfs, lfs_file_t *file,
|
|||||||
if ((file->flags & LFS_F_INLINE) &&
|
if ((file->flags & LFS_F_INLINE) &&
|
||||||
lfs_max(file->pos+nsize, file->ctz.size) >
|
lfs_max(file->pos+nsize, file->ctz.size) >
|
||||||
lfs_min(0x3fe, lfs_min(
|
lfs_min(0x3fe, lfs_min(
|
||||||
lfs->cfg->cache_size, lfs->cfg->block_size/8))) {
|
lfs->cfg->cache_size,
|
||||||
|
(lfs->cfg->metadata_max ?
|
||||||
|
lfs->cfg->metadata_max : lfs->cfg->block_size) / 8))) {
|
||||||
// inline file doesn't fit anymore
|
// inline file doesn't fit anymore
|
||||||
int err = lfs_file_outline(lfs, file);
|
int err = lfs_file_outline(lfs, file);
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -3538,6 +3543,8 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
|
|||||||
lfs->attr_max = LFS_ATTR_MAX;
|
lfs->attr_max = LFS_ATTR_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LFS_ASSERT(lfs->cfg->metadata_max <= lfs->cfg->block_size);
|
||||||
|
|
||||||
// setup default state
|
// setup default state
|
||||||
lfs->root[0] = LFS_BLOCK_NULL;
|
lfs->root[0] = LFS_BLOCK_NULL;
|
||||||
lfs->root[1] = LFS_BLOCK_NULL;
|
lfs->root[1] = LFS_BLOCK_NULL;
|
||||||
@@ -3831,7 +3838,7 @@ int lfs_fs_rawtraverse(lfs_t *lfs,
|
|||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
} else if (includeorphans &&
|
} else if (includeorphans &&
|
||||||
lfs_tag_type3(tag) == LFS_TYPE_DIRSTRUCT) {
|
lfs_tag_type3(tag) == LFS_TYPE_DIRSTRUCT) {
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
err = cb(data, (&ctz.head)[i]);
|
err = cb(data, (&ctz.head)[i]);
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ struct lfs_config {
|
|||||||
// Number of erasable blocks on the device.
|
// Number of erasable blocks on the device.
|
||||||
lfs_size_t block_count;
|
lfs_size_t block_count;
|
||||||
|
|
||||||
// Number of erase cycles before littlefs evicts metadata logs and moves
|
// Number of erase cycles before littlefs evicts metadata logs and moves
|
||||||
// the metadata to another block. Suggested values are in the
|
// the metadata to another block. Suggested values are in the
|
||||||
// range 100-1000, with large values having better performance at the cost
|
// range 100-1000, with large values having better performance at the cost
|
||||||
// of less consistent wear distribution.
|
// of less consistent wear distribution.
|
||||||
@@ -256,6 +256,12 @@ struct lfs_config {
|
|||||||
// larger attributes size but must be <= LFS_ATTR_MAX. Defaults to
|
// larger attributes size but must be <= LFS_ATTR_MAX. Defaults to
|
||||||
// LFS_ATTR_MAX when zero.
|
// LFS_ATTR_MAX when zero.
|
||||||
lfs_size_t attr_max;
|
lfs_size_t attr_max;
|
||||||
|
|
||||||
|
// Optional upper limit on total space given to metadata pairs in bytes. On
|
||||||
|
// devices with large blocks (e.g. 128kB) setting this to a low size (2-8kB)
|
||||||
|
// can help bound the metadata compaction time. Must be <= block_size.
|
||||||
|
// Defaults to block_size when zero.
|
||||||
|
lfs_size_t metadata_max;
|
||||||
};
|
};
|
||||||
|
|
||||||
// File info structure
|
// File info structure
|
||||||
|
|||||||
Reference in New Issue
Block a user