littlefs-project / littlefs

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

Suitable for microcontroller onboard flash? #29

Open kisielk opened 6 years ago

kisielk commented 6 years ago

Is littlefs suitable to use with a microcontroller's onboard flash? Specifically on something like the STM32F4 series.

geky commented 6 years ago

I know of at least 2 projects that are using littlefs on onboard flash successfully.

It depends on how much onboard flash you have. Each file in littlefs takes up at minimum 1 block (erase unit), each directory takes up 2 blocks, and the superblock takes up 4. It's a good idea to overallocate by ~1.5x so that the copy-on-write structures have room to move around, more based on how long you want to the device to last as the underlying blocks wear out (this simulation lets you try out scenarios).

Onboard flash is usually quite small compared to external flash, so the wasted space from 1 block per file may be a problem. I have some plans to improve this but it will take a while to implement. Other than that you should be fine.

Other notes about onboard vs external SPI flash:

If littlefs doesn't fit, SPIFFS is another filesystem in this space that's better optimized for very small storage, I've heard good things about it.

Let me know if that answers your question.

kisielk commented 6 years ago

Thanks for the detailed answer. The 4 blocks required for the superblock would probably be the limiting factor for me. Usually I have 1 - 5 different types of information that need to be persisted, each of which would constitute a "file". On the F4's I'm using the sector size is around 128 KByte for the big sectors (5-15) where I store this data. Because there's so few sectors, having to sacrifice 4 of them just for the superblock would probably not work for all my applications.

The data is only written on explicit user request, so the longevity isn't as much of a concern.

geky commented 6 years ago

Makes sense. Have you looked into SPIFFS? It doesn't have a superblock and stores files much more compactly. It sounds like it would fit your use case quite well.

kisielk commented 6 years ago

I've used SPIFFs on a product with external QuadSPI flash, but haven't tried it on the internal one yet. I guess I should give it a try. Actually I was considering swapping the FS on that product for littlefs :)

geky commented 6 years ago

Ah! That's exciting to hear