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

Relaxed lookahead alignment, other internal block alloc readability improvements #912

Closed geky closed 5 months ago

geky commented 6 months ago

This drops the lookahead buffer from operating on 32-bit words to operating on 8-bit bytes, and removes any alignment requirement. This may have some minor performance impact, but it is unlikely to be significant when you consider IO overhead.

The original motivation for 32-bit alignment was an attempt at future-proofing in case we wanted some more complex on-disk data structure. This never happened, and even if it did, it could have been added via additional config options.

This has been a significant pain point for users, as providing word-aligned byte-sized buffers in C can be a bit annoying.


This also includes a number of internal block allocator improvements, mostly around naming things and making the logic hopefully easier to understand.

geky-bot commented 6 months ago
Tests passed ✓, Code: 16800 B (-0.1%), Stack: 1432 B (-1.1%), Structs: 800 B (+0.0%) | | Code | Stack | Structs | | Coverage | |:--|-----:|------:|--------:|:--|---------:| | Default | 16800 B (-0.1%) | 1432 B (-1.1%) | 800 B (+0.0%) | Lines | 2360/2536 lines (+0.0%) | | Readonly | 6130 B (+0.0%) | 448 B (+0.0%) | 800 B (+0.0%) | Branches | 1199/1522 branches (+0.1%) | | Threadsafe | 17668 B (-0.1%) | 1432 B (-1.1%) | 808 B (+0.0%) | | **Benchmarks** | | Multiversion | 16864 B (-0.1%) | 1432 B (-1.1%) | 804 B (+0.0%) | Readed | 29369693876 B (+0.0%) | | Migrate | 18480 B (-0.1%) | 1736 B (-0.9%) | 804 B (+0.0%) | Proged | 1482874766 B (+0.0%) | | Error-asserts | 17452 B (-0.2%) | 1424 B (-1.1%) | 800 B (+0.0%) | Erased | 1568888832 B (+0.0%) |
HiFiPhile commented 6 months ago

Hi, could you please also update comment in lfs_util.h ?

Especially it still mentions 64-bit alignment for malloc requirement: https://github.com/littlefs-project/littlefs/blob/3513ff1afc1d67adb2e6f492f0b9bc0d798fcb0d/lfs_util.h#L218

geky commented 5 months ago

Good catch, should be updated now.

There is a risk that we will need word-alignment in the future, but I guess we'll address that when we get to that.

geky-bot commented 5 months ago
Tests passed ✓, Code: 16808 B (-0.1%), Stack: 1432 B (-1.1%), Structs: 800 B (+0.0%) | | Code | Stack | Structs | | Coverage | |:--|-----:|------:|--------:|:--|---------:| | Default | 16808 B (-0.1%) | 1432 B (-1.1%) | 800 B (+0.0%) | Lines | 2360/2536 lines (+0.0%) | | Readonly | 6130 B (+0.0%) | 448 B (+0.0%) | 800 B (+0.0%) | Branches | 1199/1522 branches (+0.1%) | | Threadsafe | 17676 B (-0.1%) | 1432 B (-1.1%) | 808 B (+0.0%) | | **Benchmarks** | | Multiversion | 16872 B (-0.1%) | 1432 B (-1.1%) | 804 B (+0.0%) | Readed | 29369693876 B (+0.0%) | | Migrate | 18488 B (-0.1%) | 1736 B (-0.9%) | 804 B (+0.0%) | Proged | 1482874766 B (+0.0%) | | Error-asserts | 17456 B (-0.2%) | 1424 B (-1.1%) | 800 B (+0.0%) | Erased | 1568888832 B (+0.0%) |