pycom / pycom-micropython-sigfox

A fork of MicroPython with the ESP32 port customized to run on Pycom's IoT multi-network modules.
MIT License
197 stars 167 forks source link

sflash_diskio_littlefs.c: Enable block level wear-leveling #516

Closed robert-hh closed 3 years ago

robert-hh commented 3 years ago

Otherwise, superblocks will be overly used and wear out in cases, where a single file is rewritten again and again.

See https://forum.pycom.io/topic/6734/external-flash-lose-files

geza-pycom commented 3 years ago

Hello! May I ask why did you select the value 1000 for block_cycles? Is it based on results of your testing, or just based your best feelings? Thanks in advance !

robert-hh commented 3 years ago

The littlefs lib recommends values between 100 and 1000. After short consideration it seemed to me, that for larger (free) flash sizes larger values should be taken. But I did not make any simulation. And I did not scan the internet for any resources. Obviously, any setting different to 0 is an improvement. My gut feeling would be the square root of the number of free blocks. That would be about 45. And smaller numbers have a worse performance that larger numbers, because of the additional super block swapping once that setting is reached. Micropython.org uses 100. This setting affects the wear leveling used for the super blocks. Ordinary data block numbers are used in a round robin fashion anyhow.

geza-pycom commented 3 years ago

Thanks for the detailed asnwer and all the analysis you have done in this topic. I would recommend to go with value 100, same as the original MicroPython project.

robert-hh commented 3 years ago

Fixed in 1.20.3.b3