Re: [Patch v4 16/22] sched/cache: Disable cache aware scheduling for processes with high thread counts

From: Peter Zijlstra

Date: Thu Apr 09 2026 - 08:43:40 EST


On Wed, Apr 01, 2026 at 02:52:28PM -0700, Tim Chen wrote:
> @@ -1507,7 +1513,8 @@ void account_mm_sched(struct rq *rq, struct task_struct *p, s64 delta_exec)
> */
> if (time_after(epoch,
> READ_ONCE(mm->sc_stat.epoch) + EPOCH_LLC_AFFINITY_TIMEOUT) ||
> - get_nr_threads(p) <= 1) {
> + get_nr_threads(p) <= 1 ||
> + exceed_llc_nr(mm, cpu_of(rq))) {
> if (mm->sc_stat.cpu != -1)
> mm->sc_stat.cpu = -1;
> }

> @@ -1608,6 +1633,13 @@ static void task_cache_work(struct callback_head *work)
> if (p->flags & PF_EXITING)
> return;
>
> + if (get_nr_threads(p) <= 1) {
> + if (mm->sc_stat.cpu != -1)
> + mm->sc_stat.cpu = -1;
> +
> + return;
> + }
> +
> if (!zalloc_cpumask_var(&cpus, GFP_KERNEL))
> return;
>

> @@ -10105,6 +10144,13 @@ static enum llc_mig can_migrate_llc_task(int src_cpu, int dst_cpu,
> if (cpu < 0 || cpus_share_cache(src_cpu, dst_cpu))
> return mig_unrestricted;
>
> + /* skip cache aware load balance for single/too many threads */
> + if (get_nr_threads(p) <= 1 || exceed_llc_nr(mm, dst_cpu)) {
> + if (mm->sc_stat.cpu != -1)
> + mm->sc_stat.cpu = -1;
> + return mig_unrestricted;
> + }
> +
> if (cpus_share_cache(dst_cpu, cpu))
> to_pref = true;
> else if (cpus_share_cache(src_cpu, cpu))

This is what that made me notice that weird get_nr_threads() <= 1 thing.