Processor affinity
Processor affinity
Main page

Processor affinity

logo
Community Hub0 subscribers
What are your thoughts?
Be the first to start a discussion here.
Be the first to start a discussion here.
Processor affinity

In computer science, processor affinity, also called CPU pinning or cache affinity, enables the binding and unbinding of a process or a thread to a central processing unit (CPU) or a range of CPUs, so that the process or thread will execute only on the designated CPU or CPUs rather than any CPU. This can be viewed as a modification of the native central queue scheduling algorithm in a symmetric multiprocessing operating system. Each item in the queue has a tag indicating its kin processor. At the time of resource allocation, each task is allocated to its kin processor in preference to others.

Scheduling-algorithm implementations vary in adherence to processor affinity. Under certain circumstances, some implementations will allow a task to change to another processor if it results in higher efficiency. For example, when two processor-intensive tasks (A and B) have affinity to one processor while another processor remains unused, many schedulers will shift task B to the second processor in order to maximize processor use. Task B will then acquire affinity with the second processor, while task A will continue to have affinity with the original processor.[citation needed]

On most operating systems, the set of processors a process or thread is allowed (or preferred) to run on is expressed as an affinity mask, which is a bit mask corresponding to the system's cores.

There are several reasons for processor affinity to be used.

The execution of a thread may be interrupted by the OS scheduler to make space for other programs or threads during an interrupt. If the thread was later dispatched to the processor it was previously running on, there may be some remaining data in the CPU cache that can be reused, allowing for fewer cache misses. Setting the processor affinity would make sure the thread always runs on the same processor(s), but at the same time forces it to wait for the processor(s) to become available again. This feature is especially useful for CPU-intensive processes with few interrupts. Doing the same to an ordinary program might instead slow it down as they tend to be interrupted more frequently and end up waiting more. A practical example of processor affinity is executing multiple instances of a single-threaded application, such as some graphics-rendering software.[citation needed]

On CPUs with simultaneous multi-threading (SMT, also loosely known as hyper-threading, a genericized trademark of Intel), the two or more "threads" (logical processors, "virtual cores") on a physical core share the L1 and L2 caches. As far as affinity for locality purposes is concerned, they are identical.

On non-uniform memory access (NUMA) systems a similar problem exists, except the latency comes not from L1/L2 cache misses, but from L3 misses and cross-node memory access. Constraining all threads of a program to the same NUMA node (or at least the same CPU socket) would ensure they can share their L3 caches. Additional configuration may be necessary to ensure that memory is allocated from the local NUMA node.

Processor affinity also enforces a static division of processing resources. As a result, it can be used to limit the amount of CPU cores used by a CPU-intensive process, leaving other cores available for the other programs to use. This is, of course, not optimal, as it would leave resources completely unused when there are no other programs running as well as still allow other programs to compete with the CPU-intensive program for resources on the few cores it's allowed to run on. More advanced methods to divide resources include CPU priority settings, CPU utilization shares, and hard utilization percentage limits.

See all
User Avatar
No comments yet.