Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

trim function to allow pre-erase of blocks for improved future write performance #493

Open
PaulStoffregen opened this issue Nov 30, 2020 · 1 comment

Comments

@PaulStoffregen
Copy link

I'd like to propose adding an optional trim function, which would allow low-level driver code to pre-erase blocks.

  void (*trim)(const struct lfs_config *c, lfs_block_t block);

Trim is a standard feature of modern SSD drives which allows the slow block erase to be performed "in the background". Future writes can complete much faster if the media they use has already been erased.

Hopefully littlefs could do this too? Testing with NOR flash chips seems to show most of the waiting is spent in erase(). Like with modern SSD drives, if we could have the filesystem provide this information about when used blocks are no longer needed, low level drivers could be created to use the trim info to pre-erase those blocks.

@geky
Copy link
Member

geky commented Dec 8, 2020

Ah! This is a good idea.

Unfortunately littlefs wouldn't be able to take advantage of trim as is. A large part of how littlefs works is that it doesn't actually know when blocks stop being referenced. When a file is opened, the underlying blocks are copied-on-write and share references to other possibly in-use blocks. When a file is synced littlefs doesn't bother to check what blocks have been freed, instead leaving it up to the block allocator to figure out which blocks are unused later.

Though it may be worth reconsidering when the allocator gets its much-needed redesign (#75).

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants