Skip to content

sharded_slab: Support alignment#134

Open
avdgrinten wants to merge 4 commits into
managarm:masterfrom
avdgrinten:sharded-slab-overalign
Open

sharded_slab: Support alignment#134
avdgrinten wants to merge 4 commits into
managarm:masterfrom
avdgrinten:sharded-slab-overalign

Conversation

@avdgrinten

Copy link
Copy Markdown
Member

Alignment works like this:

  • If an object's size fits into a slab after padding it to alignment, allocate it from a slab. Slabs are naturally aligned, so this is correct.
  • Otherwise, if the alignment is smaller than the chunk alignment, allocate it as a large object (i.e., allocate a single object chunk that has the chunk header at chunk_boundary and the object at chunk_boundary + alignment).
  • Otherwise, the object is called overaligned. In this case, allocate the object itself at a chunk_boundary and store the header out of band. Overaligned objects are the only objects that have addresses that are multiples of chunk_boundary, so they can be detected in the deallocate() path.

@avdgrinten avdgrinten requested review from 48cf, no92 and qookei June 14, 2026 10:02
Assisted-by: Claude Code (Opus 4.8)
Assisted-by: Claude Code (Opus 4.8)
@avdgrinten avdgrinten force-pushed the sharded-slab-overalign branch from caccf86 to 8318789 Compare June 14, 2026 10:08
Comment on lines +260 to +261
// Slabs are naturally aligned. Use the aligned size for bucket computation.
auto idx = policy_traits::size_to_bucket(aligned_size);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Actually, for non-power-of-2 buckets, this does not work. Even if the allocation size if a multiple of alignment, the bucket size does not need to be. So this needs some re-thinking.

Comment on lines +791 to +792
template<sharded_slab::Policy P>
using sharded_slab_domain = sharded_slab::pool<P>;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note to myself: copy/paste mistake.

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.

1 participant