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

lfs_bd_cmp() compares more bytes at one time #395

Merged
merged 1 commit into from
Dec 4, 2020

Conversation

gmpy
Copy link

@gmpy gmpy commented Mar 13, 2020

It's very slowly to compare one byte at one time. Here are the
performance I get from 128M spinand with NFTL by sequential writing.

| file size | buffer size | write speed |
| 10 MB | 0 B | 3206.01 KB/s |
| 10 MB | 1 B | 2434.04 KB/s |
| 10 MB | 2 B | 2685.78 KB/s |
| 10 MB | 4 B | 2857.94 KB/s |
| 10 MB | 8 B | 3060.68 KB/s |
| 10 MB | 16 B | 3155.30 KB/s |
| 10 MB | 64 B | 3193.68 KB/s |
| 10 MB | 128 B | 3230.62 KB/s |
| 10 MB | 256 B | 3153.03 KB/s |

| 70 MB | 0 B | 2258.87 KB/s |
| 70 MB | 1 B | 1827.83 KB/s |
| 70 MB | 2 B | 1962.29 KB/s |
| 70 MB | 4 B | 2074.01 KB/s |
| 70 MB | 8 B | 2147.03 KB/s |
| 70 MB | 64 B | 2179.92 KB/s |
| 70 MB | 256 B | 2179.96 KB/s |

The 0 Byte size means no validation and the 1 Byte size is how
littlefs do before. Based on the above table and to save memory,
comparing 8 bytes at one time is more wonderful.

Signed-off-by: WeiXiong Liao [email protected]

It's very slowly to compare one byte at one time. Here are the
performance I get from 128M spinand with NFTL by sequential writing.

| file size | buffer size  | write speed  |
| 10 MB     | 0   B        | 3206.01 KB/s |
| 10 MB     | 1   B        | 2434.04 KB/s |
| 10 MB     | 2   B        | 2685.78 KB/s |
| 10 MB     | 4   B        | 2857.94 KB/s |
| 10 MB     | 8   B        | 3060.68 KB/s |
| 10 MB     | 16  B        | 3155.30 KB/s |
| 10 MB     | 64  B        | 3193.68 KB/s |
| 10 MB     | 128 B        | 3230.62 KB/s |
| 10 MB     | 256 B        | 3153.03 KB/s |

| 70 MB     | 0   B        | 2258.87 KB/s |
| 70 MB     | 1   B        | 1827.83 KB/s |
| 70 MB     | 2   B        | 1962.29 KB/s |
| 70 MB     | 4   B        | 2074.01 KB/s |
| 70 MB     | 8   B        | 2147.03 KB/s |
| 70 MB     | 64  B        | 2179.92 KB/s |
| 70 MB     | 256 B        | 2179.96 KB/s |

The 0 Byte size means no validation and the 1 Byte size is how
littlefs do before. Based on the above table and to save memory,
comparing 8 bytes at one time is more wonderful.

Signed-off-by: WeiXiong Liao <[email protected]>
@gmpy
Copy link
Author

gmpy commented Mar 13, 2020

#381 @geky @pjsg

Following the codes, I get that lfs will always hit cache when do validate and the root cause of
slow speed is comparative efficiency. Here is my new patch to improve write performance.

@pjsg
Copy link

pjsg commented Mar 13, 2020

This looks reasonable to me....

uint8_t dat;
int err = lfs_bd_read(lfs,
for (lfs_off_t i = 0; i < size; i += diff) {
uint8_t dat[8];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was 8 chosen.
Remember that this is being stored on the stack.
Any thoughts on making this configurable or reasons why it shouldn't be configurable?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too many configurations can be confusing.
I think 8 bytes is the best balance between performance and used space.

@geky geky added this to the v2.3 milestone Nov 16, 2020
@geky
Copy link
Member

geky commented Nov 16, 2020

Hi @gmpy, this is a great patch and great analysis!

Sorry this PR has been hanging for so long. I wasn't able to make a release for a while, but will bring this in the next minor release.

@geky geky changed the base branch from master to devel December 4, 2020 04:34
@geky geky merged commit 6627206 into littlefs-project:devel Dec 4, 2020
This was referenced Dec 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants