pub struct NumaBuffer { /* private fields */ }Expand description
An owned buffer allocated with VirtualAllocExNuma, freed with
VirtualFree on drop.
The allocation is page-granular: VirtualAllocExNuma rounds a request up
to the system page size, so a caller asking for a small buffer gets at
least a page. NumaBuffer::len reports the length that was requested,
which is the length a kernel call should be told about.
§Buffer traits
This type implements io-buffers’ IoBuf and IoBufMut, so a ring takes it
as a buffer. This crate defines no trait of its own: the traits belong to
io-buffers, which is portable and so cannot depend on this allocator, and
the orphan rule lets only the crate that owns the trait or the type
implement it. A crate that owns a buffer trait of its own implements it for
this type the same way, over NumaBuffer::as_ptr,
NumaBuffer::as_mut_ptr and NumaBuffer::len.
Implementations§
Source§impl NumaBuffer
impl NumaBuffer
Sourcepub fn new(len: usize, node: Option<NumaNode>) -> Result<NumaBuffer, Error>
pub fn new(len: usize, node: Option<NumaNode>) -> Result<NumaBuffer, Error>
Allocate len bytes, preferring node if given.
Passing None requests no NUMA preference, which is the same choice
the default allocator makes implicitly.
§What a successful return does and does not mean
A valid node is a preference, not an instruction – nndPreferred
says so in its name – so success means the request was accepted and
memory was obtained, never that the pages came from the node asked for.
An invalid node is a different matter and is genuinely refused: this
crate’s tests assert that u32::MAX - 1 fails. Note that u32::MAX
itself is not a test of that, because it is the API’s own
no-preference sentinel and is accepted by design – a measurement that
reads it as an out-of-range node being tolerated has measured the
sentinel instead.
§Errors
The error from VirtualAllocExNuma, which includes a len of zero and
a node number the machine does not have.
Sourcepub fn as_mut_ptr(&mut self) -> *mut u8
pub fn as_mut_ptr(&mut self) -> *mut u8
The allocation’s base address for writing.
Takes &mut self because this value uniquely owns the allocation, so
exclusive access to the value is exclusive access to the bytes.
Trait Implementations§
Source§impl Debug for NumaBuffer
impl Debug for NumaBuffer
Source§impl Drop for NumaBuffer
impl Drop for NumaBuffer
Source§impl IoBuf for NumaBuffer
impl IoBuf for NumaBuffer
Source§fn stable_ptr(&self) -> *const u8
fn stable_ptr(&self) -> *const u8
Source§fn bytes_len(&self) -> usize
fn bytes_len(&self) -> usize
IoBuf::stable_ptr may be read.Source§impl IoBufMut for NumaBuffer
impl IoBufMut for NumaBuffer
Source§fn stable_mut_ptr(&mut self) -> *mut u8
fn stable_mut_ptr(&mut self) -> *mut u8
IoBuf::stable_ptr and must not change for the value’s life.