Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp5111429rwl; Wed, 28 Dec 2022 13:09:46 -0800 (PST) X-Google-Smtp-Source: AMrXdXsDkwvdUWkm3cAL337HyKQ0e2C/ppKfAEyiv1fzIqPvhdXboHoQI1waqKc5Nw8TgG0qtCT/ X-Received: by 2002:a17:902:cf01:b0:18b:3389:2caf with SMTP id i1-20020a170902cf0100b0018b33892cafmr53201183plg.59.1672261786214; Wed, 28 Dec 2022 13:09:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672261786; cv=none; d=google.com; s=arc-20160816; b=yyfhH4J2cQJJdv07SsNw6GMg8cRhrl0Q+5fMR4telIpAc339T4MuYP1hpgzVf1iAKT twMZVLrfrlgG4Bbb4VFl/ikwnaoA9II+NvR+J39AhAr7IHNtK9HpR0WLNm6Z50n8fkQ/ HnjcWK/m1MqW3AmMP9UiBhgcrJwEzrUNJ2bEM+AUb+MFejDQQgaVh+7PCOYmLAEapwNd v7LPDtW9ot8qr0f3BZ1xblvOCI4Je35LzLo9vYO1rW3DzqiGc4v1J1AmZGq6iiRpw/H3 hbQ9LOHDtomv0NYr9+CYiHZWZJ164zrQOXP0VI7j8+cGuvMav89uvqMw5zb7eC2PfSt6 vo8w== 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=f5MIKcljMcE7MvfbzWkOdHywhkXeIvtEXmo6zdl9LQ8=; b=UnhDXXsLQe1M53iUmVxefX8kZict36cEPT5Y5Hc3kx4lbONo31bFOmKWld2JXXsQnN zlzi7qoNbhxle1611/4QT26U3ZyfjMXDYCSIyBvCfhv31/gGUwcbycqii8UThTwO+fqH 2HG6yAX9Ue2c+mzZO38k4t35ugvi+rFkbFYoSMX8mTTeqWs30uWtZptXPMtTiQFPE+WE JO3iLSnv7lyCI8eFyeZpLa7UHq4E4rAw6kz2uuC4/Xa4KMBbraHsHW7vMZA68+g9147X TT/Cqha3Qv8BuOKvCe54268OY+1msy9LHBUbpzH4ve5+jFhm4gqbKSeaSGKYiJjw/br0 60sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Wigkmznk; 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 x10-20020a63db4a000000b00463e9f26c48si17717257pgi.177.2022.12.28.13.09.37; Wed, 28 Dec 2022 13:09:46 -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=Wigkmznk; 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 S230486AbiL1Uuw (ORCPT + 62 others); Wed, 28 Dec 2022 15:50:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229668AbiL1Uuu (ORCPT ); Wed, 28 Dec 2022 15:50:50 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C746212A8B for ; Wed, 28 Dec 2022 12:50: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=f5MIKcljMcE7MvfbzWkOdHywhkXeIvtEXmo6zdl9LQ8=; b=WigkmznklbBaMTp0pO+NktJkdC C0sozicZLpHWh40cEB8nAniR+BhkVcdcHqmITf3ej6X3mp2apCnPArdPZSuWqvV8XvcLX2BUUFgK5 cIZkTMjuE9ZpSIFc7rNTPif1WxDcd8+rxJJDncIeicUjOehoZ0PEHYwxKg0VeZVGr6G2WmsF4j0LF jRUk1EIBgVatyhqKiXQNqmIxrI7AB3nM3tCzMOSIrppuf/rtIxY6cA9PRAR7C4VujPRpsHNWC7Mkv MN8acv8vbQgfbk3ktn8HVX4yZ0XzAhXCME0DPSpicmf43xvVOLRiN2aCx51809WjFOve3PMekmMcB aXO0/VVg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pAdNk-009Nk8-Gs; Wed, 28 Dec 2022 20:50:36 +0000 Date: Wed, 28 Dec 2022 20:50:36 +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=-2.7 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,URI_DOTEDU 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 Wed, Dec 28, 2022 at 09:48:51PM +0900, Hyeonggon Yoo wrote: > Hello mm folks, > > I have a few questions about the current status of mmap_lock scalability. > > ============================================================= > What is currently causing the kernel to use mmap_lock to protect the maple tree? > ============================================================= > > I understand that the long-term goal is to remove the need for mmap_lock in readers > while traversing the maple tree, using techniques such as RCU or SPF. > What is the biggest obstacle preventing this from being achieved at this time? The long term goal is even larger than this. Ideally, the VMA tree would be protected by a spinlock rather than a mutex. That turned out to be too large a change for the moment (and isn't all that important compared to enabling RCU readers) > ================================================== > How does the maple tree provide RCU-safe manipulation of VMAs? > ================================================== > > Is it similar to the approach suggested in the RCUVM paper (replacing the original > root node with a new root node that shares most of its nodes and deferring > the freeing of stale nodes using RCU)? > > I'm having difficulty understanding the design of the maple tree in this regard. > > [RCUVM paper] https://pdos.csail.mit.edu/papers/rcuvm:asplos12.pdf 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. As with any B-tree, when modifying a node, we don't touch nodes that we don't need to touch. As with any RCU data structure, we defer freeing things while RCU readers might still have a reference to them. We don't necessarily go all the way to the root node when modifying a leaf node. For example, if we have this structure: Root: Node A, 4000, Node B Node A: p1, 50, p2, 100, p3, 150, p4, 200, NULL, 250, p6, 1000, p7 Node B: p8, 4050, p9, 4100, p10, 4150, p11, 4200, NULL, 4250, p13 and we replace p4 with a NULL over the whole range from 150-199, we construct a new Node A2 that contains: Node A2: p1, 50, p2, 100, p3, 150, NULL, 250, p6, 1000, p7 and we simply write A2 over the entry in Root. Then we mark Node A as dead and RCU-free Node A. There's no need to replace Root as stores to a pointer are atomic. If we need to rebalance between Node A and Node B, we will need to create a new Root (as well as both A and B), mark all of them as dead and RCU-free them.