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
- Bind a process to CPU cores.
Bind a process to CPU cores when you start it.
taskset -c {cpu_lists} processBind a running process to CPU cores.
taskset -cp {cpu_lists} PID
- 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=cpusBind 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.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot