[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241121144442.GL24774@noisy.programming.kicks-ass.net>
Date: Thu, 21 Nov 2024 15:44:42 +0100
From: Peter Zijlstra <peterz@...radead.org>
To: Andrii Nakryiko <andrii@...nel.org>
Cc: linux-trace-kernel@...r.kernel.org, linux-mm@...ck.org,
akpm@...ux-foundation.org, oleg@...hat.com, rostedt@...dmis.org,
mhiramat@...nel.org, bpf@...r.kernel.org,
linux-kernel@...r.kernel.org, jolsa@...nel.org, paulmck@...nel.org,
willy@...radead.org, surenb@...gle.com, mjguzik@...il.com,
brauner@...nel.org, jannh@...gle.com, mhocko@...nel.org,
vbabka@...e.cz, shakeel.butt@...ux.dev, hannes@...xchg.org,
Liam.Howlett@...cle.com, lorenzo.stoakes@...cle.com,
david@...hat.com, arnd@...db.de, richard.weiyang@...il.com,
zhangpeng.00@...edance.com, linmiaohe@...wei.com,
viro@...iv.linux.org.uk, hca@...ux.ibm.com
Subject: Re: [PATCH v4 tip/perf/core 2/4] mm: Introduce
mmap_lock_speculation_{begin|end}
On Sun, Oct 27, 2024 at 06:08:16PM -0700, Andrii Nakryiko wrote:
> From: Suren Baghdasaryan <surenb@...gle.com>
>
> Add helper functions to speculatively perform operations without
> read-locking mmap_lock, expecting that mmap_lock will not be
> write-locked and mm is not modified from under us.
>
> Suggested-by: Peter Zijlstra <peterz@...radead.org>
> Signed-off-by: Suren Baghdasaryan <surenb@...gle.com>
> Signed-off-by: Andrii Nakryiko <andrii@...nel.org>
> ---
> include/linux/mmap_lock.h | 29 +++++++++++++++++++++++++++--
> 1 file changed, 27 insertions(+), 2 deletions(-)
>
> @@ -86,11 +87,35 @@ static inline void mm_lock_seqcount_end(struct mm_struct *mm)
> do_raw_write_seqcount_end(&mm->mm_lock_seq);
> }
>
> -#else
> +static inline bool mmap_lock_speculation_begin(struct mm_struct *mm, unsigned int *seq)
> +{
> + *seq = raw_read_seqcount(&mm->mm_lock_seq);
> + /* Allow speculation if mmap_lock is not write-locked */
> + return (*seq & 1) == 0;
> +}
At the very least this should have more comment; I don't think it
adequately explains the reason for being weird. Perhaps:
/*
* Since mmap_lock is a sleeping lock, and waiting for it to
* become unlocked is more or less equivalent with taking it
* ourselves, don't bother with the speculative path and take
* the slow path, which takes the lock.
*/
*seq = raw_read_seqcount(&mm->mm_lock_seq);
return !(*seq & 1);
But perhaps it makes even more sense to add this functionality to
seqcount itself. The same argument can be made for seqcount_mutex and
seqcount_rwlock users.
> +static inline bool mmap_lock_speculation_end(struct mm_struct *mm, unsigned int seq)
> +{
> + return !do_read_seqcount_retry(&mm->mm_lock_seq, seq);
> +}
This naming is somewhare weird, begin/end do not typically imply boolean
return values.
Perhaps something like? can_speculate, or speculate_try_begin, paired
with speculated_success or speculate_retry ?
Powered by blists - more mailing lists