pellepl / spiffs

Wear-leveled SPI flash file system for embedded devices
MIT License
1.52k stars 402 forks source link

Split Garbage Collection (SPIFFS_gc) Into Smaller Chunks #289

Open peteman720 opened 2 years ago

peteman720 commented 2 years ago

Hello,

I am running SPIFFS on an ARM M4F processor connected to an 8MB MX25R6435F SPI flash. SPIFFS is allocated 6MB of the external flash, and has been configured for 64KB blocks with 256B pages.

As the flash fills up, write performance degrades. I can improve write performance by manually running garbage collection, but SPIFFS_gc often requires several seconds to run when the flash is ~85% full and SPIFFS_GC_MAX_RUNS=1. I would like to run garbage collection in the background, but 3 seconds is far too long to block all IO in my application.

My question is thus: Is it possible to split up garbage collection into smaller chunks that can be interspersed between other, more important operations? A quick look at SPIFFS_gc shows that SPIFFS_LOCK is held during the entirety of spiffs_gc_check, which leads me to believe the that garbage collection must be done atomically.

I'd be interested to hear from anyone else who has encountered similar performance problems and found a way to run garbage collection in the background without blocking other filesystem IO for an extended period.

Thanks for the help!