Skip to content

Checking your reading list…

Retry verification

Stay curious. Build better.

Appearance

Choose how BestHub looks on this device.

Changes apply immediately.

Search articles

Open Discover with these filters

Suggested searches

Why 16 Threads on 40 Cores Yield 40% Per-Core Utilization: Linux CFS Load Balancing Explained
Fundamentals 14 min read

Why 16 Threads on 40 Cores Yield 40% Per-Core Utilization: Linux CFS Load Balancing Explained

This article explains why 16 CPU-intensive threads on a 40-core Linux system show uniform 40% per-core utilization instead of saturating 16 cores, detailing the CFS scheduler's per-CPU runqueues, load balancing mechanisms (wake-up, periodic, idle), and scheduling domain hierarchy that distribute threads evenly across all cores.

1. Concurrency Limit and CPU Load Distribution

The process concurrency limit caps total CPU consumption, while load balancing determines spatial distribution. Process A uses 16 CPU cores total (1600% in top), matching its 16 runnable threads. Spread across 40 cores, each core averages 16/40 ≈ 40% utilization.

"At most 16C" is set by the process's runnable thread count. Sixteen threads can occupy at most 16 CPUs simultaneously — this parallelism ceiling is independent of total system cores. Even on a 128-core machine, the process still consumes only 16 cores' worth of compute.

"~40% per core" results from the scheduler's load balancing. The default CFS scheduler spreads threads across all cores, so 16 units of compute are divided among 40 cores, giving each core 16/40 ≈ 40%.

Minimal reproduction example (16 CPU-bound threads on a 40-core server):

// 16 CPU-intensive threads
pthread_t t[16];
for (int i = 0; i < 16; i++)
    pthread_create(&t[i], NULL, busy_loop, NULL); // while(1){}
# Observation commands
mpstat -P ALL 1          # per-core usage → all ≈ 40%
top -H -p <pid>         # per-thread CPU → 16 threads each ~100%
ps -eLf | grep <pid>    # confirm thread count = 16

2. Thread: The Minimum Scheduling Unit

Although a process is often viewed as the scheduling object, the Linux scheduler's smallest runnable entity is the thread (kernel task), not the process. A process is merely a thread group; it does not consume CPU or enter scheduling queues itself. Process CPU usage is the sum of its threads' usage. Sixteen concurrent threads equal sixteen runnable tasks, so process A's total CPU ceiling is 16 fully loaded cores (16C).

Under the hood, threads are created via clone() with CLONE_THREAD and share address space ( mm), file descriptor table ( files), signal handlers, etc. Each thread has its own task_struct containing independent scheduling fields: policy, priority/nice value, and CFS's vruntime. From the scheduler's perspective there is no process A — only sixteen independent scheduling entities.

Thread vs process scheduling view
Thread vs process scheduling view

A single thread can run on only one CPU at any instant; sixteen threads provide sixteen parallel slots. More system cores cannot increase parallelism. Why, then, are the sixteen threads not pinned to sixteen cores (leaving twenty-four idle) but instead spread evenly across all forty? The answer lies in the kernel's load balancer.

3. Per-CPU Runqueue Mechanism

The Linux CFS (Completely Fair Scheduler) uses a per-CPU runqueue (rq) design, not a global queue.

Queue structure: Each rq contains a cfs_rq organized as a red-black tree keyed by virtual runtime ( vruntime). Smaller vruntime means the thread has accumulated less CPU time and thus higher priority.

Thread selection: pick_next_task_fair() picks the leftmost node (minimum vruntime) to run on the CPU.

Accounting and preemption: On each timer tick, update_curr() increments the current thread's vruntime; check_preempt_tick() decides whether to preempt (triggering switch_to()).

Structural constraint: A thread can be queued on or running on only one CPU's rq at a time; it cannot exist on two cores simultaneously.

Per-CPU runqueue structure
Per-CPU runqueue structure

Sixteen threads × one CPU each = sixteen parallel slots. Yet the sixteen units of compute are uniformly distributed across all forty cores because of the kernel's load balancer.

4. CPU Load Balancing Mechanism

If the scheduler pinned sixteen threads to sixteen cores, we would observe sixteen cores at 100% and twenty-four at 0%. The default CFS design goal is the opposite: keep load as even as possible across cores, so threads continuously migrate among the forty cores. The kernel employs three primary balancing paths:

Wake-up balancing: When a thread is woken or created, select_task_rq_fair() with wake_affine() picks a target core, preferring idle cores or those sharing cache with the waker.

Periodic balancing: The scheduler periodically runs run_rebalance_domains() across scheduling domains (SMT → same LLC cluster → NUMA node → whole system). It uses find_busiest_group() / find_busiest_queue() to locate the busiest queue and migrates threads to less loaded queues.

Idle balancing: When a CPU is about to go idle, idle_balance() (including nohz idle balancing) actively pulls threads from other queues; if pulling fails, active_balance uses a stopper thread to force migration.

Load balancing paths
Load balancing paths

Sixteen CPU-bound threads (continuously runnable, no sleep, no I/O wait) stay runnable. The load balancer cycles their execution opportunities across all forty cores. Consequently, in any sampling window each core spends roughly 40% of its time executing these threads. Real-world balancing is further shaped by scheduling domain hierarchy (SMT/cluster/NUMA), migration cost, and hyper-threading sharing, so perfect uniformity is not guaranteed.

Linux uses sched_domain hierarchical layers for load balancing, from fine to coarse:

SMT domain          (2 logical CPUs within same physical core)
  └→ MC domain      (cores sharing same LLC)
       └→ DIE domain (multiple LLCs within same chip)
            └→ NUMA domain (same NUMA node)
                 └→ GLOBAL domain (cross-node)

Each domain layer has its own load_balance() trigger conditions and migration cost:

SMT domain: Trigger frequency: every tick. Migration cost: very low. Typical behavior: move task from busy sibling to idle sibling.

MC domain: Trigger frequency: periodic (sd->balance_interval). Migration cost: low. Typical behavior: migrate to idle core within same LLC.

NUMA domain: Trigger frequency: low frequency. Migration cost: high (cross memory controller). Typical behavior: migrate to idle core within same node.

GLOBAL domain: Trigger frequency: very low frequency. Migration cost: very high. Typical behavior: avoid if possible.

5. Summary

Assuming sixteen CPU-bound threads (continuously runnable, no sleep, no I/O wait), total demand per second is sixteen threads × 100% per thread = sixteen core-seconds per second. This is the physical meaning of process A's 16C CPU ceiling (top shows ~1600%): each second it consumes CPU time equivalent to sixteen cores running at full speed for one whole second. The system provides forty core-seconds per second. The load balancer spreads demand across all cores, so each core is busy for 16 ÷ 40 = 0.4 core-seconds per second, i.e., 40% utilization.

Utilization calculation diagram
Utilization calculation diagram

This 40% is a time-average measure: tools like mpstat and top sample /proc/stat at fixed intervals and compute busy time divided by wall-clock time. Sixteen threads migrate among cores, so each sampling window shows each core executing the process's threads for about 40% of the window — hence no core hits 100% and none stays completely idle.

The derivation above assumes: default CFS (SCHED_OTHER) configuration, no CPU affinity binding, no cpuset constraints, no real-time thread preemption, no cgroup quotas, threads are CPU-bound and continuously runnable, and no other significant system load. The following situations alter the conclusion: Real-time threads present: Higher-priority real-time threads preempt CFS threads, changing distribution. Container/cgroup quota: Quota limiting the process to 16C causes throttling, not uniform 40% per core. NUMA binding or cpuset: Threads restricted to a subset of nodes/cores; system-wide load spreading fails. Hyper-threading: Forty logical cores may map to twenty physical cores × two threads; SMT siblings share execution units, so utilization should be recalculated per physical core. Mixed workload: Other processes, kernel threads, or interrupts add to per-core usage; cannot attribute solely to process A.
About this article

For questions about attribution, corrections or content rights, please contactadmin@besthub.devand we will review it promptly.

Linuxperformance analysisthread schedulingNUMACFS schedulerCPU load balancingper-CPU runqueuescheduling domains

Discussion 0

Questions, practical examples and thoughtful responses.

Open full discussion