﻿# Check thread affinity rather than only the parent process

Inspect affinity for the threads doing the work and preserve creation timing rather than extrapolating from the process leader.

Author: Retrivium editorial team
Updated: 2026-11-03
Canonical URL: https://retrivium.ai/journal/guide-linux-taskset-thread/
Language: en

The serving process's main thread is pinned near a GPU, but tokenization workers run elsewhere. Linux affinity is a thread property. Inspecting the process leader alone can therefore miss the execution boundary of the threads doing useful preparation, particularly when a library creates or reconfigures its own worker pool after startup.

## Enumerate the actual workers

Associate the service instance with its process and thread identities using the supported task directory. Preserve the observation time because pools can expand or replace workers. A thread name is useful context but not a stable unique identity. Record which threads are active during the operation being investigated rather than assuming every listed task participates in that path.

## Read masks per thread

sched_getaffinity observes the thread identified by its task ID. The process leader's ID refers to that leader, not automatically all siblings. A tool's all-tasks option has a different scope from its single-target form. Review the observation mode before drawing conclusions from a short command output that happens to display the familiar application PID.

## Account for inheritance timing

New threads inherit an affinity mask from their creator under the documented threading behavior. Later library changes can alter masks again. Moving the leader after a pool exists does not automatically express the desired policy for every old worker. Capture startup and steady-state masks separately when a regression appears only after the first request initializes additional libraries.

## Respect wider constraints

Administrative cpusets and online CPUs restrict where a thread can actually run. Affinity does not establish exclusive ownership of those CPUs and does not move existing host-buffer pages. Keep execution eligibility, CPU sharing and memory placement separate. A narrowly pinned preparation thread can also become the bottleneck, so proximity alone is not evidence that the chosen mask is useful.

## Verify a controlled pool

Use a disposable worker program with a known creation sequence and inspect each relevant task before and after the scoped policy operation. Keep configuration ownership clear so another controller does not rewrite the masks. Acceptance explains which threads received which constraint. It does not guarantee lower inference latency, NUMA-local pages or suitable affinity for every library-created worker in future releases.

## Primary references

[Linux Thread CPU Affinity](https://man7.org/linux/man-pages/man2/sched_setaffinity.2.html).

[taskset Affinity Utility](https://man7.org/linux/man-pages/man1/taskset.1.html).

[Process Thread Information](https://man7.org/linux/man-pages/man5/proc_pid_task.5.html).

Related reading: [First touch and NUMA: locating GPU host buffers](/journal/gpu-host-memory-first-touch/); [Idle GPU, throttled CPU: diagnosing container CPU quota](/journal/cgroup-cpu-throttling-gpu-feeder/).
