Skip to content

littlefs: Fix issue with immediate exhaustion and small unaligned storage #5761

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

Merged
merged 1 commit into from
Jan 18, 2018

Conversation

geky
Copy link
Contributor

@geky geky commented Dec 27, 2017

This was a small hole in the logic that handles initializing the lookahead buffer. To imitate exhaustion (so the block allocator will trigger a scan), the lookahead buffer is rewound a full lookahead and set up to look like it is exhausted. However, unlike normal allocation, this rewind was not kept aligned to a multiple of the scan size, which is limited by both the lookahead buffer and the total storage size.

This bug went unnoticed for so long because it only causes problems when the block device is both:

  1. Not aligned to the lookahead buffer (not a power of 2)
  2. Smaller than the lookahead buffer (< 64 blocks)

While this seems like a strange corner case for a block device, this turned out to be very common for internal flash, especially when a handful of blocks are reserved for code.

note: intended for patch
cc @marcuschangarm

@@ -2040,8 +2040,8 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) {
}

// setup free lookahead
lfs->free.begin = -lfs->cfg->lookahead;
lfs->free.off = lfs->cfg->lookahead;
lfs->free.begin = -lfs_min(lfs->cfg->lookahead, lfs->cfg->block_count);
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be good to have a comment here as to why you are doing this ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be updated

…torage

This was a small hole in the logic that handles initializing the
lookahead buffer. To imitate exhaustion (so the block allocator
will trigger a scan), the lookahead buffer is rewound a full
lookahead and set up to look like it is exhausted. However,
unlike normal allocation, this rewind was not kept aligned to
a multiple of the scan size, which is limited by both the
lookahead buffer and the total storage size.

This bug went unnoticed for so long because it only causes
problems when the block device is both:
1. Not aligned to the lookahead buffer (not a power of 2)
2. Smaller than the lookahead buffer

While this seems like a strange corner case for a block device,
this turned out to be very common for internal flash, especially
when a handleful of blocks are reserved for code.
@geky geky force-pushed the littlefs-fix-lookahead-rewind branch from 3781597 to 5e7c097 Compare January 4, 2018 16:23
@0xc0170
Copy link
Contributor

0xc0170 commented Jan 12, 2018

Waiting for one review update, meantime

/morph build

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 15, 2018

/morph build

@mbed-ci
Copy link

mbed-ci commented Jan 15, 2018

Build : FAILURE

Build number : 870
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/5761/

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 16, 2018

license server error

/morph build

@mbed-ci
Copy link

mbed-ci commented Jan 16, 2018

Build : SUCCESS

Build number : 876
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/5761/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build

@mbed-ci
Copy link

mbed-ci commented Jan 16, 2018

@mbed-ci
Copy link

mbed-ci commented Jan 16, 2018

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.

5 participants