DEV Community

Izanagi
Izanagi

Posted on

CPU affinity for games: pinning processes to cores

CPU affinity lets you control which processor cores a process can run on. For gaming, strategic core assignment can reduce interference between game threads and background processes.

How affinity works

Windows bitmask: core 0 = bit 0, core 1 = bit 1, etc. Setting affinity to 0xFFFFFFF0 (for example) excludes cores 0-3 from the process and runs it on cores 4+.

The gaming use case

If you have 8+ cores, you can dedicate specific cores to your game and route background processes away from them:

  1. Pin your game to cores 2-7 (leave 0-1 for OS/background)
  2. Pin background processes (browser, Discord) to cores 0-1
  3. Game gets exclusive access to the majority of cores

Setting affinity permanently (via PowerShell)

Windows doesn't have a built-in way to set affinity permanently. Workarounds:

# Set affinity for a running process
$proc = Get-Process -Name "cs2"
$proc.ProcessorAffinity = 0xFFFC  # all cores except 0-1
Enter fullscreen mode Exit fullscreen mode

For permanent assignment, create a wrapper script that launches the game and immediately sets affinity.

Hybrid CPU note

On Intel 12th+ gen with P-cores and E-cores: pin games to P-cores only. E-cores are designed for background tasks.

Use HeterogeneousSchedulingPolicy=4 (Windows handles P/E core routing automatically) as an alternative to manual affinity.

When not to bother

On systems with 4 or fewer cores, restricting affinity can hurt performance. More beneficial on 8+ core systems.

IzanagiOP handles P/E core scheduling policy and IFEO priority without requiring manual affinity management. https://terweb.lt/

Top comments (0)