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 C9785C4332F for ; Thu, 29 Dec 2022 16:51:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EEED58E0002; Thu, 29 Dec 2022 11:51:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E9F1E8E0001; Thu, 29 Dec 2022 11:51:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D66758E0002; Thu, 29 Dec 2022 11:51:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C43348E0001 for ; Thu, 29 Dec 2022 11:51:34 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 861FAA05F8 for ; Thu, 29 Dec 2022 16:51:34 +0000 (UTC) X-FDA: 80295934908.16.2D0BC8A Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf01.hostedemail.com (Postfix) with ESMTP id 8CEC040020 for ; Thu, 29 Dec 2022 16:51:31 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=LmjuFtOE; spf=none (imf01.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1672332692; a=rsa-sha256; cv=none; b=CIBA0YiqJaqSgCRlVdzSX8PfId42iQGAkBDtW63tnwUXRgU3XqIIxfagzwlnIG9pV7fI7r Dj5EZg+ZTcYQpBuKQ6pfGTVYIxFgfjyD+WV5GyyDR7AsLt5pfT48JzxbE9W5KqumfW1DlY EulrEPZcUdE5mhIO1MtMmk7TII88fw0= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=LmjuFtOE; spf=none (imf01.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1672332692; 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=cnL6QnxP/K+nmxQWxJETPtt5kczBdA/yoSQY1DSaqog=; b=7aol1Tq9LuW7Pew+IWQfDdDr28w7MOSaVP4g74HlDUub0W1vvofgguAVYTb3BJ4KHaOr9h ZEpjCYV0XLDSx4yzTSal7wEPnEiF3RB/6pVX28Ihi1U+gO0LlHtNzq27yTkt61aYMYufB3 ZVDLChJdR2VfjtMNULc/JAAAgOybwNQ= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=cnL6QnxP/K+nmxQWxJETPtt5kczBdA/yoSQY1DSaqog=; b=LmjuFtOEV0tPO3SypWjtYP5xI5 JbSCwXzl8GY92DBFc5ltCbDh+uImdIZz7NyKkZOzjnlR5x17U5E66D7TczSXSjxjh0RfHSEU8UsB+ 5waUugrXekLCPzeKeqD9tUaJ1H5sjY3vYYRO+qAjkPFvi4FaZX0N/Isb31s6FYKycr/j/N+BrPN68 aFvhlbilCVcDGvtoR4P8wcTuznUC7g4WuQ7hBbFEb/GeNNEn7UsP+T6JyZxMP3XkPQqB9jcUjPqAe GzQMrCK3SKKmM2aaBq6asRuSt/aFITeSBo39hIkCmTTDw7fYSOZGNmLrnT9OssVThxEAncquxAG7B iZ9nwRGg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pAw81-00A08R-A5; Thu, 29 Dec 2022 16:51:37 +0000 Date: Thu, 29 Dec 2022 16:51:37 +0000 From: Matthew Wilcox To: Hyeonggon Yoo <42.hyeyoo@gmail.com> Cc: linux-mm@kvack.org, liam.howlett@oracle.com, surenb@google.com, ldufour@linux.ibm.com, michel@lespinasse.org, vbabka@suse.cz, linux-kernel@vger.kernel.org Subject: Re: [QUESTION] about the maple tree and current status of mmap_lock scalability Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 8CEC040020 X-Stat-Signature: 4ae5rwnc1ef8eatjw6s56pcsg4otoata X-HE-Tag: 1672332691-25547 X-HE-Meta: U2FsdGVkX18Uehjylp4042/ecXWrIb71yza1lawiiqBoK70dd1ilGbiOGqfwLdGX9vkjLmVglX24PDn/ofadKxK6PjDjLZHF/C5g6X3vo7dIIisefeWsvDnX9YW8rSzUx0Zn4ILzFYcw/fvpDFYP3lgawn0S+0pgwAItH13WwjxZl+FoEG+7/3u43c7VPLH4jAV1/Cgu0YU0Pbj52AF7hb897Wo4hS3UpMqZwdYAVcI4KpywkpQQukp0ZI5+llYiia9onMd00rr5zAQYXfZ2uptJGnTAl2haVOhJnTlEV4/c0FF8fbg7HC5yoiFpwdNfQGWGJsDomF2+UOsrCRUIwtHaiV21+FIayXY02t0hCUaRr94b36syTJ94JNaFcYezGnLSz2ZNF05IrrqZRp1nB3xUI1Chtvnt1lGsCSRKeuFF5J02F6q/Kc/muC6U86HZafoh9a/tAIJdilI+ZxyRNacEfrcIDkIHP7LApR40R5tHKq1fQYiuUs5J6OBGP/z+AB7pS2wV+LTSjdq7Re9MmVwjV0i3Tq3Z8JVyZMYhduaRM7M9af1/eSEjNp9+uYde/3+JLVGyYg0wVwDwj+bLkiwel1jE/vdI/ydUVIrvS6EVaSVQHfkLzu+/M5Uh06LUavOEKaZ8Kbqf41VdjKpXt+SYXlTLoUpzEhyjD36Tv8hm0AJTfzBhDddd1iaMlSDt1W3PZeaNxMZcfKYD6Vo/GdP4Txtg3yM6Mll4oshW0UXFbyN1U6jlRObaKM7aSM0y2pxzYnBqNE+n23RVdZ0C2Gwi9Q2KUBT5aDojjqhXH7IyhEyxX/Ub+cP/XvR49ZcR8DH0LDAsyR7BiTS3x9vlFQVRx8rVjOuDJsujRJOmPn+qlOIUajB6Q48cuH71k5fnzMs3AGu/7r60sWlyrKmbczvKk4txP/NUHq42XhCcRAiDGx9knoAGyDEEQCtft3Ay1xWBj3bNtScayogvXPW HsA== 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: On Thu, Dec 29, 2022 at 11:22:28PM +0900, Hyeonggon Yoo wrote: > On Wed, Dec 28, 2022 at 08:50:36PM +0000, Matthew Wilcox wrote: > > The long term goal is even larger than this. Ideally, the VMA tree > > would be protected by a spinlock rather than a mutex. > > You mean replacing mmap_lock rwsem with a spinlock? > How is that possible if readers can take it for page fault? The mmap_lock is taken for many, many things. So the plan was to have a spinlock in the maple tree (indeed, there's still one there; it's just in a union with the lockdep_map_p). VMA readers would walk the tree protected only by RCU; VMA writers would take the spinlock while modifying the tree. The work Suren, Liam & I are engaged in still uses the mmap semaphore for writers, but we do walk the tree under RCU protection. > > While I've read the RCUVM paper, I wouldn't say it was particularly an > > inspiration. The Maple Tree is independent of the VM; it's a general > > purpose B-tree. > > My intention was to ask how to synchronize with other VMA operations > after the tree traversal with RCU. (Because it's unreasonable to handle > page fault in RCU read-side critical section) > > Per-VMA lock seem to solve it by taking the VMA lock in read mode within > RCU read-side critical section. Right, but it's a little more complex than that. The real "lock" on the VMA is actually a sequence count. https://lwn.net/Articles/906852/ does a good job of explaining it, but the VMA lock is really there as a convenient way for the writer to wait for readers to be sufficiently "finished" with handling the page fault that any conflicting changes will be correctly retired. https://www.infradead.org/~willy/linux/store-free-page-faults.html outlines how I intend to proceed from Suren's current scheme (where RCU is only used to protect the tree walk) to using RCU for the entire page fault.