This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

FlashFS - power fail and wear levelling

Can anyone explain how the FlashFS handles loss of power? I am concerned about losing data that has been buffered but not written during a power failure. I will be writing directly to SPI flash chips (M25Pxx).

Also, does the file system perform wear levelling?

Parents
  • I think no file system is immune to power failure. Like your PC, also the FlashFS will fail on power failure. So you need to avoid this situation.

    An idea would be to use a battery backup and power fail indication. When loss of power is indicated, an application needs to complete the file operation and then shutdown.

    The other low cost option is to predetect the power failure (for example by monitoring the 50Hz ticks from mains). When the power fail is detected, the file should be closed. During this time the power is taken from power capacitors, big enough to provide power for about 100 ms or so (to complete the file close operation).

    The FlashFS implements some sort of wear-levelling until you reformat or erase all files. Then it starts from beginning.

Reply
  • I think no file system is immune to power failure. Like your PC, also the FlashFS will fail on power failure. So you need to avoid this situation.

    An idea would be to use a battery backup and power fail indication. When loss of power is indicated, an application needs to complete the file operation and then shutdown.

    The other low cost option is to predetect the power failure (for example by monitoring the 50Hz ticks from mains). When the power fail is detected, the file should be closed. During this time the power is taken from power capacitors, big enough to provide power for about 100 ms or so (to complete the file close operation).

    The FlashFS implements some sort of wear-levelling until you reformat or erase all files. Then it starts from beginning.

Children
  • I think no file system is immune to power failure.

    Hmm, aren't journaling file systems designed to be immune to power failure? It's not that difficult to make file system operations atomic across unexpected power cycles.

  • Many journaling FS are handling meta-data but not file data. When you have an open file and write data to it, you may not know how many bytes that will survive, and you can't modify a file in the middle and know what state it will be in if there is a power loss.

    In some situations, you may have to create a new file and then replace the original file (a meta data operation) to get a snapshot change that will guarantee that you either have the old or the new file if you get a power loss during the operation.

    In an embedded environment, I would be very scared to use a FS that doesn't have at least journaling of meta-data.