Skip to content

Commit

Permalink
Merge pull request #1045 from SFBdragon/main
Browse files Browse the repository at this point in the history
perf: forward default allocator methods and remove memory overprovisioning
  • Loading branch information
mkroening authored Apr 24, 2024
2 parents 2347a3f + 5d72ad1 commit 5fa96eb
Showing 1 changed file with 11 additions and 5 deletions.
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

0 comments on commit 5fa96eb

Please sign in to comment.