Skip to content

Commit

Permalink
lfs_dir_traverse: better try to use cache
Browse files Browse the repository at this point in the history
cache trace show lots of possible caching in lfs_dir_traverse

cache recache for block 835 number 4938 line=1683
cache recache for block 882 number 4938 line=1683
cache recache for block 930 number 4938 line=1683
cache recache for block 978 number 4938 line=1683

test

config
    .read_size = 4,
    .prog_size = 16,
    .block_size = 4096,
    .block_count = (8*1024),
    .cache_size = 1024,
    .metadata_max = 1024,

        for (int i = 0; i <= 1000; i++) {
                char test_path[32];
                if (i > 100) {
                        sprintf(test_path, "testdir/test%d", i-100);
                        err = lfs_remove(&lfs, test_path);
                }

                sprintf(test_path, "testdir/test%d", i);
                uint32_t prng = i;
                lfs_size_t size = 4096 + (test_prng(&prng) & 3);

                lfs_file_t file;
                err = lfs_file_open(&lfs, &file, test_path,
                                LFS_O_WRONLY | LFS_O_CREAT | LFS_O_TRUNC);
                lfs_ssize_t res = lfs_file_write(&lfs, &file, chunk, size);
                err = lfs_file_close(&lfs, &file);
        }

before patch

top read operation (number of flash read size, number of flash op)
106060, 16976,
106060, 16976,
106560, 19645,
107084, 16977,
108820, 17624,

total read/write
total read=26174188 B write=4287328 B
total num read=1445383 op write=7732 op

after patch

15044, 41
15044, 41
15044, 41
15044, 41
16068, 42,

total read=18809040 B write=4287328 B
total num read=49477 op write=7732 op
  • Loading branch information
matthieu-c-tagheuer committed May 2, 2024
1 parent a5631ce commit 80ae688
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ static int lfs_dir_traverse(lfs_t *lfs,
if (off+lfs_tag_dsize(ptag) < dir->off) {
off += lfs_tag_dsize(ptag);
int err = lfs_bd_read(lfs,
NULL, &lfs->rcache, sizeof(tag),
NULL, &lfs->rcache, lfs->cfg->block_size,
dir->pair[0], off, &tag, sizeof(tag));
if (err) {
return err;
Expand Down

0 comments on commit 80ae688

Please sign in to comment.