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

perf: forward default allocator methods and remove memory overprovisioning #1045

Merged
merged 3 commits into from
Apr 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 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 All @@ -45,6 +41,16 @@ unsafe impl GlobalAlloc for LockedAllocator {
let layout = Self::align_layout(layout);
unsafe { self.0.dealloc(ptr, layout) }
}

unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
let layout = Self::align_layout(layout);
unsafe { self.0.alloc_zeroed(layout) }
}

unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
let layout = Self::align_layout(layout);
unsafe { self.0.realloc(ptr, layout, new_size) }
}
}

#[cfg(all(test, not(target_os = "none")))]
Expand Down