6

Is there a way to make all processes, except the ones I intentionally set otherwise with taskset or numactl use only certain cores/memory (without looping through every thread of every process and setting it myself)?

A few more details: I have 2 physical CPU chips, each with 4 cores / 8 threads along with a total of 256 GB RAM. The memory is not evenly distributed between the two CPU memory buses. I would like the one with significantly less memory to be the general-purpose one with most programs (e.g. background tasks) running on that CPU and with its memory. Then on the CPU with most of the memory run special tasks that I will be timing the speed of and want them to not have an CPU-contention, NUMA, or anything like that.

  • You may enclose your programs to virtual machines using KVM/libvirt, you may specify vCPU/cores mapping in the XML deffinition file. – Jaroslav Kucera Oct 4 '17 at 19:36
  • systemd? Or something else? Have you researched cgroups? – Outurnate Oct 4 '17 at 20:08
  • @JaroslavKucera this wouldn't limit the base system's processes to the given CPU, and the other set of processes is a small set. – thaimin Oct 4 '17 at 20:29
  • @outurnate I guess all of the processes would be started by systemd, but just setting its affinity/numa/cgroup wouldn't necessarily effect all of its children, even just setting the affinity of a process doesn't effect its threads. Unless there is a way to 'hook' systemd initialization to change it before it forks any processes. Also, wouldn't cgroups have the same issue in that every process would need to be added? – thaimin Oct 4 '17 at 20:29
  • child processes automatically belong to the parent cgroup. systemd also creates a hierarchy of cgroups for slices/scopes/service. Unfortunately, you can't set a cpuset for a slice. I've got answer - will type up – Outurnate Oct 4 '17 at 20:37
4

This can be achieved by modifying systemd config. First, change the default affinity settings in /etc/systemd/system.conf by adding:

[Manager]
CPUAffinity=1

Then, under you unit, clear the affinity, then reset it to your desired CPUs

[Exec]
CPUAffinity=
CPUAffinity=2-4
| improve this answer | |
  • Sorry for delay, but this does seem to work! Thanks! – thaimin Nov 2 '17 at 15:43
  • @thaimin glad to hear it! – Outurnate Nov 2 '17 at 19:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.