[REGRESSION] sched: 333238da9a19 makes 1-CPU TCP loopback ping-pong ~25% slower (lost wakeup preemption)

From: Jiri Vozar

Date: Thu Dec 03 2026 - 18:26:13 EST


Hi Vincent, Peter,

Commit 333238da9a19 ("sched: Update time before requeueing delayed
entities") makes TCP loopback ping-pong between two tasks that share a
CPU about 20-25% slower. Our performance CI found it in two places:
Fedora ELN 7.2-rc6 -> 7.3-rc5, and the RHEL 6.12 backport of the same
commit. Reverting only that commit removes the regression. Tracing
shows that the waker is no longer preempted on wakeup: it blocks in
read() instead, so every round trip needs two wakeups instead of one.

I don't think the commit is wrong; it computes the requeued entity's
lag correctly. Please tell me whether this is a known trade-off, or
whether the requeue placement should behave differently.

Setup
-----
- Machine: 2 x Intel Xeon 6740P, nosmt (96 CPUs), 2 NUMA nodes.
- Boot: isolcpus=nohz_full=rcu_nocbs=72,78,84,90.
- Benchmark: libmicro "pipe" TCP mode, two processes ("-x tcp -m mp")
or two threads ("-m mt"), 1-byte messages:

nice -n 19 numactl -m<node> -C 72,78,84,90 bench pipe -s 1 -x tcp -m mp

Isolated CPUs are not load balanced, so both tasks end up on CPU 72.
On a normal boot the tasks get spread over two CPUs and there is no
difference.
- Sched features: defaults (DELAY_DEQUEUE, DELAY_ZERO, PLACE_LAG,
RUN_TO_PARITY, PREEMPT_SHORT, NO_NEXT_BUDDY), base_slice 2.8ms.
- Preemption model (kernel default, no preempt= on the cmdline):
lazy on 7.3, voluntary on RHEL 6.12.

Results
-------
usecs/op, median of 3 runs on the same host, lower is better (nice 0
gives the same split: 5794 vs 4514 for 7.3-rc5 rebuilt vs reverted):

tcp tcp tcp unix
kernel 2-proc 2-thr 1-task 2-proc
7.2-rc6 (Fedora ELN) 4673 4504 2086 4570
7.3-rc5 (Fedora ELN) 5838 5693 2104 3058
7.3-rc5 rebuilt, unmodified 5723 5572 2073 3053
7.3-rc5 rebuilt, commit reverted 4527 4379 2064 3382
RHEL 6.12 without the backport 4978 4782 2393 3321
RHEL 6.12 with the backport 6075 5744 2393 3241
RHEL 6.12 rebuilt, unmodified 6057 5693 2403 3281
RHEL 6.12 rebuilt, commit
reverted 4880 4732 2404 3255

TCP 2-proc / 2-thr: +25% / +26% on ELN, +22% / +20% on RHEL.
"commit reverted" = only 333238da9a19 reverted, same toolchain.

In 7.3 the update_curr() sits in enqueue_task_fair() ahead of the
ENQUEUE_DELAYED branch, since 68e37487810a ("sched/fair: Fix flat
hierarchy"). The "reverted" kernel moves it below the
requeue_delayed_entity() call, so it is skipped for delayed requeues
only.

What changes
------------
1. How the CPU changes hands. I counted sched_switch events from one
ping-pong task to the other on CPU 72 during 2s of the 2-process
test. R means the sender was preempted while still runnable; S
means it blocked in read().

kernel R (preempted) S (blocked)
6.12 without backport 96,407 97,169
6.12 with backport 7 184,512
7.3-rc5, commit reverted 151,404 154,088
7.3-rc5 853 252,166

2. The wakeup decision. bpftrace on enqueue_task_fair() and
wakeup_preempt_fair() for wakeups of the ping-pong peer on CPU 72,
over a whole 2-process run at nice 19 (the CI setting):

7.3-rc5 rebuilt 7.3-rc5 reverted
wakee was sched_delayed 3.2% 72%
wakeup set NEED_RESCHED_LAZY 0.5% 98.6%
delayed wakee re-placed (lag->0) 99.9% 0.2%

My reading of the mechanism, for two equal-weight tasks A (running,
waker) and B (wakee):

- Without the commit, B has just blocked with a small negative lag, so
it is delay-dequeued. A's reply wakes it from the loopback receive
path, and requeue_delayed_entity() evaluates B's lag against a stale
V, because A's runtime since it was picked is not yet accounted. B
keeps its negative lag and its old vruntime and deadline.
wakeup_preempt_fair() -> update_curr() then charges A and moves it
past B, so A is no longer eligible. In a nice-0 trace of the
reverted kernel, this update averaged 4.3us of vruntime against B's
1.9us lead. pick_eevdf() returns B, and A is lazily preempted on
return from write(). B replies before A reaches read(), so A never
sleeps. That is one wakeup per round trip, and the pattern sustains
itself.

- With the commit, V is current at the requeue. B's lag comes out
>= 0, DELAY_ZERO clamps it to 0, and B is re-placed at V (equal to
A's vruntime) with a fresh deadline, V + slice. That deadline is
usually later than A's. When it isn't, A is still inside its
RUN_TO_PARITY-protected slice. Either way A stays eligible and
protected, so nothing preempts it. A carries on into read(), blocks,
and has to be woken by B's reply. That is two wakeups per round
trip. On the busy CPU that costs about +17% instructions and +27%
cycles per switch, and +20-26% time/op for TCP. From then on every
wakeup is a normal one, with the wakee placed at the waker's
vruntime, so this pattern also sustains itself.

On both kernels the wakeup preempts exactly when A is past B after
the update. There are no exceptions in 6.0M traced nice-0 wakeups:

7.3-rc5 rebuilt 7.3-rc5 reverted
wakeups (nice 0, whole run) 3,424,085 2,579,611
wakee was sched_delayed 10.4% 72.2%
delayed wakee re-placed (lag->0) 99.9% 0.2%
preempted (A past B) 17,229 2,523,946
not preempted (A at or behind B) 3,406,741 55,622

The commit does not change that rule. It changes how often A ends up
past B, through the re-placement of the delayed wakee.

Unix-socket ping-pong is not hurt by this commit: on 7.3 it gets
about 10% faster (3382 -> 3053), and on RHEL 6.12 it is neutral.
Most of the -33% unix gain between 7.2 and 7.3 comes from other
changes. We have not worked out why the unix case reacts
differently.

Questions
---------
- Is this an expected consequence of computing the requeue lag
correctly? Is the 1-CPU synchronous ping-pong case acceptable
collateral?
- If not: should a delayed entity whose lag gets clamped to 0 on
requeue keep its old deadline instead of getting a fresh one? Or
should synchronous wakeups be handled differently here?

I can test patches on the same hardware, or rerun on a vanilla upstream
build if that helps.

#regzbot introduced: 333238da9a19

Thanks,
Jiri Vozar
Red Hat Kernel Performance QE