Skip to content

Lookahead bug? #46

@davidefer

Description

@davidefer

Hi
I'm working with an SPI flash with 126 usable/erasable blocks of 65536 bytes each, The page write size is 256. littlefs is V1.3.
I'm experiencing a problem while writing big files.

When I format the storage, I get the following:
Total space 8257536
Used space 262144
Free space 7995392
Where Used space = number of blocks(126) * blocks size(64KB) - free space (calculated as suggested here #45)

Now I write 4 files, 1MB each, in the sequence: file3, file2, file1, file0 (opened with LFS_O_WRONLY | LFS_O_CREAT | LFS_O_TRUNC)

I get the following after writing:
Total space 8257536
Used space 4718592
Free space 3538944

So far so good.

Now I write 5 files, again 1MB each, in the sequence: file4,file3,file2,file1,file0 ( file4 at the beginning and then the same as before).

Now I get the following LFS_WARN while writing file1:
// check if we have looked at all blocks since last ack
if (lfs->free.off == lfs->free.ack - lfs->free.begin) {
LFS_WARN("No more free space %d", lfs->free.off + lfs->free.begin);
return LFS_ERR_NOSPC;
}
lfs warn:299: No more free space 251

The call stack is the following:
lfs_alloc line 299
lfs_ctz_extend line 1149
lfs_file_write line 1655

lfs->free.begin = 192
lfs->free.size=59
lfs->free.off=59
lfs->free.ack=251

If I force the file1 to be closed, then I get the following:
Total space 8257536
Used space 5832704
Free space 2424832

Please note that the files are re-written without being deleted, but since I open them again with the truncate flag, I would expect that their space is immediately freed for writing.

I've seen that, when I reformat, the issue happens always after writing the block 125 (the last one). If I perform a different sequence, the block is different.

Could you please help? Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions