|
NUMA++ 0.11.0
|
Utilities for allocating huge pages. More...
Classes | |
| class | numapp::HugePageSize |
Describes a huge page size and maintains the invariant that page size is an integral power of 2, compatible with mmap() expectations. More... | |
| class | numapp::HugePageResource |
| Polymorphic memory resource allocating huge pages with specified NUMA policy. More... | |
Enumerations | |
| enum class | numapp::HugePagePreset : std::size_t { numapp::HugePagePreset::Huge8k = 8 * 1024 , numapp::HugePagePreset::Huge16k = 16 * 1024 , numapp::HugePagePreset::Huge64k = 64 * 1024 , numapp::HugePagePreset::Huge256k = 256 * 1024 , numapp::HugePagePreset::Huge1M = 1 * 1024 * 1024 , numapp::HugePagePreset::Huge2M = 2 * 1024 * 1024 , numapp::HugePagePreset::Huge4M = 4 * 1024 * 1024 , numapp::HugePagePreset::Huge16M = 16 * 1024 * 1024 , numapp::HugePagePreset::Huge256M = 256 * 1024 * 1024 , numapp::HugePagePreset::Huge1G = 1ul * 1024 * 1024 * 1024 } |
| Preset huge page sizes. More... | |
Functions | |
| auto | numapp::EncodeMmapFlags (HugePageSize page_size) noexcept -> int |
Encodes page size into bit representation expected by mmap(). | |
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.
| |||||||||||||||||||||
| void * | numapp::AllocateHuge (std::size_t size, HugePageSize page_size, MemPolicy const &policy, MemPolicyFlag flags, std::error_code &ec) noexcept | ||||||||||||||||||||
| Non-throwing version of AllocateHuge() | |||||||||||||||||||||
| void * | numapp::AllocateHuge (std::size_t size, HugePageSize page_size, MemPolicy const &policy, MemPolicyFlag flags) | ||||||||||||||||||||
| Throwing version of AllocateHuge() | |||||||||||||||||||||
| void | numapp::FreeHuge (void *ptr, std::size_t size, HugePageSize page_size, std::error_code &ec) noexcept | ||||||||||||||||||||
| Free huge pages previously allocated with AllocateHuge. | |||||||||||||||||||||
| void * | AllocateHuge (std::size_t size, HugePageSize page_size, MemPolicy const &policy, MemPolicyFlag flags, std::error_code &ec) noexcept | ||||||||||||||||||||
| Non-throwing version of AllocateHuge() | |||||||||||||||||||||
| void * | AllocateHuge (std::size_t size, HugePageSize page_size, MemPolicy const &policy, MemPolicyFlag flags) | ||||||||||||||||||||
| Throwing version of AllocateHuge() | |||||||||||||||||||||
| void | numapp::FreeHuge (void *ptr, std::size_t size, HugePageSize page_size) | ||||||||||||||||||||
Throwing version of FreeHuge(). | |||||||||||||||||||||
Utilities for allocating huge pages.
|
strong |
Preset huge page sizes.
Commonly supported sizes are
Definition at line 476 of file memory.hpp.
|
nodiscard |
Throwing version of AllocateHuge()
See Allocate and free huge pages for details.
Definition at line 193 of file memory.cpp.
|
nodiscardnoexcept |
Non-throwing version of AllocateHuge()
See Allocate and free huge pages for details.
Definition at line 165 of file memory.cpp.
|
Throwing version of AllocateHuge()
See Allocate and free huge pages for details.
Definition at line 193 of file memory.cpp.
|
Non-throwing version of AllocateHuge()
See Allocate and free huge pages for details.
Definition at line 165 of file memory.cpp.
|
noexcept |
Encodes page size into bit representation expected by mmap().
mmap() flags.Definition at line 160 of file memory.cpp.
| void numapp::FreeHuge | ( | void * | ptr, |
| std::size_t | size, | ||
| HugePageSize | page_size ) |
Throwing version of FreeHuge().
See Allocate and free huge pages for details.
| std::system_error | on errors. |
Definition at line 215 of file memory.cpp.
|
noexcept |
Free huge pages previously allocated with AllocateHuge.
See Allocate and free huge pages for details.
Definition at line 205 of file memory.cpp.