From e60e2127b7a22986184a7980a096c9066ae1c84e Mon Sep 17 00:00:00 2001 From: Shaun Beautement Date: Fri, 19 Apr 2024 14:30:04 +0200 Subject: [PATCH] perf(alloc): don't pad the size of allocations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Martin Kröning --- src/mm/allocator.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/mm/allocator.rs b/src/mm/allocator.rs index cf77a5374b..c068a5ddcd 100644 --- a/src/mm/allocator.rs +++ b/src/mm/allocator.rs @@ -3,7 +3,6 @@ use core::alloc::{GlobalAlloc, Layout}; -use align_address::Align; use hermit_sync::RawInterruptTicketMutex; use talc::{ErrOnOom, Span, Talc, Talck}; @@ -16,13 +15,10 @@ impl LockedAllocator { #[inline] fn align_layout(layout: Layout) -> Layout { - let size = layout - .size() - .align_up(core::mem::size_of::>()); let align = layout .align() .max(core::mem::align_of::>()); - 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) {