|
NUMA++ 0.11.0
|
Describes a huge page size and maintains the invariant that page size is an integral power of 2, compatible with mmap() expectations.
More...
#include <memory.hpp>
Public Member Functions | |||||||||||||||||||||
| HugePageSize (HugePagePreset preset) noexcept | |||||||||||||||||||||
| Construct from preset page size value. | |||||||||||||||||||||
| HugePageSize (std::size_t bytes) | |||||||||||||||||||||
| Construct with given page size. | |||||||||||||||||||||
| auto | operator<=> (HugePageSize const &) const noexcept -> std::strong_ordering=default | ||||||||||||||||||||
| Three-way comparison operator. | |||||||||||||||||||||
Allocate and free huge pages | |||||||||||||||||||||
Allocation is similar to Allocate and free but with the additional argument specifying the (huge) page size. Like non-huge allocations the pages are not pre-faulted by the functions so to avoid page fault failurs it is recommended to do that before use. #include <numapp/memory.hpp>
void Example() {
// Allocate 16MiB from NUMA node 1 in 2MiB pages.
auto const size = 16 * 1024 * 1024;
// 1) AllocateHuge will allocate size, rounding up to nearest page_size
// multiple
void* ptr = numapp::AllocateHuge(size,
page_size,
numapp::MemPolicyFlag::Strict);
// 2) It is particularly important to pre-fault huge-pages as the likelihood
// for failure is higher. If page-fault would fail when memory is accessed
// the result is a segmentation fault.
// Page-fault failed; this would have caused a segmentation fault if not
// for `numapp::MemLock()`.
throw std::system_error(ec, "Page fault failed");
}
// 3) FreeHuge will free memory, rounding up to nearest page_size multiple
// as required by mmap.
numapp::FreeHuge(ptr, size, page_size);
}
static MemPolicy MakeBindNode(int node) Creates a strict policy (using MPOL_BIND) to allocate all memory to the specified node. void FreeHuge(void *ptr, std::size_t size, HugePageSize page_size, std::error_code &ec) noexcept Free huge pages previously allocated with AllocateHuge. Definition memory.cpp:205 void * AllocateHuge(std::size_t size, HugePageSize page_size, MemPolicy const &policy, MemPolicyFlag flags, std::error_code &ec) noexcept Non-throwing version of AllocateHuge() Definition memory.cpp:165 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 Contains memory function declarations.
| |||||||||||||||||||||
| constexpr auto | Size () const noexcept -> std::size_t | ||||||||||||||||||||
| Query size in bytes. | |||||||||||||||||||||
Describes a huge page size and maintains the invariant that page size is an integral power of 2, compatible with mmap() expectations.
Definition at line 534 of file memory.hpp.
|
noexcept |
Construct from preset page size value.
| preset | page size preset. |
Definition at line 145 of file memory.cpp.
|
explicit |
Construct with given page size.
Provided size bytes must an integer power of two and its base-2 logarithm must not be 0.
| bytes | Size in bytes. |
| std::invalid_argument | if bytes is not an integer power of two or its base-2 logarithm is 0. |
Definition at line 149 of file memory.cpp.
|
constexprnoexcept |
Query size in bytes.
Definition at line 728 of file memory.hpp.