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

Relaxed lookahead alignment, other internal block alloc readability improvements #912

Merged
merged 4 commits into from
Jan 19, 2024

Conversation

geky
Copy link
Member

@geky geky commented Dec 20, 2023

This drops the lookahead buffer from operating on 32-bit words to operating on 8-bit bytes, and removes any alignment requirement. This may have some minor performance impact, but it is unlikely to be significant when you consider IO overhead.

The original motivation for 32-bit alignment was an attempt at future-proofing in case we wanted some more complex on-disk data structure. This never happened, and even if it did, it could have been added via additional config options.

This has been a significant pain point for users, as providing word-aligned byte-sized buffers in C can be a bit annoying.


This also includes a number of internal block allocator improvements, mostly around naming things and making the logic hopefully easier to understand.

- Renamed lfs.free      -> lfs.lookahead
- Renamed lfs.free.off  -> lfs.lookahead.start
- Renamed lfs.free.i    -> lfs.lookahead.next
- Renamed lfs.free.ack  -> lfs.lookahead.ckpoint
- Renamed lfs_alloc_ack -> lfs_alloc_ckpoint

These have been named a bit confusingly, and I think the new names make
their relevant purposes a bit clearer.

At the very it's clear lfs.lookahead is related to the lookahead buffer.
(and doesn't imply a closed free-bitmap).
Some of this is just better documentation, some of this is reworking the
logic to be more intention driven... if that makes sense...
This drops the lookahead buffer from operating on 32-bit words to
operating on 8-bit bytes, and removes any alignment requirement. This
may have some minor performance impact, but it is unlikely to be
significant when you consider IO overhead.

The original motivation for 32-bit alignment was an attempt at
future-proofing in case we wanted some more complex on-disk data
structure. This never happened, and even if it did, it could have been
added via additional config options.

This has been a significant pain point for users, since providing
word-aligned byte-sized buffers in C can be a bit annoying.
@geky geky added enhancement needs minor version new functionality only allowed in minor versions labels Dec 20, 2023
@geky-bot
Copy link
Collaborator

Tests passed ✓, Code: 16800 B (-0.1%), Stack: 1432 B (-1.1%), Structs: 800 B (+0.0%)
Code Stack Structs Coverage
Default 16800 B (-0.1%) 1432 B (-1.1%) 800 B (+0.0%) Lines 2360/2536 lines (+0.0%)
Readonly 6130 B (+0.0%) 448 B (+0.0%) 800 B (+0.0%) Branches 1199/1522 branches (+0.1%)
Threadsafe 17668 B (-0.1%) 1432 B (-1.1%) 808 B (+0.0%) Benchmarks
Multiversion 16864 B (-0.1%) 1432 B (-1.1%) 804 B (+0.0%) Readed 29369693876 B (+0.0%)
Migrate 18480 B (-0.1%) 1736 B (-0.9%) 804 B (+0.0%) Proged 1482874766 B (+0.0%)
Error-asserts 17452 B (-0.2%) 1424 B (-1.1%) 800 B (+0.0%) Erased 1568888832 B (+0.0%)

@HiFiPhile
Copy link

Hi, could you please also update comment in lfs_util.h ?

Especially it still mentions 64-bit alignment for malloc requirement:

// Note, memory must be 64-bit aligned

The only reason we needed this alignment was for the lookahead buffer.

Now that the lookahead buffer is relaxed to operate on bytes, we can
relax our malloc alignment requirement all the way down to the byte
level, since we mainly use lfs_malloc to allocate byte-level buffers.

This does introduce a risk that we might need word-level mallocs in the
future. If that happens we will need to decide if changing the malloc
alignment is a breaking change, or gate alignment requirements behind
user provided defines.

Found by HiFiPhile.
@geky
Copy link
Member Author

geky commented Jan 16, 2024

Good catch, should be updated now.

There is a risk that we will need word-alignment in the future, but I guess we'll address that when we get to that.

@geky-bot
Copy link
Collaborator

Tests passed ✓, Code: 16808 B (-0.1%), Stack: 1432 B (-1.1%), Structs: 800 B (+0.0%)
Code Stack Structs Coverage
Default 16808 B (-0.1%) 1432 B (-1.1%) 800 B (+0.0%) Lines 2360/2536 lines (+0.0%)
Readonly 6130 B (+0.0%) 448 B (+0.0%) 800 B (+0.0%) Branches 1199/1522 branches (+0.1%)
Threadsafe 17676 B (-0.1%) 1432 B (-1.1%) 808 B (+0.0%) Benchmarks
Multiversion 16872 B (-0.1%) 1432 B (-1.1%) 804 B (+0.0%) Readed 29369693876 B (+0.0%)
Migrate 18488 B (-0.1%) 1736 B (-0.9%) 804 B (+0.0%) Proged 1482874766 B (+0.0%)
Error-asserts 17456 B (-0.2%) 1424 B (-1.1%) 800 B (+0.0%) Erased 1568888832 B (+0.0%)

@geky geky mentioned this pull request Jan 16, 2024
@geky geky added next minor and removed needs minor version new functionality only allowed in minor versions labels Jan 17, 2024
@geky geky added this to the v2.9 milestone Jan 17, 2024
@geky geky changed the base branch from master to devel January 19, 2024 18:21
@geky geky merged commit ed7bd05 into devel Jan 19, 2024
109 checks passed
@geky geky mentioned this pull request Jan 19, 2024
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.

None yet

3 participants