|
NUMA++ 0.11.0
|
NUMA++ memory policy APIs. More...
Topics | |
| Huge Pages | |
| Utilities for allocating huge pages. | |
Files | |
| file | memory.hpp |
| Contains memory function declarations. | |
| file | mempolicy.hpp |
| Contains declarations for numapp::MemPolicy. | |
| file | memory.cpp |
| Definition of memory functions from <numapp/memory.hpp> | |
Classes | |
| class | numapp::PageResource |
| Polymorphic memory resource allocating full system pages with specified NUMA policy. More... | |
| class | numapp::LockResource |
| Lock memory allocated from upstream memory resource using specified LockFlag. More... | |
| class | numapp::MemPolicy |
| Class representing a memory policy that can be modified and used to apply to the current thread or a memory range. More... | |
| class | numapp::ScopedMemPolicy |
| Applies memory policy to this thread at construction and reverts to previous at destruction. More... | |
Enumerations | |
| enum class | numapp::MemPolicyFlag : unsigned |
| Flag that modify the behaviour of applying a memory policy to a range of memory. | |
Memory Locking | |
These functions provide the means to prevent memory from being paged to the swap area.
Locking may require additional permissions if it exceeds resource limits (- See also page section Memory Locking. | |
| enum class | numapp::LockFlag : unsigned int { numapp::LockFlag::PreFault = 0u , numapp::LockFlag::OnFault = MLOCK_ONFAULT } |
| Mutually exclusive flags that modifies behaviour of MemLock(). More... | |
| enum class | numapp::LockAllFlag : int { numapp::LockAllFlag::Current = MCL_CURRENT , numapp::LockAllFlag::Future = MCL_FUTURE , numapp::LockAllFlag::OnFault = MCL_ONFAULT } |
| Flags that are combined to modify behaviour of MemLockAll(). More... | |
| std::error_code | numapp::MemLock (void const *addr, std::size_t len, LockFlag flag) noexcept |
| Lock memory pages in the specified address range. | |
| std::error_code | numapp::MemUnlock (void const *addr, std::size_t len) noexcept |
| Unlock memory pages in the specified address range. | |
| std::error_code | numapp::MemLockAll (LockAllFlag flags) noexcept |
| Lock all memory pages as specified by provided flags. | |
| std::error_code | numapp::MemUnlockAll () noexcept |
| Unlock all locked memory in this process. | |
Hardware Queries | |
Query host system/hardware. | |
| std::size_t | numapp::GetPageSize () noexcept |
| Fast query of system page size. | |
| int | numapp::GetNumNodes () noexcept |
| Query number of configured NUMA nodes. | |
| std::optional< int > | numapp::GetNodeDistance (int node1, int node2) noexcept |
| Get NUMA distance between two nodes. | |
| std::optional< int > | numapp::GetNodeOfCpu (int cpu) noexcept |
| Get NUMA node of the given CPU. | |
Allocate and free memory with specified memory policy | ||||||||||||||||||
(1) Overloads without
Example allocating with bind policy and then lock and pre-fault the newly allocated memory: #include <numapp/memory.hpp>
#include <numapp/mempolicy.hpp>
void* BindAlloc(std::size_t size, int node, std::error_code& ec) {
using namespace numapp;
MemPolicy policy = MemPolicy::MakeBindNode(node);
void* ptr = Allocate(size, policy, MemPolicyFlag::Strict, ec);
if (ec) {
return nullptr;
}
ec = MemLock(ptr, size, LockFlag::PreFault);
if (ec) {
return nullptr;
}
return ptr;
}
Class representing a memory policy that can be modified and used to apply to the current thread or a ... Definition mempolicy.hpp:174 static MemPolicy MakeBindNode(int node) Creates a strict policy (using MPOL_BIND) to allocate all memory to the specified node. std::error_code MemLock(void const *addr, std::size_t len, LockFlag flag) noexcept Lock memory pages in the specified address range. Definition memory.cpp:58 void * Allocate(std::size_t size, MemPolicy const &policy, std::error_code &ec) noexcept See group for details. Definition memory.cpp:87 Contains memory function declarations. Contains declarations for numapp::MemPolicy. Definition bitmask.cpp:11 | ||||||||||||||||||
| void * | numapp::Allocate (std::size_t size, MemPolicy const &policy, std::error_code &ec) noexcept | |||||||||||||||||
| See group for details. | ||||||||||||||||||
| void * | numapp::Allocate (std::size_t size, MemPolicy const &policy, MemPolicyFlag flags, std::error_code &ec) noexcept | |||||||||||||||||
| See group for details. | ||||||||||||||||||
| void * | numapp::Allocate (std::size_t size, MemPolicy const &policy) | |||||||||||||||||
| See group for details. | ||||||||||||||||||
| void * | numapp::Allocate (std::size_t size, MemPolicy const &policy, MemPolicyFlag flags) | |||||||||||||||||
| See group for details. | ||||||||||||||||||
| void | numapp::Free (void *ptr, std::size_t size, std::error_code &ec) noexcept | |||||||||||||||||
| See group for details. | ||||||||||||||||||
| void | numapp::Free (void *ptr, std::size_t size) | |||||||||||||||||
| See group for details. | ||||||||||||||||||
| void * | Allocate (std::size_t size, MemPolicy const &policy, std::error_code &ec) noexcept | |||||||||||||||||
| See group for details. | ||||||||||||||||||
| void * | Allocate (std::size_t size, MemPolicy const &policy, MemPolicyFlag flags, std::error_code &ec) noexcept | |||||||||||||||||
| See group for details. | ||||||||||||||||||
| void * | Allocate (std::size_t size, MemPolicy const &policy) | |||||||||||||||||
| See group for details. | ||||||||||||||||||
| void * | Allocate (std::size_t size, MemPolicy const &policy, MemPolicyFlag flags) | |||||||||||||||||
| See group for details. | ||||||||||||||||||
| void | Free (void *ptr, std::size_t size, std::error_code &ec) noexcept | |||||||||||||||||
| See group for details. | ||||||||||||||||||
| void | Free (void *ptr, std::size_t size) | |||||||||||||||||
| See group for details. | ||||||||||||||||||
Apply Memory Policy to Current Thread | |
Applies default memory policy to calling thread or to thread stack memory. | |
| std::error_code | numapp::thisThread::Apply (MemPolicy const &policy) noexcept |
| Applies the default memory policy to the calling thread. | |
| std::error_code | numapp::thisThread::ApplyStack (MemPolicy const &policy, MemPolicyFlag flags=MemPolicyFlag::Move|MemPolicyFlag::Strict) noexcept |
| Convenience function that applies a memory policy to current thread stack memory. | |
| std::error_code | Apply (MemPolicy const &policy) noexcept |
| Applies the default memory policy to the calling thread. | |
NUMA++ memory policy APIs.
See Memory Policy for an overview.
|
strong |
Flags that are combined to modify behaviour of MemLockAll().
LockAllFlag have the following operators defined in namespace numapp:
operator|(LockAllFlag, LockAllFlag)operator=|(LockAllFlag&, LockAllFlag)operator&(LockAllFlag, LockAllFlag)operator=&(LockAllFlag&, LockAllFlag) Definition at line 146 of file memory.hpp.
|
strong |
Mutually exclusive flags that modifies behaviour of MemLock().
Definition at line 119 of file memory.hpp.
|
Applies the default memory policy to the calling thread.
| policy | memory policy to set. |
|
nodiscardnoexcept |
Applies the default memory policy to the calling thread.
| policy | memory policy to set. |
|
nodiscardnoexcept |
Convenience function that applies a memory policy to current thread stack memory.
| policy | Memory policy to apply. |
| flags | combination of MemPolicyFlag values that modify the behaviour. Default is to move pages and fail if this cannot be done. |
|
nodiscardnoexcept |
Get NUMA distance between two nodes.
A node has distance 10 to itself.
| node1 | NUMA node number. |
| node2 | NUMA node number. |
std::nullopt when distance cannot be determined.numa(3) (numa_distance) Definition at line 48 of file memory.cpp.
|
nodiscardnoexcept |
Get NUMA node of the given CPU.
| cpu | CPU to get the NUMA node for. |
std::nullopt if cpu is invalid.numa(3) (numa_node_of_cpu) Definition at line 53 of file memory.cpp.
|
nodiscardnoexcept |
Query number of configured NUMA nodes.
numa(3) (numa_num_configured_nodes) Definition at line 44 of file memory.cpp.
|
nodiscardnoexcept |
Fast query of system page size.
numa(3) (numa_pagesize) Definition at line 40 of file memory.cpp.
|
nodiscardnoexcept |
Lock memory pages in the specified address range.
To unlock memory use numapp::MemUnlock or numapp::MemUnlockAll.
| addr | Defines the starting address of the range. |
| len | Defines the length of the address range. |
| flag | Behaviour modifier, see LockFlag. |
Definition at line 58 of file memory.cpp.
|
nodiscardnoexcept |
Lock all memory pages as specified by provided flags.
As an example this is how to lock current and future memory allocations:
To unlock memory use MemUnlock and MemUnlockAll.
LockAllFlag::Future is used memory pages will be locked during mapping using the calling thread default memory policy. For numapp::Allocate() this means that pages may have to be moved after mapping (see also notes in numapp::Allocate()).| flags | Combination of LockAllFlag values. See documentation of LockAllFlag how it modifies the behaviour. |
Definition at line 72 of file memory.cpp.
|
nodiscardnoexcept |
Unlock memory pages in the specified address range.
| addr | Defines the starting address of the range. |
| len | Defines the length of the address range. |
Definition at line 65 of file memory.cpp.
|
nodiscardnoexcept |
Unlock all locked memory in this process.
Definition at line 79 of file memory.cpp.