From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: linux-kernel@vger.kernel.org, Aaron Lu <aaron.lu@intel.com>,
Olivier Dion <odion@efficios.com>,
michael.christie@oracle.com
Subject: Re: [RFC PATCH v3] sched: Fix performance regression introduced by mm_cid
Date: Tue, 11 Apr 2023 08:57:20 -0400 [thread overview]
Message-ID: <f96978d0-ae96-0b4e-042f-531d17cb217e@efficios.com> (raw)
In-Reply-To: <20230411093705.GB578657@hirez.programming.kicks-ass.net>
On 2023-04-11 05:37, Peter Zijlstra wrote:
> On Fri, Apr 07, 2023 at 09:14:36PM -0400, Mathieu Desnoyers wrote:
>
>> diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
>> index bc0e1cd0d6ac..f3e7dc2cd1cc 100644
>> --- a/kernel/sched/sched.h
>> +++ b/kernel/sched/sched.h
>> @@ -3354,6 +3354,37 @@ static inline int mm_cid_get(struct mm_struct *mm)
>> static inline void switch_mm_cid(struct task_struct *prev, struct task_struct *next)
>> {
>> + /*
>> + * Provide a memory barrier between rq->curr store and load of
>> + * {prev,next}->mm->pcpu_cid[cpu] on rq->curr->mm transition.
>> + *
>> + * Should be adapted if context_switch() is modified.
>> + */
>> + if (!next->mm) { // to kernel
>> + /*
>> + * user -> kernel transition does not guarantee a barrier, but
>> + * we can use the fact that it performs an atomic operation in
>> + * mmgrab().
>> + */
>> + if (prev->mm) // from user
>> + smp_mb__after_mmgrab();
>> + /*
>> + * kernel -> kernel transition does not change rq->curr->mm
>> + * state. It stays NULL.
>> + */
>> + } else { // to user
>> + /*
>> + * kernel -> user transition does not provide a barrier
>> + * between rq->curr store and load of {prev,next}->mm->pcpu_cid[cpu].
>> + * Provide it here.
>> + */
>> + if (!prev->mm) // from kernel
>> + smp_mb();
>> + /*
>> + * user -> user transition guarantees a memory barrier through
>> + * switch_mm().
>> + */
>
> What about the user->user case where next->mm == prev->mm ? There
> sys_membarrier() relies on finish_task_switch()'s mmdrop(), but we
> can't.
AFAIU the finish_task_switch()'s mmdrop() is for the case where:
* [...] or in
* case 'prev->active_mm == next->mm' through
* finish_task_switch()'s mmdrop().
which applies for the case where we schedule from a kernel thread (which
kept the prior user task's mm as active mm) to a user task with the same
mm.
But this is really a transition from kernel -> user, not user -> user ?
Why should either membarrier or mm_cid care about a transition from
prev->mm to next->mm where mm is unchanged ? It does not register
as a transition from the comparison perspective.
I'll update my comment in switch_mm_cid to:
/*
* user -> user transition guarantees a memory barrier through
* switch_mm() when current->mm changes. If current->mm is
* unchanged, no barrier is needed.
*/
Thanks,
Mathieu
>
>> + }
>> if (prev->mm_cid_active) {
>> mm_cid_put_lazy(prev);
>> prev->mm_cid = -1;
>>
--
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
next prev parent reply other threads:[~2023-04-11 12:57 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-05 16:26 Mathieu Desnoyers
2023-04-05 20:37 ` Mathieu Desnoyers
2023-04-06 9:51 ` Peter Zijlstra
2023-04-07 23:50 ` Mathieu Desnoyers
2023-04-08 1:14 ` Mathieu Desnoyers
2023-04-11 9:37 ` Peter Zijlstra
2023-04-11 10:25 ` Peter Zijlstra
2023-04-11 13:10 ` Mathieu Desnoyers
2023-04-11 12:57 ` Mathieu Desnoyers [this message]
2023-04-11 11:03 ` Peter Zijlstra
2023-04-11 11:53 ` Peter Zijlstra
2023-04-11 8:46 ` Peter Zijlstra
2023-04-11 12:38 ` Mathieu Desnoyers
2023-04-11 8:53 ` Peter Zijlstra
2023-04-11 12:41 ` Mathieu Desnoyers
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=f96978d0-ae96-0b4e-042f-531d17cb217e@efficios.com \
--to=mathieu.desnoyers@efficios.com \
--cc=aaron.lu@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=michael.christie@oracle.com \
--cc=odion@efficios.com \
--cc=peterz@infradead.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®