#1209·littlefs

Performance comparaison: lfs_fs_size vs lfs_stat

Author: ashirojiCreated May 27, 2026Updated May 27, 2026

Hi @geky ,

In my current project, I'm using littleFS to store various files (logs, sensor data) to a NOR flash(128Mbytes) and I need to keep track of the used/free memory to inform the user of how much memory is still available. So I used the lfs_fs_size (littlefs_statvfs in zephyr port) After leaving one device running for a while, I got hit with 30s lags. Doing some research in the GitHub repo, I see that this is expected due to littleFS needing to scan the memory each time lfs_fs_size is called, so more files/bigger memory -> more time.

I've been thinking about ways to workaround this problem The first idea I got is: since I know the file names, I can use lfs_stat and add up all the results. Is lfs_stat a constant time function? or is it possible that it will cause lags similar to lfs_fs_size?

The second idea I got is: create my own data structure to keep track of data written to disk (fs_write returns the number of bytes written + metadata size). That way I can avoid the performance hit using lfs_fs_size. Does this sound like a plausible workaround to you?

Thank you for your time and help

Source: littlefs-project/littlefs