15std::error_code
Apply(MemPolicy
const& policy)
noexcept {
16 if (
auto err =
ll::SetMemPolicy(
static_cast<int>(policy.GetMode()), policy.GetNodemask());
24std::error_code
ApplyStack(MemPolicy
const& policy, MemPolicyFlag flags)
noexcept {
26 void* stack_addr =
nullptr;
27 std::size_t stack_size = 0;
28 if (
auto err = pthread_getattr_np(pthread_self(), &attr); err != 0) {
29 return std::make_error_code(
static_cast<std::errc
>(err));
31 if (
auto err = pthread_attr_getstack(&attr, &stack_addr, &stack_size); err != 0) {
32 return std::make_error_code(
static_cast<std::errc
>(err));
34 return ::numapp::Apply(stack_addr, stack_size, policy, flags);
39std::error_code
Apply(
void* address,
42 MemPolicyFlag flags) NUMAPP_NOEXCEPT {
45 static_cast<int>(policy.GetMode()),
47 static_cast<std::underlying_type<MemPolicyFlag>::type
>(flags));
51 auto node_mask = Nodemask();
53 (void)numa_bitmask_setbit(node_mask.GetNative(), node);
55 if (!numa_bitmask_isbitset(node_mask.GetNative(), node)) {
56 throw std::system_error(std::make_error_code(std::errc::invalid_argument));
66 throw std::system_error(err);
75 throw std::system_error(err);
87std::ostream& operator<<(std::ostream& os,
MemPolicy::Mode const& mode) {
105std::ostream& operator<<(std::ostream& os,
MemPolicy const& mempolicy) {
106 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.