Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp6200538rwl; Thu, 29 Dec 2022 08:56:16 -0800 (PST) X-Google-Smtp-Source: AMrXdXsdP0nxf9Gok/iLRyB2sTmYRzP+sN2z4dDjKLzJZNBKqWEuBuo+0V/br5eqlKdWgBolm1yF X-Received: by 2002:a17:906:7747:b0:7c1:1804:a0c7 with SMTP id o7-20020a170906774700b007c11804a0c7mr24049096ejn.75.1672332976376; Thu, 29 Dec 2022 08:56:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672332976; cv=none; d=google.com; s=arc-20160816; b=Z4EU4S0UsFFDQq8DKfLpLoauxTLPElL7ncOIZPYpp0t8Z9qS+Rq8DxSYEuy6lEjswN 2v/JKDBE0eYC5pIsLUvyJIRhQyDB0FI1Dw3ESqPjDLr/eeSMEiQbc73uxVMaEdJxKOBK 2fDZGZ6prr5Cv0huiYVRSiEx/3BXmBjUwu5e6hAdmPhBem0fDlVNSecLzy8CudaJJw2k 9H20ter1OAM5pYUbD4kjM35QCb0e/sFkvJGd87oh6Xe/Z3sV5ggL68q0wA23Tp0VIihu zrcePH1rmAiz7UNDI1cWuKeFGjIEVItfXj4uTPNpktbsA9qkUIL/4VgsH6ImOgJpsOLh j5ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=cnL6QnxP/K+nmxQWxJETPtt5kczBdA/yoSQY1DSaqog=; b=IDDOujHit/B0E9+/4yMEripOkMWcyaZgIVRnHCjjyj+w5xqS6/wDoS5Twya/dNDbwA B/WSdcp7aIgirNRMNQBJo3TV1mmJ0B8ONPxDOxEJu9ES9ilJUeCYWTqSDd10VZnHyd8F chNQfBUaEj9r8tqOD2wy2LrrCFq0HU3AhSvwH+Dy1jP+abwVFN4ppNtg+sd8GYIgUEOV JVXG/NezF6jZz17Wpd7ITc2/glBsk+mmP5h1MjrE2OcVT06rTCSKJmgbmvtHkHPXfMl1 31zBscbDxFFHdiMmBb7eBqkWtxg1g9W7vcNJkvLG/aTW+i4saTJShY/Pr/2/Oe3IGiK1 Ln0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=LmjuFtOE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id go37-20020a1709070da500b007ad945aa04asi16606713ejc.678.2022.12.29.08.55.54; Thu, 29 Dec 2022 08:56:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=LmjuFtOE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231336AbiL2Qvp (ORCPT + 61 others); Thu, 29 Dec 2022 11:51:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233409AbiL2Qvn (ORCPT ); Thu, 29 Dec 2022 11:51:43 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E81C9DF88 for ; Thu, 29 Dec 2022 08:51:41 -0800 (PST) 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-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.