littlefs-project / littlefs

A little fail-safe filesystem designed for microcontrollers
BSD 3-Clause "New" or "Revised" License
4.9k stars 771 forks source link

Extend lfs_fs_gc to compact metadata, compact_thresh #913

Closed geky closed 5 months ago

geky commented 6 months ago

This extends lfs_fs_gc to now handle three things:

  1. Calls mkconsistent if not already consistent
  2. Compacts metadata > compact_thresh
  3. Populates the block allocator

Which should be all of the janitorial work that can be done without additional on-disk data structures.

Normally, metadata compaction occurs when an mdir is full, and results in mdirs that are at most block_size/2.

Now, if you call lfs_fs_gc, littlefs will eagerly compact any mdirs that exceed the compact_thresh configuration option. Because the resulting mdirs are at most block_size/2, it only makes sense for compact_thresh to be >= block_size/2 and <= block_size.

Additionally, there are some special values:

Note that compact_thresh only affects lfs_fs_gc. Normal compactions still only occur when full.

This depends on: https://github.com/littlefs-project/littlefs/pull/912

geky-bot commented 6 months ago
Tests passed ✓, Code: 16964 B (+0.9%), Stack: 1432 B (-1.1%), Structs: 804 B (+0.5%) | | Code | Stack | Structs | | Coverage | |:--|-----:|------:|--------:|:--|---------:| | Default | 16964 B (+0.9%) | 1432 B (-1.1%) | 804 B (+0.5%) | Lines | 2380/2559 lines (-0.1%) | | Readonly | 6130 B (+0.0%) | 448 B (+0.0%) | 804 B (+0.5%) | Branches | 1223/1556 branches (-0.1%) | | Threadsafe | 17828 B (+0.8%) | 1432 B (-1.1%) | 812 B (+0.5%) | | **Benchmarks** | | Multiversion | 17028 B (+0.9%) | 1432 B (-1.1%) | 808 B (+0.5%) | Readed | 29369693876 B (+0.0%) | | Migrate | 18644 B (+0.8%) | 1736 B (-0.9%) | 808 B (+0.5%) | Proged | 1482874766 B (+0.0%) | | Error-asserts | 17636 B (+0.9%) | 1424 B (-1.1%) | 804 B (+0.5%) | Erased | 1568888832 B (+0.0%) |
geky-bot commented 6 months ago
Tests passed ✓, Code: 16964 B (+0.9%), Stack: 1432 B (-1.1%), Structs: 804 B (+0.5%) | | Code | Stack | Structs | | Coverage | |:--|-----:|------:|--------:|:--|---------:| | Default | 16964 B (+0.9%) | 1432 B (-1.1%) | 804 B (+0.5%) | Lines | 2380/2559 lines (-0.1%) | | Readonly | 6130 B (+0.0%) | 448 B (+0.0%) | 804 B (+0.5%) | Branches | 1223/1556 branches (-0.1%) | | Threadsafe | 17828 B (+0.8%) | 1432 B (-1.1%) | 812 B (+0.5%) | | **Benchmarks** | | Multiversion | 17028 B (+0.9%) | 1432 B (-1.1%) | 808 B (+0.5%) | Readed | 29369693876 B (+0.0%) | | Migrate | 18644 B (+0.8%) | 1736 B (-0.9%) | 808 B (+0.5%) | Proged | 1482874766 B (+0.0%) | | Error-asserts | 17636 B (+0.9%) | 1424 B (-1.1%) | 804 B (+0.5%) | Erased | 1568888832 B (+0.0%) |
geky-bot commented 5 months ago
Tests passed ✓, Code: 16972 B, Stack: 1432 B, Structs: 804 B | | Code | Stack | Structs | | Coverage | |:--|-----:|------:|--------:|:--|---------:| | Default | 16972 B | 1432 B | 804 B | Lines | 2380/2559 lines | | Readonly | 6130 B | 448 B | 804 B | Branches | 1223/1556 branches | | Threadsafe | 17836 B | 1432 B | 812 B | | **Benchmarks** | | Multiversion | 17036 B | 1432 B | 808 B | Readed | 29369693876 B | | Migrate | 18652 B | 1736 B | 808 B | Proged | 1482874766 B | | Error-asserts | 17640 B | 1424 B | 804 B | Erased | 1568888832 B |