Re: [PATCH v10 1/2] sched/cache: Reduce the overhead of task_cache_work by only scan the visisted cpus

From: Chen Yu

Date: Wed Oct 21 2026 - 12:51:19 EST


On Fri, Oct 09, 2026 at 03:29:42AM +0000, Luo Gengkun wrote:
> The overhead of task_cache_work() is high, especially in multi-NUMA systems.
> Currently, task_cache_work() tries to find the pref_llc by scanning all CPUs
> in the system. However, most of these scans are meaningless, such as those
> for CPUs that have never been visited or were accessed a long time ago.
>
> To address this problem, introduce visited_cpus to track the visited CPUs
> and evict them once they have not been accessed for a duration exceeding
> llc_epoch_affinity_timeout.
>
> Now that we know exactly which CPUs to scan from visited_cpus, we can remove
> get_scan_cpumasks().
>
> Signed-off-by: Luo Gengkun <luogengkun@xxxxxxxxxxxxxxx>
>

Thanks Prateek for popping this patch up, and thanks Gengkun for the continuous
optimization on this. I asked AI to launch a full hackbench test on a Xeon with
4 LLCs per node, especially to test the case where the LLC is saturated, under
which scenario the contention for the visit_cpu mask is high. The test shows no
regression. So from a code design point of view, this change is a good optimization
to reduce the potential overhead, and also paves the way for the multiple preferred
LLC/node work that Jianyong is doing IMO,

Reviewed-by: Chen Yu <yu.c.chen@xxxxxxxxx>
Tested-by: Chen Yu <yu.c.chen@xxxxxxxxx>

thanks,
Chenyu

=========================================
Hackbench comparison
BASE: cas_on_base
TEST: cas_on_visit
=========================================
MODE G FD | BASE(s) | TEST(s) | DIFF% | RESULT
------- -- ----+-----------------+-----------------+---------+----------
process 1 4 | 0.329/16.1% | 0.302/27.8% | 8.21% | IMPROVED
threads 2 16 | 222.206/2.3% | 215.147/0.9% | 3.18% | IMPROVED
threads 2 20 | 26.031/14.3% | 24.097/7.4% | 7.43% | IMPROVED
threads 4 8 | 4.338/26.6% | 3.965/31.5% | 8.60% | IMPROVED