Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wenyuzhao committed May 23, 2024
1 parent c96feae commit 576f804
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 32 deletions.
6 changes: 2 additions & 4 deletions buddy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ impl Mutator for BuddyMutator {

fn new() -> Self {
Self {
freelist: FreeListAllocator::new::<FREELIST_SPACE>(Lazy::new(|| {
&Self::plan().freelist_space
})),
los: LargeObjectAllocator::new(Lazy::new(|| &Self::plan().large_object_space)),
freelist: FreeListAllocator::new::<FREELIST_SPACE>(&Self::plan().freelist_space),
los: LargeObjectAllocator::new(&Self::plan().large_object_space),
}
}

Expand Down
2 changes: 1 addition & 1 deletion bump/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Mutator for BumpMutator {

fn new() -> Self {
Self {
bump: BumpAllocator::new(Lazy::new(|| &Self::plan().immortal)),
bump: BumpAllocator::new(&Self::plan().immortal),
}
}

Expand Down
12 changes: 6 additions & 6 deletions hoard/src/hoard_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,20 @@ impl HoardSpace {
}
/// Thread-local heap
pub struct HoardAllocator {
space: Lazy<&'static HoardSpace, Local>,
space: &'static HoardSpace,
tlab: DiscreteTLAB<{ SizeClass::<4>::from_bytes(Self::LARGEST_SMALL_OBJECT).as_usize() + 1 }>,
local: Lazy<Box<Pool>, Local>,
local: Box<Pool>,
}

impl HoardAllocator {
const LOCAL_HEAP_THRESHOLD: usize = 16 * 1024 * 1024;
const LARGEST_SMALL_OBJECT: usize = 1024;

pub const fn new(space: Lazy<&'static HoardSpace, Local>, _space_id: SpaceId) -> Self {
pub fn new(space: &'static HoardSpace, _space_id: SpaceId) -> Self {
Self {
space,
tlab: DiscreteTLAB::new(),
local: Lazy::new(|| Box::new_in(Pool::new(false), Meta)),
local: Box::new_in(Pool::new(false), Meta),
}
}
}
Expand All @@ -108,7 +108,7 @@ impl Allocator for HoardAllocator {
return Some(cell);
}
}
self.local.alloc_cell(size_class, &self.space)
self.local.alloc_cell(size_class, self.space)
}

fn dealloc(&mut self, cell: Address) {
Expand All @@ -119,7 +119,7 @@ impl Allocator for HoardAllocator {
{
self.tlab.push(block.size_class, cell);
} else {
self.local.free_cell(cell, &self.space);
self.local.free_cell(cell, self.space);
}
}
}
4 changes: 2 additions & 2 deletions hoard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ impl Mutator for HoardMutator {

fn new() -> Self {
Self {
hoard: HoardAllocator::new(Lazy::new(|| &Self::plan().hoard_space), HOARD_SPACE),
los: LargeObjectAllocator::new(Lazy::new(|| &Self::plan().large_object_space)),
hoard: HoardAllocator::new(&Self::plan().hoard_space, HOARD_SPACE),
los: LargeObjectAllocator::new(&Self::plan().large_object_space),
}
}

Expand Down
12 changes: 6 additions & 6 deletions hoard/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{hoard_space::HoardSpace, super_block::SuperBlock};
use array_const_fn_init::array_const_fn_init;
use mallockit::{
space::page_resource::MemRegion,
util::{mem::size_class::SizeClass, Address, Lazy, Local},
util::{mem::size_class::SizeClass, Address},
};
use spin::{relax::Yield, MutexGuard};
use std::sync::atomic::{AtomicUsize, Ordering};
Expand Down Expand Up @@ -255,7 +255,7 @@ impl Pool {
&self,
size_class: SizeClass,
blocks: &mut BlockList,
space: &Lazy<&'static HoardSpace, Local>,
space: &'static HoardSpace,
) -> SuperBlock {
// Get a block from global pool
let block = space
Expand All @@ -276,7 +276,7 @@ impl Pool {
pub fn alloc_cell(
&mut self,
size_class: SizeClass,
space: &Lazy<&'static HoardSpace, Local>,
space: &'static HoardSpace,
) -> Option<Address> {
debug_assert!(!self.global);
let mut blocks = unsafe { self.blocks.get_unchecked(size_class.as_usize()).lock() };
Expand All @@ -292,7 +292,7 @@ impl Pool {
}

#[cold]
pub fn free_cell(&self, cell: Address, space: &Lazy<&'static HoardSpace, Local>) {
pub fn free_cell(&self, cell: Address, space: &'static HoardSpace) {
let block = SuperBlock::containing(cell);
let mut owner = block.owner;
let mut blocks = owner.lock_blocks(block.size_class);
Expand All @@ -308,7 +308,7 @@ impl Pool {
fn free_cell_slow_impl(
&self,
cell: Address,
space: &Lazy<&'static HoardSpace, Local>,
space: &'static HoardSpace,
blocks: &mut BlockList,
) {
let block = SuperBlock::containing(cell);
Expand All @@ -331,7 +331,7 @@ impl Pool {
fn flush_block_slow(
&self,
size_class: SizeClass,
space: &Lazy<&'static HoardSpace, Local>,
space: &'static HoardSpace,
blocks: &mut BlockList,
) {
// Transit a mostly-empty block to the global pool
Expand Down
10 changes: 4 additions & 6 deletions mallockit/src/space/freelist_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,15 @@ impl Cell {
}

pub struct FreeListAllocator {
space: Lazy<&'static FreeListSpace, Local>,
freelist: Lazy<IntrusiveFreeList<AddressSpace>, Local>,
space: &'static FreeListSpace,
freelist: IntrusiveFreeList<AddressSpace>,
}

impl FreeListAllocator {
pub const fn new<const SPACE_ID: SpaceId>(space: Lazy<&'static FreeListSpace, Local>) -> Self {
pub fn new<const SPACE_ID: SpaceId>(space: &'static FreeListSpace) -> Self {
Self {
space,
freelist: Lazy::new(|| {
IntrusiveFreeList::new(false, HEAP.get_space_range(SPACE_ID).start)
}),
freelist: IntrusiveFreeList::new(false, HEAP.get_space_range(SPACE_ID).start),
}
}

Expand Down
4 changes: 2 additions & 2 deletions mallockit/src/space/immortal_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ impl Space for ImmortalSpace {
}

pub struct BumpAllocator {
space: Lazy<&'static ImmortalSpace, Local>,
space: &'static ImmortalSpace,
allocation_area: AllocationArea,
retry: bool,
}

impl BumpAllocator {
pub const fn new(space: Lazy<&'static ImmortalSpace, Local>) -> Self {
pub const fn new(space: &'static ImmortalSpace) -> Self {
Self {
space,
allocation_area: AllocationArea::EMPTY,
Expand Down
8 changes: 4 additions & 4 deletions mallockit/src/space/large_object_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::{
page_resource::{FreelistPageResource, PageResource},
Allocator, Space, SpaceId,
};
use crate::util::{Address, Lazy, Local, Page, PageSize, Size4K};
use crate::util::{Address, Page, PageSize, Size4K};

pub struct LargeObjectSpace {
id: SpaceId,
Expand Down Expand Up @@ -62,7 +62,7 @@ pub struct LargeObjectAllocator<
> where
[(); bins::<S>(MAX_CACHEABLE_SIZE)]: Sized,
{
space: Lazy<&'static LargeObjectSpace, Local>,
space: &'static LargeObjectSpace,
bins: [Address; bins::<S>(MAX_CACHEABLE_SIZE)],
max_live: usize,
live: usize,
Expand All @@ -77,7 +77,7 @@ where
{
const CACHE_ENABLED: bool = bins::<S>(MAX_CACHEABLE_SIZE) > 0;

pub const fn new(los: Lazy<&'static LargeObjectSpace, Local>) -> Self {
pub fn new(los: &'static LargeObjectSpace) -> Self {
Self {
space: los,
bins: [Address::ZERO; bins::<S>(MAX_CACHEABLE_SIZE)],
Expand All @@ -89,7 +89,7 @@ where
}

fn space(&self) -> &'static LargeObjectSpace {
*self.space
self.space
}

fn alloc_slow(&mut self, layout: Layout) -> Option<Address> {
Expand Down
2 changes: 1 addition & 1 deletion sanity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Mutator for SanityMutator {

fn new() -> Self {
Self {
los: LargeObjectAllocator::new(Lazy::new(|| &Self::plan().large_object_space)),
los: LargeObjectAllocator::new(&Self::plan().large_object_space),
}
}

Expand Down

0 comments on commit 576f804

Please sign in to comment.