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

Dubious offset calculation in lfs_alloc_reset #484

Open
gtaska opened this issue Nov 11, 2020 · 1 comment · Fixed by #487
Open

Dubious offset calculation in lfs_alloc_reset #484

gtaska opened this issue Nov 11, 2020 · 1 comment · Fixed by #487
Labels
needs fix we know what is wrong wear leveling

Comments

@gtaska
Copy link

gtaska commented Nov 11, 2020

The code for lfs_alloc_reset is:

// Invalidate the lookahead buffer. This is done during mounting and
// failed traversals
static void lfs_alloc_reset(lfs_t *lfs) {
    lfs->free.off = lfs->seed % lfs->cfg->block_size;
    lfs->free.size = 0;
    lfs->free.i = 0;
    lfs_alloc_ack(lfs);
}

In this code, lfs->free.off is initialized with a range-bound version of lfs->seed - however it is bounded based on the configured block_size. Everywhere else that uses/updates lfs->free.off bounds it based on block_count (which makes more sense, as you are trying to find an index such that 0 <= index < block_count).

I don't think that this is necessarily going to cause immediate issues, as everywhere else it is used it appears to be subject to another modulus operation, however in certain configurations where block_size is small compared to block_count this may bias the wear leveling.

@geky geky added bug needs fix we know what is wrong labels Nov 14, 2020
@geky
Copy link
Member

geky commented Nov 14, 2020

Hi @gtaska, thanks for raising an issue! You're right this is innocuous but should be fixed.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
needs fix we know what is wrong wear leveling
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants