Filesystem Max Writes - Does MicroPython manage dynamic wearing?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
Curly Tale Games
Posts: 10
Joined: Sat May 29, 2021 5:32 am

Filesystem Max Writes - Does MicroPython manage dynamic wearing?

Post by Curly Tale Games » Mon Jun 21, 2021 3:34 am

I'm doing some data logging to the filesystem on a ESP32 running MicroPython and I have some concerns about destroying the flash storage.

I've read that the ESP32 can support 100,000 writes before it starts to degrade blocks of flash storage. I looked at the different filesystems that MicroPython supports on the ESP32: FAT and littlefs v2

https://docs.micropython.org/en/latest/ ... ystem.html

From the Readme of littlefs v2 it looks like it doesn't overwrite the same blocks over and over again to move evenly wear the storage on the chip, they call it Dynamic Wear Leveling.

https://github.com/littlefs-project/littlefs

What filesystem does Micropython use by default on the ESP32?

Does FAT provide any Dynamic Wear Leveling? What if I keep creating new log files and then delete the oldest logs after space fills up? Will it wear evenly then?

Thanks!
-Ben

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Filesystem Max Writes - Does MicroPython manage dynamic wearing?

Post by Roberthh » Mon Jun 21, 2021 5:49 am

The default file system for ESP32 is littlefs V2. You can change that to FAT by creating the file system as FAT. But FAT has indeed no wear leveling. Playing tricks with files will not help much with FAT. The critical area is the File Allocation Table (FAT) and the root directory, which are at fixed places. Littlefs use dynamic block assignment too for file management, at the cost of speed. I did a test once with a ESP32 creating files 10 Million times. Using Littlefs that worked fine.

Note 1: The wear leveling is only effective if there is sufficient room on the file system.
Note 2: FAT is faster in that Littlefs in handling files and reading directories, not nexcessary in writing to files. It did not measure the difference, but it is obvious,

Curly Tale Games
Posts: 10
Joined: Sat May 29, 2021 5:32 am

Re: Filesystem Max Writes - Does MicroPython manage dynamic wearing?

Post by Curly Tale Games » Fri Jun 25, 2021 12:49 am

Thank you so much! I think I'll stick with littlefs V2 for logging files then since I don't want to kill my ESP32's storage :)

katesimon123
Posts: 15
Joined: Mon Jun 14, 2021 12:49 am

Re: Filesystem Max Writes - Does MicroPython manage dynamic wearing?

Post by katesimon123 » Tue Jun 29, 2021 1:11 pm

Yeah, littlefs works better than FAT in the file system. I have worked on it in the Raspberry Pi 4 Project.

Post Reply