Low Orbit Flux Logo 2 F

Linux - CPU Affinity and Isolation



lscpu -e   # view CPUs / Cores on system
nproc      # show number of cores

CPU affinity



taskset -p 1234       # show affinity for this process

Pin process to specific cores:



taskset -c <cpu_list> <command>

taskset -c 5 server.sh         # start proc pinned to one core
taskset -c 1,2,5-8 server.sh   # start proc with core list

taskset -c 5 -p 1234           # pin existing process

numactrl -C 0 server.sh        # run command pinned to numa node 0


nice -n -20 taskset -c 5 server.sh      # high priority, pinned to core


chrt  # another commadn to change real time scheduling prioritizes
cset  # More advanced tool designed for creating CPU sets and controlling the CPU affinity of entire groups of processes.

CPU Isolation

/etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="isolcpus=2,3 nohz_full=2,3 rcu_nocbs=2,3" GRUB_CMDLINE_LINUX_DEFAULT="quiet splash isolcpus=2,3 nohz_full=2,3 rcu_nocbs=2,3"

Update GRUB and reboot to apply changes:



sudo update-grub
sudo reboot