Search code examples
linuxmemorysystem-callsnumanumactl

set_mempolicy from a different process


For NUMA machines, Linux provides the set_mempolicy system call that allows a process to define its preferred NUMA node for memory allocations.

Is there some similar function that allows to change the memory policy of another running process? So something like this set_mempolicy(pid, ...) where pid corresponds to a different running process?

Note, that the other process (the one I want to change its memory policy) is already running and I have no control over it. So a solution like this:

set_mempolicy(...);
fork(); // now new process has the same memory policy

is not what I'm looking for.


Solution

    1. create a cpuset with mems containing the desired node(s), and memory_migrate containing 1
    2. write the process' PID into the cpuset's tasks file

    New allocations by the process will be fulfilled according to the cpuset's mems config, and existing pages will be migrated when the task is added to the set.

    NB. This feels like a serverfault Q/A really, but your can write your cpuset management in C if it makes you feel better.