littlefs-project / littlefs

A little fail-safe filesystem designed for microcontrollers
BSD 3-Clause "New" or "Revised" License
4.9k stars 770 forks source link

Cache Puzzled #990

Open lenli-lenli opened 3 weeks ago

lenli-lenli commented 3 weeks ago

dear: The problem is about cache consistency between MCU and LITTLEFS systems . When littlefs writes a file, it just writes data to the pcache . Multiple write operations may cause inconsistencies between the cache of the MCU and pcache .At this time, the latest data has not been updated to pcache. and now pcache is updated to the low-level block device, will there be a problem here?

geky commented 1 week ago

Hi @lenli-lenli,

The pcache only holds data temporarily during a prog operation. Separate file handles also have their own caches that are flushed during lfs_file_sync or lfs_file_close, so multiple write operations should not cause conflicts.

Depending on how your MCU and block device are implemented, you may need to flush the MCU's cache with a DSB instruction or something similar after a bd read operation. But this is highly dependent on your MCU and block device. I don't think it's possible to answer this exhaustively in littlefs without reference your MCU's manual.