-
Notifications
You must be signed in to change notification settings - Fork 806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New API function lfs_find_free_blocks. #610
New API function lfs_find_free_blocks. #610
Conversation
0bbba67
to
f82f34c
Compare
Sorry about leaving this open for so long. It arrived at an inconvenient time and ended up flying under my radar. I've been look at other ways of approaching this problem, but that's not an excuse to not merge this when it's likely immediately useful to users. Thoughts on renaming this function to The only concern I can think of is that it may be preferable to have an incremental/interruptable garbage collector, but that would be much more involved, and we can always introduce a new API for this in the future. I realize this is way past the statute of limitations for open PRs, so I can go ahead and take it over. This needs to be updated for consistent code style (4-space indentions, 80-column width) and needs at least minimal tests. |
After more thought, I don't think this will make it in to this minor release. It's a good idea, but needs a bit of work:
And the current minor release has already been delayed enough. With a number of ideas around garbage-collection in #791, I think it would make more sense to look at this as a piece of a larger set of garbage-collection work. |
795505d
to
444d243
Compare
What exactly do you mean by shifting lookahead by the first clear bit?
If we keep the same offset shift then lfs_alloc can directly use the new function and reuse in this sense the code. |
Tests passed ✓, Code: 16694 B (+0.2%), Stack: 1448 B (+1.1%), Structs: 788 B (+0.0%)
|
Sorry, I did write that confusingly. Consider a new filesystem with say 32 blocks and a lookahead of 8 bits:
In the current implementation, calling lfs_find_free_blocks moves
But it should move here:
Otherwise we miss free blocks. The implementation as-is isn't broken in the sense that it gives incorrect blocks, but:
I think changing it to something like this would work: lfs->free.off = (lfs->free.off + lfs->free.i) % lfs->cfg->block_count; |
What if we allow users to pick a strategy? Your proposal is consistent in repeated calls and makes let's say necessary shift. It may work very badly in specific cases like this (I am not sure whether and how frequently it may happen):
If this case is low probable or never may exist I am going to update the equation to your proposal. Why doesn't the code use the free.i directly it should be equal to free.size when all block are used? |
That is good example of where the lookahead buffer performs poorly. But I think that's more a flaw the approach of the lookahead buffer as a whole. This example works poorly in both strategies:
I don't think there was a reason. The previous code just wasn't written to handle |
The new function is updated to move the lookahead at the first free block. Would you like something else to be done? |
Tests passed ✓, Code: 16694 B (+0.2%), Stack: 1448 B (+1.1%), Structs: 788 B (+0.0%)
|
5443bd2
to
9f46d2f
Compare
…esn't exist move it for whole lookahead size.
Tests passed ✓, Code: 16694 B (+0.2%), Stack: 1448 B (+1.1%), Structs: 788 B (+0.0%)
|
Hi @opilat, sorry, I somehow missed your last comment's question. TODO list for this PR, from my perspective:
I went ahead and made these changes here, but forgot I don't have push access to this PR: Are you able to either grant push access or merge the commits in the above? If you're ok with these changes than this looks good to me for the next minor release. |
It performs a free block search which later will not slow down a write operation.
It helps to have predictable write times. In scenarios like storing data from a microphone. Write taken too long when littlefs does the free block search during it.
I am open to other solutions.