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 D4034D58D64 for ; Mon, 25 Nov 2024 16:18:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 56DAC6B008C; Mon, 25 Nov 2024 11:18:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 51DBB6B0092; Mon, 25 Nov 2024 11:18:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E58D6B0093; Mon, 25 Nov 2024 11:18:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 1FCEC6B008C for ; Mon, 25 Nov 2024 11:18:53 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 92087C0CD3 for ; Mon, 25 Nov 2024 16:18:52 +0000 (UTC) X-FDA: 82825126062.29.BF2F202 Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) by imf06.hostedemail.com (Postfix) with ESMTP id 2E1BD180012 for ; Mon, 25 Nov 2024 16:18:48 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=EjFI2Cvi; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf06.hostedemail.com: domain of surenb@google.com designates 209.85.160.182 as permitted sender) smtp.mailfrom=surenb@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732551529; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=mXQbE0T1v2fJwmVq6RAvjEXp4Ag7Di7PPppePVUvnw8=; b=JXHHqXJGP5vyPBafenZVnwaZhPtHyKHFYkskFv6Q7lrkvapQfhefxF4oHBYloSDPvRsOZ4 UDShud/Dkdi7rNenU5dXzThyrfBkvWVH1MpMOM5hSUOsG3EOhO7F4/2E/X66sHfw6nGQpv rXr6ACciNLqoFbD72GH4ey2QWRp0RWc= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=EjFI2Cvi; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf06.hostedemail.com: domain of surenb@google.com designates 209.85.160.182 as permitted sender) smtp.mailfrom=surenb@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732551529; a=rsa-sha256; cv=none; b=j39MPg62TjyXIYq3zfD223Y5maD+XYMbBisTYfFili8548Q32RsQhMWYKwS6x02WEGK+Ny Hqwpzc4YB4GM8JRfnLTA5u3uBNgLr14Noup7/t2go05XIFTuBCl2/d++Nbr6eS/p0gi02O U8OQjGZ7QEjnSOcHjco518oQyX+pIIg= Received: by mail-qt1-f182.google.com with SMTP id d75a77b69052e-46687f60b73so385791cf.0 for ; Mon, 25 Nov 2024 08:18:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1732551530; x=1733156330; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=mXQbE0T1v2fJwmVq6RAvjEXp4Ag7Di7PPppePVUvnw8=; b=EjFI2CviLPPu9eW+fllyehYmFbcVkyZlRcYazCKUTP9XTAsnnMJliGbM91SaeJu5pt IMvCwSG+sUndOMgoj90NcjO1t1W58hyHNDuuGlgChrbbO0QZDdmJh0sHPu8MfwvN7hEo Y9zRjyVVco0jVI/PHCBHGGXvgRxKwhDhh1n67ryyqy2wOMvz5aVohJseNvukBXsqYcmh EAm7lHOQc2rPXPfhv2u3nv7cQGpBsHkPO6w3r1seuDv3owqEcJp7P9OyrRsZYoqXjctE LCwv9FeQhkR3TgQt9sJaNYXjvIIf16SF+rKR+owypo45SzlM0q0Q1e2IK/sD4w7844Ir 59Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732551530; x=1733156330; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mXQbE0T1v2fJwmVq6RAvjEXp4Ag7Di7PPppePVUvnw8=; b=sXsFFk/7AYGPy7l4V01QKhW3w8ubmWiH7vhDFgMPorGam7NxNj/uM109urbMqMYucW IqPmv1vTu6xyrU/cyn2BwXUzIZwSciWG0jJ7cXTl0Qgx5+Zd9LmLda5hOzrHxm7fyNEo MFPTL7FSJvDGthfbZQgUtpaphN2fkoNVtBlbZZxTMf50TvKvwsWdwYRWs3qSw5KeLq3s 9PIurt8Z/HlyEewdkoQ3AXbZiZC56Gq+0JZ+32DyAvV8uK5slrpOkoKTm10+sAwCq/Tf lXmYMLaIGjzAVaQ9VIs5vLi8bKTnZJGawyZT3L+mKd3NYlckmqmlicSuNSm8zKqAqEPh OBZQ== X-Forwarded-Encrypted: i=1; AJvYcCVBMYtZAD4Iqo750SpzZtYZcnni/dvIRYycE4SGC7gtz8dHutBZVZhQQV3KVB+rDdlRHV2GxtKUrg==@kvack.org X-Gm-Message-State: AOJu0Yy/dhE/FLFaKAL0C7+fB4kr/Upbl3Orng7v6/juojp1dOBp7/om DnDA13PCGWwUOjYaN94T7xhluVixIYXlurUn0TxhfYCq6cybVAuSkQ3kln8RbNez+JYvGAStn4q DDWiU7a/oNnxtrXcJS1TUhoJd5xDGTQDwEO5w X-Gm-Gg: ASbGncuB+dgz4pmx9RWhO5KY9Yo7JU4DwSMJ+7hZyYfHEr5/5zf8eZcsMEcG9OGJZ/b CYrMp3xxptuC3RdZkE575ot80p5tyazQ= X-Google-Smtp-Source: AGHT+IFRGABe8UuCauRXseeLtrBztJhWj7HLj+gZpzacy0cROzVdyaPTjiBLKoRlDAdTCCtEEtMIyWV96nvvfVhbrNk= X-Received: by 2002:a05:622a:1b26:b0:461:358e:d635 with SMTP id d75a77b69052e-46672c47a12mr7096701cf.18.1732551529138; Mon, 25 Nov 2024 08:18:49 -0800 (PST) MIME-Version: 1.0 References: <20241122174416.1367052-1-surenb@google.com> <20241122174416.1367052-3-surenb@google.com> <20241125005804.libwzfcz6d5zeyi4@master> In-Reply-To: <20241125005804.libwzfcz6d5zeyi4@master> From: Suren Baghdasaryan Date: Mon, 25 Nov 2024 08:18:38 -0800 Message-ID: Subject: Re: [PATCH v3 3/3] mm: introduce mmap_lock_speculate_{try_begin|retry} To: Wei Yang Cc: akpm@linux-foundation.org, peterz@infradead.org, andrii@kernel.org, jannh@google.com, Liam.Howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, mhocko@kernel.org, shakeel.butt@linux.dev, hannes@cmpxchg.org, david@redhat.com, willy@infradead.org, brauner@kernel.org, oleg@redhat.com, arnd@arndb.de, zhangpeng.00@bytedance.com, linmiaohe@huawei.com, viro@zeniv.linux.org.uk, hca@linux.ibm.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 2E1BD180012 X-Stat-Signature: auq6u611qgoabrqcipmxhsu995zdfqjq X-HE-Tag: 1732551528-226693 X-HE-Meta: U2FsdGVkX1+b4S1EY60oeVDIXKLmkMJhHAxFALhd6ulIBwXjyYcCCYWzoj4KWbD5WtsHv/Ric71rd8zfbhCcpY0xrSNAxcM3ZS77hbknsanhv4QfNyHokRhU7UqXHzbL//0J3V1ejskRHxDpG3G35lWc3bzqGtvZpWnFD3E1i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OS+M+qaBpXcuZpx2Z4eLnCJ3ZT5sLhxP/GBN50l1lfqz+hfkvg4u/V/A7RplDysGfoykFI0jOTHngnOMYJMhxKHCiNyKo1JcbiK7vzsKlsv+SyfSiqag0OQpBGTXzxC/L6L0GZtHrjdmU455LZkQw3KpdkEXlTfPn776gUNjGOhUeHDmTlYZrYSzJjMTJGCQ== 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, Nov 24, 2024 at 4:58=E2=80=AFPM Wei Yang wrote: > > On Fri, Nov 22, 2024 at 09:44:16AM -0800, Suren Baghdasaryan wrote: > >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 > >Reviewed-by: Liam R. Howlett > >--- > >Changes since v2 [1] > >- Added SOB, per Liam Howlett > > > >[1] https://lore.kernel.org/all/20241121162826.987947-3-surenb@google.co= m/ > > > > include/linux/mmap_lock.h | 33 +++++++++++++++++++++++++++++++-- > > 1 file changed, 31 insertions(+), 2 deletions(-) > > > >diff --git a/include/linux/mmap_lock.h b/include/linux/mmap_lock.h > >index 9715326f5a85..8ac3041df053 100644 > >--- a/include/linux/mmap_lock.h > >+++ b/include/linux/mmap_lock.h > >@@ -71,6 +71,7 @@ static inline void mmap_assert_write_locked(const stru= ct mm_struct *mm) > > } > > > > #ifdef CONFIG_PER_VMA_LOCK > >+ > > static inline void mm_lock_seqcount_init(struct mm_struct *mm) > > { > > seqcount_init(&mm->mm_lock_seq); > >@@ -87,11 +88,39 @@ static inline void mm_lock_seqcount_end(struct mm_st= ruct *mm) > > do_raw_write_seqcount_end(&mm->mm_lock_seq); > > } > > > >-#else > >+static inline bool mmap_lock_speculate_try_begin(struct mm_struct *mm, = unsigned int *seq) > >+{ > >+ /* > >+ * Since mmap_lock is a sleeping lock, and waiting for it to beco= me > >+ * unlocked is more or less equivalent with taking it ourselves, = don't > >+ * bother with the speculative path if mmap_lock is already write= -locked > >+ * and take the slow path, which takes the lock. > >+ */ > >+ return raw_seqcount_try_begin(&mm->mm_lock_seq, *seq); > >+} > >+ > >+static inline bool mmap_lock_speculate_retry(struct mm_struct *mm, unsi= gned int seq) > >+{ > >+ return do_read_seqcount_retry(&mm->mm_lock_seq, seq); > > Just curious why we don't use read_seqcount_retry(). > > Looks this is the only user outside seqlock.h. Ah, good eye! read_seqcount_retry() would be better. Peter, do you want me to post a new patchset or you can patch it when picking it up? > > >+} > >+ > >+#else /* CONFIG_PER_VMA_LOCK */ > >+ > > static inline void mm_lock_seqcount_init(struct mm_struct *mm) {} > > static inline void mm_lock_seqcount_begin(struct mm_struct *mm) {} > > static inline void mm_lock_seqcount_end(struct mm_struct *mm) {} > >-#endif > >+ > >+static inline bool mmap_lock_speculate_try_begin(struct mm_struct *mm, = unsigned int *seq) > >+{ > >+ return false; > >+} > >+ > >+static inline bool mmap_lock_speculate_retry(struct mm_struct *mm, unsi= gned int seq) > >+{ > >+ return true; > >+} > >+ > >+#endif /* CONFIG_PER_VMA_LOCK */ > > > > static inline void mmap_init_lock(struct mm_struct *mm) > > { > >-- > >2.47.0.371.ga323438b13-goog > > -- > Wei Yang > Help you, Help me