Skip to content

Commit

Permalink
perf(alloc): don't pad the size of allocations
Browse files Browse the repository at this point in the history
Increasing the alignment of an allocation is sufficient to avoid false sharing.
Talc needs a little bit of metadata next to each allocation, and this would create N-8 sized holes in between every allocation due to the demands placed on it.
By removing the size requirement, false sharing avoidance is unhindered, but this allows Talc to minimize the overhead of high-alignments.
(Talc is designed to automatically place the metadata in a way that minimized false sharing, but this only helps if Talc can sneak it in within the same cache line, which is impossible if Talc thinks you want the whole cache line for user data.)

Co-authored-by: Martin Kröning <[email protected]>
Signed-off-by: Martin Kröning <[email protected]>
  • Loading branch information
SFBdragon and mkroening committed Apr 19, 2024
1 parent dd9d69a commit e60e212
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions src/mm/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use core::alloc::{GlobalAlloc, Layout};

use align_address::Align;
use hermit_sync::RawInterruptTicketMutex;
use talc::{ErrOnOom, Span, Talc, Talck};

Expand All @@ -16,13 +15,10 @@ impl LockedAllocator {

#[inline]
fn align_layout(layout: Layout) -> Layout {
let size = layout
.size()
.align_up(core::mem::size_of::<crossbeam_utils::CachePadded<u8>>());
let align = layout
.align()
.max(core::mem::align_of::<crossbeam_utils::CachePadded<u8>>());
Layout::from_size_align(size, align).unwrap()
Layout::from_size_align(layout.size(), align).unwrap()
}

pub unsafe fn init(&self, heap_bottom: *mut u8, heap_size: usize) {
Expand Down

0 comments on commit e60e212

Please sign in to comment.