FS Cache on internal flash #11645
-
For devices with internal flash enabled, micropython compiles in What would be the implications of disabling this cache, or if that's not advisable, is reducing it considerably? I can't find a direct way to do it, but setting Why is external flash not similarly cached? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The reason for the flash cache is because the internal flash on STM32 parts uses enormous sector sizes (8-16kiB is not uncommon, but up to 128kiB in some parts), while the filesystem works in blocks that can be more like 512B (e.g. for FAT). So the problem we have is that the filesystem layer issues a write for a block, but we can only erase the entire sector, so first we need to copy the original sector, update the subsection with the block, then write the whole sector out. External flash typically has much smaller erase sizes, however we still do support a cache for these (typically 4kiB). See With filesystems like LittleFS, it's able to understand this sort of flash geometry, so I don't think the cache is strictly necessary (i.e. it understands that erases are disconnected from writes). But because we support switching at runtime between LittleFS and FAT the cache infrastructure stays there. Right now, there's actually not much to be gained by disabling the cache because we put it in CCRAM which is currently inaccessible to the heap as it's dis-contiguous from SRAM. This is also what restricts the size of the filesystem on some devices -- in the linker script we assign sectors of flash to either the filesystem or firmware. Only sectors that are smaller or the same size as CCRAM can be used for the filesystem. (Technically we can use larger ones but then the rest of the sector goes wasted as we can only use up to CCRAM bytes from it). However
So it would be very worthwhile to do some experiments with STM32 builds that only support LittleFS on their internal flash that use the CCRAM to gain a performance advantage. |
Beta Was this translation helpful? Give feedback.
hi @victorallume
The reason for the flash cache is because the internal flash on STM32 parts uses enormous sector sizes (8-16kiB is not uncommon, but up to 128kiB in some parts), while the filesystem works in blocks that can be more like 512B (e.g. for FAT). So the problem we have is that the filesystem layer issues a write for a block, but we can only erase the entire sector, so first we need to copy the original sector, update the subsection with the block, then write the whole sector out.
That would be extremely inefficient, so we only write the sector out again when either a timer elapses or a write comes in for a block in a different sector.
External flash typically has much smaller …