How the filesystems cope
FLASHVIS compares five filesystems today:
FASTFFS, LittleFS, SPIFFS, JesFS, and ChaN FatFs over the
ESP-IDF wear_levelling FTL (shown as FAT+WL), with more
planned. The first four are purpose-built for raw flash: they write new data into erased space
and let superseded copies linger as garbage to reclaim later, since flash cannot cheaply
overwrite in place. FatFs is the outlier, a classic overwrite-in-place FAT
filesystem that only runs on flash because a wear-levelling translation layer beneath it remaps
and rotates sectors to imitate a rewritable disk.
What they share
- Bounded RAM/ROM. All five are built to run in a small, fixed amount of memory.
RAM usage is strictly bounded and can be backed by statically provided buffers, so
consumption does not grow as the volume fills.
- Wear leveling. All five spread erases across the die so no one sector wears out
early. The four flash-native designs rotate their own allocation (and GC) cursors; FatFs
leans entirely on the wear_levelling layer beneath it to remap and rotate physical sectors.
- Power-loss behavior is where they diverge. FASTFFS and LittleFS are fully
copy-on-write and fall back to the last known good state after an interrupted write. The
log-structured SPIFFS and chain-structured JesFS recover their committed files on remount.
FatFs overwrites in place, so a write cut short, for example by a full volume,
can leave a file truncated.
FASTFFS
The core idea is simple: file data is written copy-on-write into flash
sectors, then a compact append-only index record (4 bytes) commits the namespace update. On
remount, the index is replayed to recover the current set of names and where they start. Old
file versions and interrupted writes are left as obsolete or orphaned data for later
cleanup.
Within a sector, file metadata is appended to the tail, growing backwards, while file
data (including the name) grows from the start of the sector down. This allows many
smaller files to share a sector efficiently. When a file is deleted/overwritten it is marked
obsolete, leaving any other live files in place and intact.
Its garbage collector is incremental, reclaiming in small cheap background steps that
keep garbage low for a small, steady cost. The background GC control sets how often this
runs during the automatic workload, but typically this would happen in the background while the
application using FASTFFS is idle. It will still reclaim inline when free (erased, usable)
space runs tight. It levels wear through two round-robin cursors: one for GC and one for alloc.
Compaction triggers on write allocation pressure when there is nowhere free/erased to
write to, and no sector can be erased because they still have live data. It copies out live
files (or parts of them) that are trapping the most obsolete/reclaimable space, so that sectors
can be erased and reused. This is only done when necessary, since it is expensive and causes
write amplification.
LittleFS
At a high level, LittleFS is a block based filesystem that uses small logs to store
metadata and larger copy-on-write (COW) structures to store file data.
In LittleFS, these ingredients form a sort of two-layered cake, with the small logs (called
metadata pairs) providing fast updates to metadata anywhere on storage, while the COW
structures store file data compactly.
Small files (under 1/4th of a sector, or 1KB) are stored directly in the metadata
pairs. Files over that threshold are stored in one or more whole sectors.
It reclaims space as part of its writes rather than in a background operation. It has
no incremental GC step to drive, so the background GC control does not appear when
LittleFS is focused. It does have a GC function, but it does not reclaim space and is very
expensive, so it is not used here out of fairness.
SPIFFS
SPIFFS is log-structured at a 256-byte page granule, the same size as
one die cell, so its native map lines up one-to-one with the grid. Every 4 KB block begins
with an object-lookup table: a compact array with one entry per data page in the block,
recording which object that page belongs to. That table is SPIFFS's metadata and its
liveness model in one.
Deleting or replacing a file erases nothing right away; it programs the page's lookup entry
to a deleted marker (0x0000, since programming only clears bits to
0), leaving the page as garbage that lingers until its whole block is dead. Like
FASTFFS, SPIFFS then reclaims in bounded background steps: a quick pass erases one block
whose pages are all deleted, moving nothing. Because that step is small and churn-safe, SPIFFS
is the other filesystem the background GC control drives. Turn it up and
SPIFFS tidies more often between writes, just like FASTFFS. It also reclaims inline when free
space runs tight.
JesFS
JesFS organizes the chip as chains of 4 KB sectors. Sector 0 holds a master
header plus the file index, an array of pointers to each file's start. A file's
HEAD sector co-locates its metadata (name, length, CRC) with the first ~4 KB of its
data; longer files chain into further data sectors. Every sector carries a 4-byte magic
recording its state, which is exactly what the die coloring reads.
Deleting a file just rewrites those magics, the head to a deleted state and its
data sectors to a to-delete state, without erasing. Reclamation is entirely
inline and just-in-time: when a later write needs a fresh sector, the allocator sweeps
forward (a rotating cursor that also levels wear) and erases the next to-delete sector right
before reusing it. There is no separate GC pass, so the background GC control does
nothing when JesFS is focused.
FAT+WL
FatFs is the classic FAT filesystem, here ChaN FatFs over the ESP-IDF
wear_levelling FTL. FAT expects to overwrite sectors in place and does no erasing
itself; it simply rewrites the FAT table and directory entries as files change. Flash cannot
overwrite, so the wear_levelling layer beneath it does the real work: it remaps each logical
sector to a physical one and rotates a spare dummy sector on every update, spreading
repeated overwrites (including the constant FAT-table rewrites) across the die instead of
hammering one spot.
That translation layer costs 4 of the 64 sectors. Its config, state, and dummy
sectors show up as metadata on the die, leaving a 240 KB logical
volume (about 224 KB usable as FAT12, 4 KB clusters, two FAT copies). Deleting
a file frees its clusters in the FAT, but the old bytes stay on the die as garbage until
something reuses them; nothing reclaims proactively, so the background GC control is
inert here too.
The cost of overwrite-in-place is the headline. Driven through the same workload, FatFs
produces far more erasing than the log-structured designs. And because FAT is not
copy-on-write, a write interrupted by a full volume can leave a file truncated, where the
log-structured filesystems fall back cleanly.