littlefs-project / littlefs

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

Do we really need directory structures in meta data layer for simple structure variable read/write? #970

Open msswamy11 opened 7 months ago

msswamy11 commented 7 months ago

Hello, I am planning to use this LittleFS to my microcontroller project, my requirement is very simple as read and write some data structures in C language, lfs_file_read(&lfs, &file, &boot_count, sizeof(boot_count)); lfs_file_write(&lfs, &file, &boot_count, sizeof(boot_count));

I have integrated LFS into my project and found more time for write operations on my 35MHZ clock. For init around 1.7ms For write around 4.7ms it was taking.

Then started digging into code, observed so many directory related operations even though it was not required for simple variable read/write.

Please provide some suggestions how to make it very fast? Any other way to use this framework without directory structure for simple variable writes, to make it faster?

geky commented 7 months ago

Hi @msswamy11,

There are a number of known issues with performance in littlefs, such as https://github.com/littlefs-project/littlefs/issues/783. These are being worked on, but require significant changes. It may be useful to read through other issues, but the information is a bit scattered.

Then started digging into code, observed so many directory related operations even though it was not required for simple variable read/write.

This is a bit of a red-herring. Files can't not exist in a directory, by default they just exist in the root directory.

In littlefs, the internal lfs_dir_* functions handle anything related to file metadata, including simple file updates. Unfortunately, updating metadata gets quite complicated when you need to also handle power-loss and flash's limitations.