CPU affinity
also: processor affinity, CPU pinning, taskset
CPU affinity is the ability to bind a process or thread to run exclusively on specific CPU cores, preventing the kernel scheduler from moving it to other cores.
CPU affinity allows you to control which processor cores a process uses. Instead of letting the kernel scheduler freely move a process between all available cores, you can restrict it to run on one or more specific cores.
This is useful for performance optimization in multi-core systems. For example, on a 4-core system, you might pin a latency-sensitive application to core 0, keeping other cores free for system tasks. You can set affinity with the taskset command: taskset -c 0,1 ./myapp binds myapp to cores 0 and 1.
CPU affinity also improves cache performance—a process staying on the same core keeps its data in the CPU's local cache rather than bouncing between cores and losing cache coherency.