Some applications may require a dedicated core (and/or socket etc) to run optimally. We can achieve this by first
- Setting PID 1 (systemd) affinity mask to 1, so that any child processes run only on this core
- Manually starting new processes (which require their own core) on a spare core, overriding the affinity mask
Querying the current values
Some ways of demonstrating the current affinity mask:
hex formatted mask:
$ taskset -p 1
pid 1's current affinity mask: 1
list of CPUs:
$ taskset -p -c 1
pid 1's current affinity list: 0
or
$ grep "Cpus_allowed_list" /proc/1/status
Cpus_allowed_list: 0
These all show the current values
Setting the default values
in /etc/systemd/system.conf
, add this to the file (in the below example, to allow children of PID 1 - systemd, to be allocated to CPUs 0 - 9)
CPUAffinity=0 1 2 3 4 5 6 7 8 9
then
$ systemctl daemon-reexec (kill and restart the daemon)
$ grep Cpus_allowed_list /proc/1/status
Cpus_allowed_list: 0-9
$ taskset -p 1
pid 1's current affinity mask: 3ff
$ taskset -p -c 1
pid 1's current affinity list: 0-9
Starting a process on a specific core
$ taskset -c 5 my_server
Moving an existing process to a specific core
$ ps -fu robbie | grep my_other_server
PID TTY TIME CMD
3345 ? 00:00:00 my_other_server
$ taskset -c 7 -p 3345