pub struct MmapBacked { /* private fields */ }Expand description
OS-mapped anonymous region.
len is rounded up to a multiple of the page size at construction. The
Allocator impl serves requests bump-style from the mapping.
§Thread safety
Send: yes — the mapping is identified by (ptr, len), both Send-safe
values; we restore Send via an unsafe impl since NonNull<u8> is
!Send by default.
Sync: NO. The cursor uses UnsafeCell for &self allocation; concurrent
&self allocators would race. UnsafeCell is !Sync, which gives us the
right behavior without any extra marker field. Cross-thread allocation
belongs to higher layers (SharedBumpArena, SlabRemote).
Implementations§
Source§impl MmapBacked
impl MmapBacked
Sourcepub fn new(size: usize) -> Result<Self, AllocError>
pub fn new(size: usize) -> Result<Self, AllocError>
Allocate an anonymous OS-mapped region of at least size bytes (rounded
up to the page size).
Sourcepub fn with_huge_pages(size: usize) -> Result<Self, AllocError>
pub fn with_huge_pages(size: usize) -> Result<Self, AllocError>
Allocate with huge-pages requested. This layer ignores the hint;
HugePageAligned enforces 2 MiB / 32 MiB alignment.
Sourcepub fn new_lazy(size: usize) -> Result<Self, AllocError>
pub fn new_lazy(size: usize) -> Result<Self, AllocError>
Reserve an anonymous OS-mapped region of at least size bytes
without committing it up front (see MmapFlags::lazy_commit).
Windows-only effect. On Windows the region is MEM_RESERVE-only
and consumes no commit charge until FixedRange::commit commits
pages on demand; on Unix this is identical to new
because mmap is already demand-paged.
§Safety / usage contract
The returned region hands back reserved-but-uncommitted pages on
Windows. It is safe under BumpArena / StackAlloc
(true demand-commit), under any pass-through FixedRange wrapper over
those, and under Slab / SizeClassed / direct
Allocator::allocate (safe, but committed eagerly). It faults under
SharedBumpArena and GuardPage. See MmapFlags::lazy_commit for
the full contract.
Sourcepub fn with_flags(size: usize, flags: MmapFlags) -> Result<Self, AllocError>
pub fn with_flags(size: usize, flags: MmapFlags) -> Result<Self, AllocError>
Allocate with the supplied MmapFlags.
Trait Implementations§
Source§impl Allocator for MmapBacked
impl Allocator for MmapBacked
Source§fn allocate(&self, layout: NonZeroLayout) -> Result<NonNull<[u8]>, AllocError>
fn allocate(&self, layout: NonZeroLayout) -> Result<NonNull<[u8]>, AllocError>
layout. The returned slice’s length is
at least layout.size() but may be larger.Source§fn capacity_bytes(&self) -> Option<usize>
fn capacity_bytes(&self) -> Option<usize>
None for unbounded
allocators like System. Used by Watermark to compute thresholds.Source§fn allocate_zeroed(
&self,
layout: NonZeroLayout,
) -> Result<NonNull<[u8]>, AllocError>
fn allocate_zeroed( &self, layout: NonZeroLayout, ) -> Result<NonNull<[u8]>, AllocError>
Source§unsafe fn grow(
&self,
ptr: NonNull<u8>,
old: NonZeroLayout,
new: NonZeroLayout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow( &self, ptr: NonNull<u8>, old: NonZeroLayout, new: NonZeroLayout, ) -> Result<NonNull<[u8]>, AllocError>
Source§unsafe fn shrink(
&self,
ptr: NonNull<u8>,
old: NonZeroLayout,
new: NonZeroLayout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn shrink( &self, ptr: NonNull<u8>, old: NonZeroLayout, new: NonZeroLayout, ) -> Result<NonNull<[u8]>, AllocError>
Source§fn reset(&mut self) -> Result<(), AllocError>
fn reset(&mut self) -> Result<(), AllocError>
AllocError — only arena-style allocators implement a meaningful
reset. Read moreSource§unsafe fn usable_size(
&self,
_ptr: NonNull<u8>,
_layout: NonZeroLayout,
) -> Option<usize>
unsafe fn usable_size( &self, _ptr: NonNull<u8>, _layout: NonZeroLayout, ) -> Option<usize>
None — implementors that track usable size
override. Read moreSource§fn corruption_events(&self) -> u64
fn corruption_events(&self) -> u64
Source§impl Deallocator for MmapBacked
impl Deallocator for MmapBacked
Source§unsafe fn deallocate(&self, _ptr: NonNull<u8>, _layout: NonZeroLayout)
unsafe fn deallocate(&self, _ptr: NonNull<u8>, _layout: NonZeroLayout)
Source§impl Drop for MmapBacked
impl Drop for MmapBacked
Source§impl FixedRange for MmapBacked
impl FixedRange for MmapBacked
Source§impl OsBacked for MmapBacked
impl OsBacked for MmapBacked
Source§unsafe fn release_pages(&self, ptr: NonNull<u8>, size: usize)
unsafe fn release_pages(&self, ptr: NonNull<u8>, size: usize)
§Caveat (shared with commit)
On Windows this reads the committed high-water mark through &self
under the !Sync single-writer contract. Do NOT call release_pages
on a &MmapBacked that is shared while an allocator (or commit)
advances the watermark — that races the UnsafeCell, exactly as
commit’s own caveat warns.