Moved revision count noise behind ifdef LFS_NOISY

littlefs is intentionally designed to not rely on noise, even with cksum
collisions (hello, perturb bit!). So it makes sense for this to be an
optional feature, even if it's a small one.

Disabling revision count noise by default also helps with testing. The
whole point of revision count noise is to make cksum collisions less
likely, which is a bit counterproductive when that's something we want
to test!

This doesn't really change the revision count encoding:

  vvvvrrrr rrrrrrnn nnnnnnnn nnnnnnnn
  '-.''----.----''---------.--------'
    '------|---------------|---------- 4-bit relocation revision
           '---------------|---------- recycle-bits recycle counter
                           '---------- pseudorandom noise (optional)

I considered moving the recycle-bits down when we're not adding noise,
but the extra logic just isn't worth making the revision count a bit
more human-readable.

---

This saves a small bit of code in the default build, at the cost of some
code for the runtime checks in the LFS_NOISY build. Though I'm hoping
future config work will let users opt-out of these runtime checks:

                    code          stack          ctx
  before:          38548           2624          640
  default after:   38508 (-0.1%)   2624 (+0.0%)  640 (+0.0%)
  LFS_NOISY after: 38568 (+0.1%)   2624 (+0.0%)  640 (+0.0%)

Honestly the thing I'm more worried about is using one of our precious
mount flags for this... There's not that many bits left!
This commit is contained in:
Christopher Haster
2025-01-29 13:44:00 -06:00
parent 0aef3cbcde
commit 415e6325d1
6 changed files with 193 additions and 138 deletions
+9
View File
@@ -162,6 +162,9 @@ enum lfs_type {
// Filesystem format flags
#define LFS_F_MODE 1 // Format's access mode
#define LFS_F_RDWR 0 // Format the filesystem as read and write
#ifdef LFS_NOISY
#define LFS_F_NOISY 0x00000010 // Add noise to revision counts
#endif
#ifdef LFS_CKPROGS
#define LFS_F_CKPROGS 0x00000800 // Check progs by reading back progged data
#endif
@@ -185,6 +188,9 @@ enum lfs_type {
#define LFS_M_RDONLY 1 // Mount the filesystem as read only
#define LFS_M_FLUSH 0x00000040 // Open all files with LFS_O_FLUSH
#define LFS_M_SYNC 0x00000080 // Open all files with LFS_O_SYNC
#ifdef LFS_NOISY
#define LFS_M_NOISY 0x00000010 // Add noise to revision counts
#endif
#ifdef LFS_CKPROGS
#define LFS_M_CKPROGS 0x00000800 // Check progs by reading back progged data
#endif
@@ -210,6 +216,9 @@ enum lfs_type {
#define LFS_I_RDONLY 0x00000001 // Mounted read only
#define LFS_I_FLUSH 0x00000040 // Mounted with LFS_M_FLUSH
#define LFS_I_SYNC 0x00000080 // Mounted with LFS_M_SYNC
#ifdef LFS_NOISY
#define LFS_I_NOISY 0x00000010 // Mounted with LFS_M_NOISY
#endif
#ifdef LFS_CKPROGS
#define LFS_I_CKPROGS 0x00000800 // Mounted with LFS_M_CKPROGS
#endif