rlib
Convenience library for useful things
Loading...
Searching...
No Matches
rmemnuma.h File Reference

NUMA placement for whole-page allocations. More...

#include <rlib/rtypes.h>
#include <rlib/data/rbitset.h>

Go to the source code of this file.

Functions

rboolean r_mem_numa_available (void)
 Whether this build and this machine actually place allocations on the node they are asked for.
 
rsize r_mem_numa_page_size (void)
 Granularity every allocation here is rounded up to.
 
rpointer r_mem_numa_alloc_local (rsize size)
 Allocate size bytes placed by the system's default policy.
 
rpointer r_mem_numa_alloc_onnode (rsize size, ruint node)
 Allocate size bytes bound to NUMA node node.
 
rpointer r_mem_numa_alloc_interleaved (rsize size, const RBitset *nodeset)
 Allocate size bytes spread page-by-page across nodeset.
 
void r_mem_numa_free (rpointer ptr, rsize size)
 Release an allocation from this API.
 
rboolean r_mem_numa_bind (rpointer ptr, rsize size, ruint node)
 Bind the pages spanning ptr to node node.
 
rboolean r_mem_numa_interleave (rpointer ptr, rsize size, const RBitset *nodeset)
 Interleave the pages spanning ptr across nodeset.
 
rboolean r_mem_numa_node_of (rconstpointer ptr, ruint *node)
 Which node currently backs the page containing ptr.
 

Detailed Description

NUMA placement for whole-page allocations.

Where a large buffer lands decides how fast the threads touching it run, so these place it deliberately - bound to one node, or spread across several to share their combined bandwidth - instead of leaving it to the system's default policy.

Whole pages straight from the OS, deliberately outside the RMemVTable the r_malloc family routes through: placement is a property of the mapping, so an allocator backend has no say in it. Use this for buffers worth a mapping of their own. Release them with r_mem_numa_free and never with r_free.

Where placement is not enforced (see r_mem_numa_available) the allocators still return usable memory, just wherever the system would have put it. Node indices are the ones r_sys_topology_node_id reports, so the topology in rlib/os/rsys.h and the allocations here agree on what "node 2" means.