Help Center/ Huawei Cloud EulerOS/ Best Practices/ Configuring CPU Affinity
Updated on 2026-07-29 GMT+08:00

Configuring CPU Affinity

Introduction

Process-to-core binding (also known as CPU affinity) is when you bind processes or threads to specific CPU cores. This way, a process can only be scheduled to specific cores and process locations can be controlled more precisely.

Preparations

Prepare an ECS.

Prerequisites

  • Application scenarios: Frequent cross-core migration, or cross-NUMA or cross-socket migration impacts performance.
  • Effects: Each process is bound to specific CPU cores to avoid cross-core, cross-NUMA, or cross-die migration.

Procedure

  1. Bind a process to CPU cores.

    Bind a process to CPU cores when you start it.

    taskset -c {cpu_lists} process

    Bind a running process to CPU cores.

    taskset -cp {cpu_lists} PID

  1. If NUMA is used, you can also use a numactl command to bind a process to CPU cores.

    Bind a process to CPU cores.

    numactl -C {cpu_list} process
    #-C cpus or --physcpubind=cpus

    Bind a process to NUMA nodes.

    numactl -N {numa_node_list} process
    # -N nodes or --cpunodebind=nodes

  • {cpu_list}: for example, 0, 1 to 13, or 16
  • {numa_node_list}: for example, 0, 0 and 2, or 0 to 2
  • To check the CPU affinity of a process, run taskset -cp {pid}.
  • Other numactl parameters:
    • -m {numa_node} binds memory. For example, -m 0 binds memory to numa0. -m 0,1 binds memory to numa0 and numa1. -m 0-2 binds memory to numa0, numa1, and numa2.
    • -i <nodes> controls interleaved memory allocation. For example, -i 0,1 configures memory to be interleaved across numa0 and numa1. -i all configures memory to be interleaved across all NUMA nodes.