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>
Subject: Re: [RFC PATCH v3] sched: Fix performance regression introduced by mm_cid
Date: Tue, 11 Apr 2023 08:41:25 -0400 [thread overview]
Message-ID: <7b5bf266-1418-1fe2-5d26-f94d3f67d49f@efficios.com> (raw)
In-Reply-To: <20230411085304.GB576825@hirez.programming.kicks-ass.net>
On 2023-04-11 04:53, Peter Zijlstra wrote:
> On Wed, Apr 05, 2023 at 12:26:35PM -0400, Mathieu Desnoyers wrote:
>> +void sched_mm_cid_migrate_from(struct task_struct *t)
>> +{
>
>> + /*
>> + * If the source cpu cid is set, and matches the last cid of the
>> + * migrated task, clear the source cpu cid to keep cid allocation
>> + * compact to cover the case where this task is the last task using
>> + * this mm on the source cpu. If there happens to be other tasks left
>> + * on the source cpu using this mm, the next task using this mm will
>> + * reallocate its cid on context switch.
>> + *
>> + * We cannot keep ownership of concurrency ID without runqueue
>> + * lock held when it is not used by a current task, because it
>> + * would lead to allocation of more concurrency ids than there
>> + * are possible cpus in the system. The last_mm_cid is used as
>> + * a hint to conditionally unset the dst cpu cid, keeping
>> + * allocated concurrency ids compact.
>> + */
>> + if (cmpxchg(src_pcpu_cid, src_cid, mm_cid_set_lazy_put(src_cid)) != src_cid)
>> + return;
>> +
>
> FWIW, I'm thinking that if we write this using try_cmpxchg() it'll be a
> little nicer:
>
> lazy_cid = mm_cid_set_lazy_put(src_cid);
> if (!try_cmpxchg(src_pcpu_cid, &src_cid, lazy_cid))
> return;
>
Yes, done.
>> + /*
>> + * The implicit barrier after cmpxchg per-mm/cpu cid before loading
>> + * rq->curr->mm matches the scheduler barrier in context_switch()
>> + * between store to rq->curr and load of prev and next task's
>> + * per-mm/cpu cid.
>> + *
>> + * The implicit barrier after cmpxchg per-mm/cpu cid before loading
>> + * rq->curr->mm_cid_active matches the barrier in
>> + * sched_mm_cid_exit_signals(), sched_mm_cid_before_execve(), and
>> + * sched_mm_cid_after_execve() between store to t->mm_cid_active and
>> + * load of per-mm/cpu cid.
>> + */
>> +
>> + /*
>> + * If we observe an active task using the mm on this rq after setting the lazy-put
>> + * flag, this task will be responsible for transitioning from lazy-put
>> + * flag set to MM_CID_UNSET.
>> + */
>> + rcu_read_lock();
>> + src_task = rcu_dereference(src_rq->curr);
>> + if (src_task->mm_cid_active && src_task->mm == mm) {
>> + rcu_read_unlock();
>> + /*
>> + * We observed an active task for this mm, clearing the destination
>> + * cpu mm_cid is not relevant for compactness.
>> + */
>> + t->last_mm_cid = -1;
>> + return;
>> + }
>> + rcu_read_unlock();
>> +
>> + /*
>> + * The src_cid is unused, so it can be unset.
>> + */
>> + if (cmpxchg(src_pcpu_cid, mm_cid_set_lazy_put(src_cid), MM_CID_UNSET) != mm_cid_set_lazy_put(src_cid))
>> + return;
>
> if (!try_cmpxchg(src_pcpu_cid, &lazy_cid, MM_CID_UNSET))
> return;
done,
Thanks!
Mathieu
>
>> + __mm_cid_put(mm, src_cid);
>> +}
--
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
prev parent reply other threads:[~2023-04-11 12:41 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
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 [this message]
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=7b5bf266-1418-1fe2-5d26-f94d3f67d49f@efficios.com \
--to=mathieu.desnoyers@efficios.com \
--cc=aaron.lu@intel.com \
--cc=linux-kernel@vger.kernel.org \
--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®