pub struct Vmalloc;
Expand description
The virtually contiguous kernel allocator.
Vmalloc
allocates pages from the page level allocator and maps them into the contiguous kernel
virtual space. It is typically used for large allocations. The memory allocated with this
allocator is not physically contiguous.
For more details see self.
Implementations§
Source§impl Vmalloc
impl Vmalloc
Sourcepub unsafe fn to_page<'a>(ptr: NonNull<u8>) -> BorrowedPage<'a>
pub unsafe fn to_page<'a>(ptr: NonNull<u8>) -> BorrowedPage<'a>
Convert a pointer to a Vmalloc
allocation to a page::BorrowedPage
.
§Examples
use kernel::alloc::allocator::Vmalloc;
let mut vbox = VBox::<[u8; page::PAGE_SIZE]>::new_uninit(GFP_KERNEL)?;
{
// SAFETY: By the type invariant of `Box` the inner pointer of `vbox` is non-null.
let ptr = unsafe { NonNull::new_unchecked(from_mut(&mut *vbox)) };
// SAFETY:
// `ptr` is a valid pointer to a `Vmalloc` allocation.
// `ptr` is valid for the entire lifetime of `page`.
let page = unsafe { Vmalloc::to_page(ptr.cast()) };
// SAFETY: There is no concurrent read or write to the same page.
unsafe { page.fill_zero_raw(0, page::PAGE_SIZE)? };
}
§Safety
ptr
must be a valid pointer to aVmalloc
allocation.ptr
must remain valid for the entire duration of'a
.
Trait Implementations§
Source§impl Allocator for Vmalloc
impl Allocator for Vmalloc
Source§const MIN_ALIGN: usize = 4_096usize
const MIN_ALIGN: usize = 4_096usize
The minimum alignment satisfied by all allocations from this allocator. Read more
Source§unsafe fn realloc(
ptr: Option<NonNull<u8>>,
layout: Layout,
old_layout: Layout,
flags: Flags,
nid: NumaNode,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn realloc( ptr: Option<NonNull<u8>>, layout: Layout, old_layout: Layout, flags: Flags, nid: NumaNode, ) -> Result<NonNull<[u8]>, AllocError>
Re-allocate an existing memory allocation to satisfy the requested
layout
and
a specific NUMA node request to allocate the memory for. Read moreAuto Trait Implementations§
impl Freeze for Vmalloc
impl RefUnwindSafe for Vmalloc
impl Send for Vmalloc
impl Sync for Vmalloc
impl Unpin for Vmalloc
impl UnwindSafe for Vmalloc
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> PinInit<T> for T
impl<T> PinInit<T> for T
Source§unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
Initializes
slot
. Read more