NUMA++ 0.12.0
Loading...
Searching...
No Matches
mempolicyExample2.cpp
Go to the documentation of this file.
1/**
2 * @file
3 * @copyright
4 * SPDX-FileCopyrightText: 2023-2023 European Southern Observatory (ESO)
5 *
6 * SPDX-License-Identifier: LGPL-3.0-only
7 */
8#include <iostream>
9#include <numapp/memory.hpp>
10#include <numapp/mempolicy.hpp>
11
12void BindMemoryRange(int node, void* address, std::size_t size) {
14 using numapp::operator|;
15 using numapp::LockFlag;
17
18 auto policy = MemPolicy::MakeBindNode(node);
19 auto flags = MemPolicyFlag::Move | MemPolicyFlag::Strict;
20
21 if (auto ec = numapp::Apply(address, size, policy, flags); ec) {
22 std::cerr << "Failed to apply policy: " << ec.message() << std::endl;
23 throw std::system_error(ec);
24 }
25
26 if (auto ec = numapp::MemLock(address, size, LockFlag::PreFault); ec) {
27 std::cerr << "Failed to apply policy: " << ec.message() << std::endl;
28 throw std::system_error(ec);
29 }
30}
Class representing a memory policy that can be modified and used to apply to the current thread or a ...
std::error_code Apply(pid_t thread, CpuAffinity const &affinity) noexcept
Apply policy to specified thread.
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:60
MemPolicyFlag
Flag that modify the behaviour of applying a memory policy to a range of memory.
Definition mempolicy.hpp:38
LockFlag
Mutually exclusive flags that modifies behaviour of MemLock().
Definition memory.hpp:121
Contains memory function declarations.
Contains declarations for numapp::MemPolicy.