From: "Chen, Yu C" <yu.c.chen@intel.com>
To: Luo Gengkun <luogengkun2@huawei.com>
Cc: <dietmar.eggemann@arm.com>, <rostedt@goodmis.org>,
<bsegall@google.com>, <mingo@redhat.com>, <mgorman@suse.de>,
<vschneid@redhat.com>, <kprateek.nayak@amd.com>,
<linux-kernel@vger.kernel.org>, <peterz@infradead.org>,
<juri.lelli@redhat.com>, <vincent.guittot@linaro.org>,
<tim.c.chen@linux.intel.com>,
"chen.yu@linux.dev" <chen.yu@linux.dev>
Subject: Re: [PATCH v6 linux 1/2] sched/cache: Reduce the overhead of task_cache_work by only scan the visisted cpus
Date: Fri, 17 Jul 2026 16:27:38 +0800 [thread overview]
Message-ID: <b86112e7-0473-4456-b415-e279edd8e7d3@intel.com> (raw)
In-Reply-To: <20260717041231.3324851-2-luogengkun2@huawei.com>
On 7/17/2026 12:12 PM, Luo Gengkun wrote:
> struct sched_cache_stat {
> @@ -2398,6 +2399,7 @@ struct sched_cache_stat {
> unsigned long next_scan;
> unsigned long footprint;
> int cpu;
> + cpumask_var_t visited_cpus;
need zalloc_cpumask_var()/free_cpumask_var() in this patch.
> } ____cacheline_aligned_in_smp;
>
> #else
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index d78467ec6ee1..ab9010b2ec49 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -1585,6 +1585,7 @@ void mm_init_sched(struct mm_struct *mm,
> pcpu_sched->runtime = 0;
> /* a slightly stale cpu epoch is acceptible */
> pcpu_sched->epoch = rq->cpu_epoch;
> + pcpu_sched->epoch_last_visit = rq->cpu_epoch;
> epoch = rq->cpu_epoch;
> }
>
> @@ -1635,13 +1636,23 @@ static inline void __update_mm_sched(struct rq *rq,
> }
> }
>
> -static unsigned long fraction_mm_sched(struct rq *rq,
> - struct sched_cache_time *pcpu_sched)
> +static unsigned long fraction_mm_sched(int cpu,
> + struct mm_struct *mm)
> {
> + struct sched_cache_time *pcpu_sched =
> + per_cpu_ptr(mm->sc_stat.pcpu_sched, cpu);
> + struct rq *rq = cpu_rq(cpu);
> +
> guard(raw_spinlock_irqsave)(&rq->cpu_epoch_lock);
>
> __update_mm_sched(rq, pcpu_sched);
>
> + /* Skip the rq that has not been hit for a long time */
> + if ((rq->cpu_epoch - pcpu_sched->epoch_last_visit) > llc_epoch_affinity_timeout) {
> + cpumask_clear_cpu(cpu, mm->sc_stat.visited_cpus);
It may be worth adding a comment in account_mm_sched() or task_cache_work()
to clarify the race condition. As Tim noted, it happens between setting
and reading
visited_cpus. That said, it's a trade-off between accuracy and efficiency
- locking would fix it but at the cost of extra overhead IMO - and the
update-to-date
visited_cpus could be read properly in the next invoke of task_cache_work().
thanks,
Chenyu
next prev parent reply other threads:[~2026-07-17 8:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-17 4:12 [PATCH v6 0/2] Cache aware scheduling: Reduce the overhead of task_cache_work Luo Gengkun
2026-07-17 4:12 ` [PATCH v6 linux 1/2] sched/cache: Reduce the overhead of task_cache_work by only scan the visisted cpus Luo Gengkun
2026-07-17 8:27 ` Chen, Yu C [this message]
2026-07-17 4:12 ` [PATCH v6 linux 2/2] -- DO NOT APPLY!!! -- sched/cache/debug: Add trace event and sched feature to track scan cost Luo Gengkun
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b86112e7-0473-4456-b415-e279edd8e7d3@intel.com \
--to=yu.c.chen@intel.com \
--cc=bsegall@google.com \
--cc=chen.yu@linux.dev \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luogengkun2@huawei.com \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tim.c.chen@linux.intel.com \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.