Skip to content

Do open duration depends on number of files in folder ? #721

Open
@Antatip

Description

@Antatip

Hello,

I am new to littlefs and file systems in general.
I am making benchmarks of it using STM32WB55 and a 16M SPI flash.

I noticed that open time depends on the number of files in a folder :
A single file in a folder can be opened in 18ms (with the best settings I found)

When my folder contains 50 files :

root
└─── sounds
│  └── allelujah.mp3
│  └── alf.mp3
│  └── boom.mp3
│   ...
│   ...
│   └── zzz.mp3

I can open it in ~450ms.

So I tried putting each file in a folder :

root
└─── sounds
│   └── allelujah
│   │   └── s.mp3
│   └── alf
│   │   └── s.mp3
│   └── boom
│   │   └── s.mp3
│   ...
│   ...
│   └── zzz
│   │   └── s.mp3

In that case, one file opens in 240ms

Then I put every folder in alphabetical folders :

root
└─── sounds
│   └── a
│   │   └── allelujah
│   │   │  └── s.mp3
│   │   └── alf
│   │   │  └── s.mp3
│   └── b
│   │   └── boom
│   │   │  └── s.mp3
│   ...
│   ...
│   └── z
│   │   └── zzz
│   │   │  └── s.mp3

Here, file opens in around 150ms.

Settings

LFS v2.5.0

fileSystem_config.read = device_flash_sector_device_read;
fileSystem_config.prog = device_flash_sector_device_prog;
fileSystem_config.erase = device_flash_sector_device_erase;
fileSystem_config.sync = device_flash_sector_device_sync;

I tried using block read/write/erase callbacks but I get a LFS_ERR_NOSPC error after creating ~100 files so I use the sector functions (driver w25qxx).

Sync just returns 0.

fileSystem_config.read_size = 64;
fileSystem_config.prog_size = 32;
fileSystem_config.block_size = 4096; // Using sectors instead of blocks
fileSystem_config.block_count = 4096;
fileSystem_config.block_cycles =  500;
fileSystem_config.cache_size = 256;
fileSystem_config.lookahead_size = 1024; // waiting a nice open time before finding the best value

Questions

Are those the standard durations ?
If so, any idea of performance improvements ?
If not, What am I doing wrong ?

PS : Why are folders a lot quicker to find than files ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions