When ist littlefs garbage collection / flash erase block called?

Hello,

I would like to use littlefs in out Project and it seems to be very usefull. I read several documents and have the sample running on the eval board. But there is one important Question I couldn't answer by myself.

When is garbage collector triggered that erases all not used blocks of the below Flash? 

I would have real Problems in out product when suddenly between two writes to one or even two files the file System decides: I have to erase 30 blocks in the Flash and be therefore busy for some seconds. There are several places in my functional flow where it would be perfectly fine to do this necessary erase. And if this is done often enough I expect it doesn't take Long.

There is this block_cycle Parameter which I haven't really understood. It gives the number blocks are erased (so this is declaring one block old by writing the new Content to a new block) until the meta data is moved to another block. Block is not my Flash page size, but a smaller configurable size.

Would be great if someone could explain it or Point me to a place where this is explained.

Regards
Erwin

  • Hi Erwin,

    I must admit that I don't have a intimate knowledge of littlefs, and it is not written by us. However, you can read a bit about this in the littlefs documentation. I suggest you search for "garbage" under DESIGN. I also see a post here about how you can do garbage collection when there is time to do it, which should prevent garbage collection from happening at other times.

  • Hi Einar,

    I expected to get an email when someout updates this ticket. But this didn't happen because of your update so I see your response only today.

    Before raising this ticket I read the  design document from GitHub which helped much and where I get this understanding of gargabe Collection. But your mentioned post is interesting. May be I tweak littlefs a Little bit.

    In the meantime I've played around with the Zephyr variant of littleFS on the nrf5340 development board. According my Observation there is no garbage Collection. Every time a new page is required, i.e. littleFS wants to write data on it, the page is erase. I guess, even when the page is already empty. I hope the time to erase just one page is short enough that it doesn't harm our product too much.

    Another think I've observed is that the Format function is not exported to fs Level (littleFS is only a speciallized implementation of the General file System. Do you know whether there is a Special reason for this? I realized it by calling lfs_format directly. But after that I have to call unmount and mount again  to get the file System working.

    Hopefully I turned now Reply notifications on. So I might receive an email when you or someone else responds.

    Regards
    Erwin

  • Hi Erwin,

    I do not know the reason for this, unfortunately. You could ask the Zephyr community on Discord and see if someone there knows about why this is.

Related