Re: [PATCH v2 2/4] sched/rt: Restructure root_domain to reduce cacheline contention
From: Peter Zijlstra
Date: Fri Mar 20 2026 - 06:22:17 EST
On Mon, Jul 21, 2025 at 02:10:24PM +0800, Pan Deng wrote:
> When running a multi-instance FFmpeg workload on HCC system, significant
> contention is observed in root_domain cacheline 1 and 3.
What's a HCC? Hobby Computer Club? Google is telling me it is the most
prevalent form of liver cancer, but I somehow doubt that is what you're
on about.
> The SUT is a 2-socket machine with 240 physical cores and 480 logical
Satellite User Terminal? Subsea Umbilical Termination? Small Unit
Transceiver? Single Unit Test?
> CPUs. 60 FFmpeg instances are launched, each pinned to 4 physical cores
> (8 logical CPUs) for transcoding tasks. Sub-threads use RT priority 99
> with FIFO scheduling. FPS is used as score.
Yes yes, poorly configured systems hurt.
> perf c2c tool reveals (sorted by contention severity):
> root_domain cache line 3:
> - `cpupri->pri_to_cpu[0].count` (offset 0x38) is heavily loaded/stored,
> since counts[0] is more frequently updated than others along with a
> rt task enqueues an empty runq or dequeues from a non-overloaded runq.
> - `rto_mask` (0x30) is heavily loaded
> - `rto_loop_next` (0x24) and `rto_loop_start` (0x28) are frequently stored
> - `rto_push_work` (0x0) and `rto_lock` (0x18) are lightly accessed
> - cycles per load: ~10K to 59K
>
> root_domain cache line 1:
> - `rto_count` (0x4) is frequently loaded/stored
> - `overloaded` (0x28) is heavily loaded
> - cycles per load: ~2.8K to 44K:
>
> This change adjusts the layout of `root_domain` to isolate these contended
> fields across separate cache lines:
> 1. `rto_count` remains in the 1st cache line; `overloaded` and
> `overutilized` are moved to the last cache line
> 2. `rto_push_work` is placed in the 2nd cache line
> 3. `rto_loop_start`, `rto_loop_next`, and `rto_lock` remain in the 3rd
> cache line; `rto_mask` is moved near `pd` in the penultimate cache line
> 4. `cpupri` starts at the 4th cache line to prevent `pri_to_cpu[0].count`
> contending with fields in cache line 3.
>
> With this change:
> - FPS improves by ~5%
> - Kernel cycles% drops from ~20% to ~17.7%
> - root_domain cache line 3 no longer appears in perf-c2c report
> - cycles per load of root_domain cache line 1 is reduced to from
> ~2.8K-44K to ~2.1K-2.7K
> - stress-ng cyclic benchmark is improved ~18.6%, command:
> stress-ng/stress-ng --cyclic $(nproc) --cyclic-policy fifo \
> --timeout 30 --minimize --metrics
> - rt-tests/pi_stress is improved ~4.7%, command:
> rt-tests/pi_stress -D 30 -g $(($(nproc) / 2))
>
> According to the nature of the change, to my understanding, it doesn`t
> introduce any negative impact in other scenario.
>
> Note: This change increases the size of `root_domain` from 29 to 31 cache
> lines, it's considered acceptable since `root_domain` is a single global
> object.
Uhm, what? We're at 207 cachelines due to that previous patch, remember?
A few more don't matter at this point I would guess.
It doesn't actually apply anymore, but it needs the very same that
previous patch did -- more comments.