18std::error_code
Apply(MemPolicy
const& policy)
noexcept {
19 if (
auto err =
ll::SetMemPolicy(
static_cast<int>(policy.GetMode()), policy.GetNodemask());
27std::error_code
ApplyStack(MemPolicy
const& policy, MemPolicyFlag flags)
noexcept {
29 void* stack_addr =
nullptr;
30 std::size_t stack_size = 0;
31 if (
auto err = pthread_getattr_np(pthread_self(), &attr); err != 0) {
32 return std::make_error_code(
static_cast<std::errc
>(err));
34 if (
auto err = pthread_attr_getstack(&attr, &stack_addr, &stack_size); err != 0) {
35 return std::make_error_code(
static_cast<std::errc
>(err));
37 return ::numapp::Apply(stack_addr, stack_size, policy, flags);
42std::error_code
Apply(
void* address,
45 MemPolicyFlag flags) NUMAPP_NOEXCEPT {
48 static_cast<int>(policy.GetMode()),
50 static_cast<std::underlying_type<MemPolicyFlag>::type
>(flags));
54 auto node_mask = Nodemask();
56 (void)numa_bitmask_setbit(node_mask.GetNative(), node);
58 if (!numa_bitmask_isbitset(node_mask.GetNative(), node)) {
59 throw std::system_error(std::make_error_code(std::errc::invalid_argument));
69 throw std::system_error(err);
78 throw std::system_error(err);
90std::ostream& operator<<(std::ostream& os,
MemPolicy::Mode const& mode) {
108std::ostream& operator<<(std::ostream& os,
MemPolicy const& mempolicy) {
109 os <<
"MemPolicy {mode=" << mempolicy.GetMode() <<
", mask=" << mempolicy.GetNodemask() <<
"}";
Class representing a memory policy that can be modified and used to apply to the current thread or a ...
Mode
Memory allocation modes.
@ Bind
The Bind mode defines a strict policy that restricts memory allocation to the nodes specified in node...
@ Default
The Default mode specifies that any nondefault process memory policy be removed, so that the memory p...
@ Preferred
Preferred sets the preferred node for allocation.
@ Interleave
Interleave interleaves page allocations across the nodes specified in nodemask in numeric node ID ord...
MemPolicy(Mode mode, Nodemask &&node_mask) noexcept
Create memory policy.
static MemPolicy MakeFromActive()
Make from active default policy of calling thread.
static MemPolicy MakeFromAddress(void *address)
Make from policy at address.
static MemPolicy MakeBindNode(int node)
Creates a strict policy (using MPOL_BIND) to allocate all memory to the specified node.
std::error_code Restore() noexcept
Restores memory policy that was read during construction.
std::error_code Apply(CpuAffinity const &affinity) noexcept
Apply policy to calling thread.
std::error_code Apply(pid_t thread, CpuAffinity const &affinity) noexcept
Apply policy to specified thread.
std::error_code ApplyStack(MemPolicy const &policy, MemPolicyFlag flags=MemPolicyFlag::Move|MemPolicyFlag::Strict) noexcept
Convenience function that applies a memory policy to current thread stack memory.
Contains low-level functions.
Contains declarations for numapp::MemPolicy.
std::error_code SetMemPolicy(int mode, Nodemask const &mask) noexcept
Set active memory policy for calling thread.
std::error_code GetMemPolicy(int &mode, Nodemask &mask, void *addr, unsigned flags) noexcept
Get memory policy for calling thread or an address.