From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49291D78779 for ; Thu, 21 Nov 2024 14:45:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C65B16B0096; Thu, 21 Nov 2024 09:45:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C15E36B0098; Thu, 21 Nov 2024 09:45:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ADDB46B0099; Thu, 21 Nov 2024 09:45:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 8E9B36B0096 for ; Thu, 21 Nov 2024 09:45:01 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 449741C7C27 for ; Thu, 21 Nov 2024 14:45:01 +0000 (UTC) X-FDA: 82810372344.06.25577AD Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf19.hostedemail.com (Postfix) with ESMTP id A42601A001C for ; Thu, 21 Nov 2024 14:43:51 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=pWFH7iTO; spf=none (imf19.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732200052; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=NoTVJMzmSr+7GvpbI9xoC6QlTWnogCWjAb08P6x+C6c=; b=k+93xMV1p28r/Qu5XGbdO2FoMFpYQHv+fKVXc0u9hjLIhZ83fTvwGssI1ZXuQetkTFqQ0m FbZAIHw7sWrlNK+qH4OXszdKSXK9k+GbM6ad1f0gltpHoTRog4Mo0/ET4PfNaL4tODTRD/ w/C1HBBnbU00/xYjf+hwx+gRjv8Q5BI= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=pWFH7iTO; spf=none (imf19.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732200052; a=rsa-sha256; cv=none; b=z242loOj6SQnYU/lPv+w59aDvfcNsoJNZz13vh0D2INRQpc2o/mIaDgcN0ub47ejpR4qCw dnBItCtpHP6dMTFwg9J49H+ivaZxlW2vv6iC35q3zL20cOotjONbNJPk9+txU/wCXsW08j QBjkcqFoCKMaLkA+EESfJDgdK5m1oR0= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=NoTVJMzmSr+7GvpbI9xoC6QlTWnogCWjAb08P6x+C6c=; b=pWFH7iTOkfeuTaDn9qkuWCzJg0 XHTPtIPgIv0NKPfBaiNcQgjx5VeG+qplbW+uqkMCzsO8WUVMNh0LM3s0NflbTCaHkU8XxSyIWmz0M 3knavxb0cxSgry9QZ9SeEcMZ6B4emjFgND5d2XsHTJ0UwXVHWb0CregP8xfqENcW1Xm4ATIKJ06jo 16mG4ix63zcI4GNLP7f6r5S1r23mylfs7kVa9pxONSuSTYOR+wxkz9U7QF4/tBf9GMMuMMJoKhqW0 F86eLEdxmxj8YbSHHSmXDGComlwB2Kntw/gWjyUe8f05ua8DU/E/WbVswICDD1zbtuafZiptNJ/pW FTx6bEag==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tE8QF-00000000ahp-2TBZ; Thu, 21 Nov 2024 14:44:44 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 902C730068B; Thu, 21 Nov 2024 15:44:42 +0100 (CET) Date: Thu, 21 Nov 2024 15:44:42 +0100 From: Peter Zijlstra To: Andrii Nakryiko Cc: linux-trace-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, oleg@redhat.com, rostedt@goodmis.org, mhiramat@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, jolsa@kernel.org, paulmck@kernel.org, willy@infradead.org, surenb@google.com, mjguzik@gmail.com, brauner@kernel.org, jannh@google.com, mhocko@kernel.org, vbabka@suse.cz, shakeel.butt@linux.dev, hannes@cmpxchg.org, Liam.Howlett@oracle.com, lorenzo.stoakes@oracle.com, david@redhat.com, arnd@arndb.de, richard.weiyang@gmail.com, zhangpeng.00@bytedance.com, linmiaohe@huawei.com, viro@zeniv.linux.org.uk, hca@linux.ibm.com Subject: Re: [PATCH v4 tip/perf/core 2/4] mm: Introduce mmap_lock_speculation_{begin|end} Message-ID: <20241121144442.GL24774@noisy.programming.kicks-ass.net> References: <20241028010818.2487581-1-andrii@kernel.org> <20241028010818.2487581-3-andrii@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20241028010818.2487581-3-andrii@kernel.org> X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: A42601A001C X-Stat-Signature: nddkuy13xi8c5rx6rqz9s4i1z9fok4k9 X-Rspam-User: X-HE-Tag: 1732200231-275653 X-HE-Meta: U2FsdGVkX19YL0Y6AnqvsqPBLVrOiPPi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mf+wIVm6BBiwb9ULjoK10C5tFglyUelioFf+Se5O0CJbZAp/dAPraRE0DtrlI27wwwYGa43TmFlwbRPe7UXsTM0o5jehUQbfqryczYeEnfm/s2Sr4s5R2VoX+p2WIykg4Jl50245sWr0usnPhyhlH2+raPc6LZreeNIRibkJnpDGB3WFMlO8OJf9Jzabo/QzRRZOlGFIh9xvw6btVvrYEaus53AgsiulpHwdLFQlzHJ3Aqbjjb2hcZWnV1ErIQvAC+nsK4lZ1kdqIMwLfwRljrrNA0gtHyoi0UMmNh7Su8eVPkTRCuIJbhr X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Sun, Oct 27, 2024 at 06:08:16PM -0700, Andrii Nakryiko wrote: > From: Suren Baghdasaryan > > 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 > Signed-off-by: Suren Baghdasaryan > Signed-off-by: Andrii Nakryiko > --- > 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 ?