Search

A technology, a device or an article

Pinning a program to a CPU does not give it ownership of a core

Thread affinity defines permitted CPUs. Exclusive access, SMT topology and time quotas remain separate parts of the execution conditions.

Ochre arches and overlapping light with a small silhouette
AI-generated conceptual illustration. A metaphor for access without exclusive resource ownership.ITNWS · Original ITNWS AI-generated conceptual editorial illustration

“Give the process a core.” The phrase sounds wonderfully complete. A program is slow, the machine has several processors, and an affinity setting appears to settle the matter. Unfortunately, the setting normally says where a thread may run. It does not, by itself, say who else may run there. Permission to use a resource and ownership of that resource are different promises. Confusing them can turn a sensible restriction into a fictitious reservation, leaving the operator surprised when a pinned program still encounters competition.

The Linux sched_setaffinity interface describes an affinity mask for a thread. The mask restricts eligible CPUs. It does not create a private physical core, change the number of execution resources, or remove every source of interference. Setting a mask can therefore be useful without fulfilling the stronger statement that motivated it. A report saying only “the application was pinned” leaves unresolved whether the application had all the threads its author expected, whether those threads shared a mask, and what unrelated work remained eligible for the same CPUs.

A thread is the important unit here. An application with several threads is not automatically described by one number copied from its main thread. Linux’s interface is per thread, and applications can create threads or change their behavior later. Thread creation also introduces inheritance rules that need to be understood rather than guessed. A tool may offer a convenient process-oriented presentation, but the underlying scheduling choices concern individual runnable entities. A valid measurement should identify the actual workload, not assume that every participant acquired the intended placement because the original launcher did.

There is also a difference between a requested mask and the CPUs actually available. The kernel can intersect a request with present CPUs and with restrictions imposed elsewhere. The resulting execution set may be narrower than the person who typed the mask intended. Reading back the effective state matters for that reason. It is possible to make an apparently precise declaration about CPU numbers while describing a set that the workload cannot actually use. The meaningful condition is the set permitted by the complete arrangement, including the restrictions inherited from its environment.

A fence around the guest is not a fence around everyone else

Consider an invented machine whose logical CPUs are numbered from 0 through 7. A thread is restricted to CPU 3. That excludes the thread from CPUs 0, 1, 2, 4, 5, 6, and 7, but says nothing about excluding other threads from CPU 3. Another ordinary task can remain eligible there. The arithmetic of one selected identifier does not imply one isolated execution resource. This example describes no real processor topology. Its purpose is to expose the direction of the restriction: the mask fences in this thread rather than fencing out all competing work.

If the pinned thread blocks for input, the scheduler may run something else on that CPU. When the thread becomes runnable again, it competes according to the applicable scheduling arrangements. Affinity has not promised immediate dispatch. Nor has it promised that the thread will remain runnable continuously. A workload may wait for locks, data, or other threads even on an otherwise quiet CPU. Explaining its elapsed time therefore requires more than a placement statement. The placement restricts possible locations; it does not manufacture ready work or overrule the scheduler’s remaining responsibilities.

The cgroup v2 documentation adds another vocabulary through the cpuset controller. A hierarchy can constrain the CPUs available to a group of processes, with effective values reflecting the actual permitted set. These restrictions compose with other conditions. They are not simply another spelling for a frequency governor or a CPU-time quota. A group can be eligible for several CPUs while its usable time is limited elsewhere; a group with no special quota can still face ordinary competition. Location, quantity of CPU time, and scheduling treatment remain separate aspects of execution.

The configured list and the effective list can differ for an ordinary reason such as CPU availability. The cpuset documentation explicitly provides effective attributes rather than asking observers to reconstruct the permitted set from a configuration string alone. Hierarchical restrictions can further narrow the result, and an empty configured value has an inheritance meaning within the documented interface. That is why comparing launcher arguments is weaker than comparing the state in which the threads actually ran. It also explains a diagnostic trap: a changed effective set need not mean the application secretly edited its own affinity. The surrounding hierarchy and available CPUs are part of the placement condition. A report describing a stable intended mask should separately establish whether the effective set remained stable during the observed work.

The word exclusive appears in more specialized cpuset mechanisms, which is precisely why it should not be attached casually to a plain affinity mask. Partition and exclusivity rules have documented prerequisites and parent-child relationships. They require a valid arrangement of sets rather than a single optimistic property on a process. This article does not configure such a partition or claim that one command provides isolation on every kernel. The important distinction is conceptual: a facility designed to divide CPU eligibility across groups must consider the surrounding hierarchy, while ordinary affinity alone describes the placement restriction of the selected thread.

Teaching masks: one task is restricted to CPU 3 while another may also use it.
Teaching masks: one task is restricted to CPU 3 while another may also use it. — ITNWS · Original ITNWS educational diagram

Even a carefully divided set of logical CPUs does not automatically divide physical cores. On a machine with simultaneous multithreading, separate logical CPU identifiers may share execution resources within one core. Reserving one identifier while leaving its sibling available to another workload can preserve an important source of competition. The actual sibling relationship must come from the machine’s topology, not from a belief that adjacent numbers always belong together. Numbering is an enumeration. It is not a portable diagram of physical sharing, and it does not imply a universal mapping between every pair of identifiers.

This is not a reason to dismiss affinity. Restricting migration can change cache behavior, placement predictability, and the relationship between work and memory. Those are legitimate experimental subjects. But the direction and size of the result depend on the workload and system. A restrictive mask can also deny the scheduler useful choices when another permitted location would have been less busy. The setting is a change to the scheduling problem, not a certificate of improvement. Calling it pinning makes the location sound physically fixed; the outcome still depends on what happens at that location and what work must happen elsewhere.

Interrupts and kernel activity complicate stronger promises further. Not all work affecting a CPU is represented by an unrelated application thread that an operator can conveniently move with the same tool. Handling an interrupt, servicing a kernel path, or coordinating shared machine resources can consume time or disturb an otherwise tidy arrangement. Different facilities govern different parts of this behavior. A statement of complete isolation needs to explain its scope. If the evidence establishes only that ordinary application threads use separate eligible sets, it should not be promoted into a claim that nothing else can ever affect execution on the chosen core.

The distinction becomes visible in an experiment that records inconsistent response times after pinning. The inconsistency is not proof that affinity was ignored. The thread may have run exclusively on an eligible CPU while experiencing different competing work, different readiness, or different access to data. A placement trace and an application timeline answer related but different questions. First establish whether the restriction took effect. Then ask what remains free to vary inside the permitted environment. Treating every unexplained delay as a failure of the affinity interface prevents that second, more useful question from being asked.

A CPU-time quota offers a particularly clear counterexample to the ownership metaphor. A task may be allowed to execute on a selected CPU but still run out of the group’s permitted CPU time within an accounting period. Moving it to another allowed identifier does not necessarily remove that group limit. The earlier ITNWS discussion of CPU quotas examined this temporal restriction. Here the issue is spatial eligibility. Combining the two descriptions explains why a task can be pinned correctly and throttled correctly at the same time. There is no contradiction, because neither condition promises what the other one controls.

NUMA introduces a related separation between CPU placement and memory placement. Choosing where a thread may execute does not retroactively establish where all its pages were allocated. Existing data may remain associated with another memory locality under the system’s actual policies. Whether that matters depends on the workload and topology. This observation does not turn the article into a NUMA tuning recipe. It shows why “a core for the application” is an incomplete account of the resources needed to execute the application. The selected CPU reaches data and shared structures whose placement follows additional rules.

An honest comparison can state a narrower and stronger fact: the measured threads were restricted to a documented effective set, the topology of that set was known, and the surrounding competition was described. This does not require claiming that every source of disturbance was eliminated. It requires saying which conditions were controlled and which were observed. If exclusive partitions or specialized isolation facilities were used, their scope belongs in the method. If only ordinary affinity was used, that is enough to report, provided the report does not silently substitute a stronger property for the one actually established.

There is a practical language improvement available without touching a machine. Replace “gave it a core” with “restricted these threads to these logical CPUs” when that is what happened. The replacement is longer, but it tells the reader both the actor and the boundary. It also leaves room to explain separate arrangements for competing tasks, sibling threads, and CPU-time limits. Precision does not make the operation less useful. It makes its usefulness assessable, because the next reader can distinguish a placement decision from a claim about isolation and reproduce the condition that was really intended.

The promise should end where the mechanism ends. Affinity can tell a thread where it is allowed to run. A coordinated system arrangement may provide additional separation from other work. Hardware topology and shared resources still define what that separation means physically. None of these statements makes the others redundant. The selected CPU identifier is the beginning of an execution condition, rather than a deed granting ownership of a core. That is the difference between an experiment with a clear boundary and a reassuring sentence that asks one setting to do several unrelated jobs.

Sources checked on October 22, 2026. CPU numbers and the machine arrangement are hypothetical; no affinity, partition, interrupt, or service settings were changed.

Sources & documentation

  1. sched_setaffinity(2) ↗
  2. Linux Control Group v2 ↗