set_mempolicy - one sentence description of the event
set_mempolicy() is a system call that sets the policy of allocation of memory on NUMA machines. It sets the default memory policy for how threads in the current process interact with memory across different NUMA nodes. It is used mainly by two types of processes: runtime linker or dynamic loader to directly specify which memory policy should be used when loading the newly loaded shared objects, or NUMA-aware applications that create huge pages or allocate big objects and tune how their threads interact with different NUMA nodes.
There are two main drawbacks of using this system call. First, it does not check whether certain memory is located on a certain NUMA node, so there can be unnecessary cross-node migrations that might happen if set_mempolicy is used incorrectly. Second, it might have bad performance due to the different policies available being conflicting.
int[K] - sets the mode of the policy. Can be either MPOL_DEFAULT, MPOL_PREFERRED, MPOL_BIND, MPOL_INTERLEAVE, which sets the policy depending on the specified argument.
const unsigned long*[U,TOCTOU] - pointer to an array of unsigned long that contains the nodes to be used by the policy. The array will include up to maxnode unsigned longs.
unsigned long[K] - the maximum number of the nodes that can be used by the policy.
- K - Originated from kernel-space.
- U - Originated from user space (for example, pointer to user space memory used to get it)
- TOCTOU - Vulnerable to TOCTOU (time of check, time of use)
Hooking __do_sys_set_mempolicy allows us to capture all invocations of the set_mempolicy syscall.
Example Use Case¶
set_mempolicy is used in applications that allocate huge memory objects and need to be aware of the NUMA node the memory originates from. It is also used in runtime linkers and dynamic loaders in order to allocate shared objects on specific NUMA nodes.
set_mempolicy does not check whether certain memory is located on a certain NUMA node, so there can be unnecessary cross-node migrations that might happen if set_mempolicy is used incorrectly.
- set_numa_affinity - Used to set which NUMA nodes should be used for subsequent memory allocations.
- get_mempolicy - Used to get information about the memory policy of a process.
This document was automatically generated by OpenAI and needs review. It might not be accurate and might contain errors. The authors of Tracee recommend that the user reads the "events.go" source file to understand the events and their arguments better.