Skip to content
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

Circular scanning of free sectors in kv_alloc() #111

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

rpc-fw
Copy link

@rpc-fw rpc-fw commented Dec 20, 2021

With this patch alloc_kv() will scan sectors in a circular fashion, instead of starting from the first sector every time. Alloc_kv will check the sectors in sector cache first, and then continue scanning from the sector it found during the previous alloc. This improves write performance when total number of sectors is large, as fully used sectors no longer need to be inspected.

The improvement should be clearly noticeable when writing to the last sectors of a large kvdb. I used it on a 512 kb flash region, with each sector 4 kb in size.

@armink
Copy link
Owner

armink commented Dec 21, 2021

I will need some time to review it. Do you have some test data before and after the patch?

@rpc-fw
Copy link
Author

rpc-fw commented Dec 21, 2021

I have some logs from a test program that was writing 2 kb values in 4 kb sectors. The log captured shows the progress between two GC runs. The test randomly picks one out of 4 KVs, and each KV is first read, then written. For each read and write I logged the number of CPU cycles it took, the number of sectors read, and the number of sectors written. You can see the number of accessed sectors grow as more sectors are taken into use. After GC the writes are fast again.

default_without_circular_fix_.txt
with_circular_fix_.txt

In another test I write small values in the kvdb and observe that alloc_kv returns with my patch addresses that do not reset to 0 after the GC run (when sectors get full) but instead continue increasing until the end of the flash, after which they return back to zero. Log the value of empty_kv at the end of alloc_kv to see it.

@armink
Copy link
Owner

armink commented Dec 21, 2021

OK, Thx. I' ll test it in this weekend.

@rpc-fw
Copy link
Author

rpc-fw commented Jan 10, 2022

Did you have a chance to try it? Any thoughts?

@armink
Copy link
Owner

armink commented Jan 10, 2022

hi, @rpc-fw , I have reviewed your PR. There are a lot of changes in this PR. I'm trying a simpler way to modify.

Please wait some time for me. Thx. ;>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants