Back

Same syscalls, three times the price: what "older hardware" really costs

· 7 min read

My last post ended on a reassuring line: “The older nodes are still somewhat slower than the newer ones: that part really is hardware.”

That line hid a problem.

With the audit rules gone, I re-ran the Postgres benchmark. The older nodes (AMD EPYC 9654, Zen 4) were still 2× slower than the newer ones (EPYC 9655 and 9755, Zen 5). sysbench’s CPU test said the gap should be 1.15×. A CPU generation and a few hundred MHz explain 15–30%, not 100%.

So either Postgres was doing something odd, or “older hardware” hid a cost sysbench doesn’t see.

Benchmarking what we actually run

Synthetic benchmarks had already fooled me once. So I ran our own software, with the image versions we run in production: one 4-CPU pod with guaranteed CPU per node, on 3 Zen 4 and 4 Zen 5 staging nodes, in parallel.

There is no single “N× slower”. It goes from no difference at all to more than 3×. But it follows one thing, the share of time spent in the kernel:

                   kernel   extra time on Zen 4 (█ = +10%)
Django (HTML page)     6%   ████                   ×1.39
Elasticsearch        7–8%   ████                   ×1.22–1.36
ClickHouse         14–18%   ████                   ×1.39–1.40
Django (JSON API)     27%   ███████                ×1.67
RabbitMQ           39–41%   █████                  ×1.43–1.49
Postgres           44–59%   ███████████            ×1.95–2.12
Redis (pipelined)     69%   ██████████████         ×2.1–2.4
Redis (1 command)     89%   ██████████████████████ ×3.2

Elasticsearch and Django pages barely enter the kernel and lose 20–40%. Postgres spends about half its time there and loses 2×. Redis with one command per round trip is almost only syscalls (network read, network write, poll) and loses 3.2×.

The outliers fit too. etcd (47% kernel, ×1.0) waits on disk syncs, equally slow on both tiers, so the CPU doesn’t matter. Python’s pyperformance lands at ×1.29–1.56, with the low-kernel group. NumPy matrix multiplication (×2.0) never enters the kernel: that gap comes from Zen 5’s full-width 512-bit vector units, a separate story.

Is Zen 4 doing more work?

My first question: maybe Zen 4 makes more syscalls or context switches per operation, because of some scheduler setting or kernel tunable. Then the fix would be a config change.

perf stat software counters, per operation, Zen 4 vs Zen 5:

TestContext switches / opSyscalls / opCPU time / op
Postgres TPC-B, direct9.7 vs 9.959 vs 60466 µs vs 213 µs
Postgres via pgbouncer, select1.5 vs 1.613.6 vs 13.889 µs vs 44 µs
Redis, one command—9.5 vs 9.520.6 µs vs 6.4 µs

Same work on both tiers. Zen 4 just pays 2–3× more CPU for it: for Postgres, about 7.9 µs per syscall against 3.5 µs.

So: why is entering the kernel so much more expensive on Zen 4?

Ruling out the usual suspects

  • Clock speed. Pod-level counters first said 2.8 GHz on Zen 4, which looked like power capping. Those counters undercount on syscall-heavy loads. Whole-node APERF/MPERF counters said 3.4–3.6 GHz, the chip’s rated all-core boost, at 281–293 W under a 360 W limit. Zen 5 runs at 4.1–4.3 GHz: a real 1.15–1.23× gap, and nothing to tune.
  • Disks, RAM, NUMA, huge pages, cpufreq governor. Same disk reads per transaction, same memory latency (133–170 ns against 144–160 ns), same governor and boost settings.
  • A weaker branch predictor. On pure computation like 7-Zip, user-space branch misses are the same on both (12.7% against 12.5%).

What’s left: the kernel.

The kernel signature

perf stat can split cycles, instructions and branch misses between user space and kernel. Here the two tiers stop looking alike (Zen 4 vs Zen 5):

WorkloadKernel instructions per cycleKernel branch misses
SHA-256 (barely enters the kernel)0.39 vs 0.39–0.4112.6% vs 1.1–1.2%
Postgres TPC-B0.48 vs 0.9112.5% vs 1.1%
Redis0.70 vs 1.9010.9% vs 0.3%
stress-ng context switch0.72 vs 1.8410.8% vs 0.3%

On Zen 4, the kernel mispredicts 10–13% of its branches, whatever the workload, even for SHA-256, which spends 1% of its time there. On Zen 5: 0.3–1.2%. A miss rate that ignores the workload points to something applied to every kernel code path.

The likely candidate: the mitigation for SRSO (Speculative Return Stack Overflow, “Inception”, CVE-2023-20569). It affects Zen 3 and Zen 4, not Zen 5. Linux’s default mitigation on those CPUs, “Safe RET”, sends every kernel function return through a thunk that makes the CPU mispredict it on purpose, so an attacker can’t steer where speculation goes. Simplified:

a kernel function returns to its caller

Zen 5, no mitigation needed
  ret ──► predictor: "back to the caller"         hit

Zen 4, SRSO "Safe RET"
  ret becomes a jump to a thunk:
    call safe_ret        ◄─ predictor now expects a
                            return to right here
    lea  8(%rsp), %rsp   ◄─ drop that return address
    ret  ──► the real caller, not "right here"    MISS

A CPU normally predicts returns almost perfectly, which is what makes deep kernel call chains cheap. With Safe RET, every kernel return is a miss: a constant, workload-independent miss rate, which is what we see.

There’s a knock-on effect too: after each trip into the kernel, user code on Zen 4 mispredicts more (Postgres: 5.4% user branch misses against 1.4%). Each crossing seems to leave the predictor degraded.

Put together, the numbers add up:

Zen 4 slower by:  clock × core × kernel = predicted (measured)

Postgres TPC-B    ×1.2  × ×1.3     × ×1.4     ≈ ×2.2  (×2.1)
Redis             ×1.2  × ×1.0–1.2 × ×2.3–2.6 ≈ ×3.1  (×3.2)

A caveat: this is an inference, not a proof. The clean test is booting a Zen 4 node with spec_rstack_overflow=off and re-running the benchmarks. We didn’t, and won’t: these nodes run real workloads, and turning off a security mitigation to win an argument is not a trade I want to make. What we have is a signature consistent with SRSO, and nothing else that explains it.

Public benchmarks agree, with a nuance. When the mitigation came out, Phoronix found small changes on a Zen 4 desktop CPU, only for I/O-heavy workloads. Later, they found disabling mitigations brings no real-world benefit on Zen 5, which isn’t affected. Desktop benchmarks barely touch the kernel. Neither do our Elasticsearch, ClickHouse or Django pages, and there the gap is also just clock plus core: 1.2–1.4×. The cost only shows when a service lives in syscalls, and then it’s big.

What we can do about it

Not much on the machines. The mitigation stays on: that was decided before I started. The clock is already at its maximum under the power limit. Newer microcode would bring security fixes, not speed.

So it’s about placing workloads:

  • Large Postgres databases and busy Redis instances go on Zen 5. A Postgres instance sized for 10 cores on Zen 5 needs about 20 on Zen 4.
  • Elasticsearch, ClickHouse, Python services and etcd can stay on Zen 4, at a known 1.0–1.5× cost.
  • Fewer syscalls per operation narrows the gap. Pipelining, batching, connection pooling: Redis pipelined by 16 loses 2.2× instead of 3.2×.
  • The real fix is replacing the older nodes. Now we have the numbers to plan it.

How it went with Claude

Same setup as last time: Claude, Anthropic’s coding agent, in my terminal, read-only on the clusters. I created the benchmark pods myself from the commands it gave me.

  • The two questions that moved things were mine. “Benchmark everything we actually run” turned one Postgres anomaly into a pattern. “Could it be different context switching?” turned “the kernel is slower” into “same syscalls, three times the price”.
  • Its part was turning each question into a harness. Pods with a perf sidecar per workload, run on 7 nodes in parallel, summarised as per-tier medians.
  • It made mistakes, and the data caught them. The 2.8 GHz reading led it to a power-capping theory, dropped once node-level counters said 3.5 GHz. Its harness also hung twice: a shell wait on a background server that never exits, and a RabbitMQ readiness check that ran only once. Quick fixes, but a script you didn’t read is a script you don’t fully trust.
  • It was careful about its own claim. Its summary labelled SRSO “effect measured, cause inferred”, and named the decisive test and why we weren’t running it.

What I take away from this

  • “Older hardware” is not one number. The same two machines are 1.0× or 3.2× apart depending on what runs on them. Measure your own workloads, or at least the heaviest one, before deciding where things go.
  • Synthetic CPU benchmarks don’t measure the kernel. sysbench, 7-Zip and SHA-256 all said ~1.15×, because none of them make syscalls. Databases and caches mostly do.
  • Count the work before timing it. Syscalls and context switches per operation separate “the machine does more” from “the machine pays more per unit”. That split decided whether a config fix existed.
  • Security costs are real, and sometimes you pay them in hardware. Keeping a mitigation on can be the right call. Know its price per workload, so you buy your way around it on purpose, not by accident.

Next time someone says the old nodes are “a bit slower”, ask: slower at what?