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 0F90CC4332F for ; Wed, 28 Dec 2022 20:50:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E9DA48E0002; Wed, 28 Dec 2022 15:50:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E4E308E0001; Wed, 28 Dec 2022 15:50:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D3C7E8E0002; Wed, 28 Dec 2022 15:50:35 -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 C3B738E0001 for ; Wed, 28 Dec 2022 15:50:35 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 6C4D8C044A for ; Wed, 28 Dec 2022 20:50:35 +0000 (UTC) X-FDA: 80292908430.23.25DEEBC Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf29.hostedemail.com (Postfix) with ESMTP id DC2DC12000A for ; Wed, 28 Dec 2022 20:50:30 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Wigkmznk; dmarc=none; spf=none (imf29.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1672260633; 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=f5MIKcljMcE7MvfbzWkOdHywhkXeIvtEXmo6zdl9LQ8=; b=ZsfDXyFNr76Lf9pwakU4dptTrvdpVPc1K53Y3pC2+GH/XkPHFUAkznCncX0QkpI4viFQIC bb9z/uAtcibvu3g6XeHBcq3TM1+AQRHIxf3kxOWxYu/9bGKEWEk2sLqp8IdMihA2smnhpa 6U4H73G7BzgaRFaB9qtYfrYnEdptTX4= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Wigkmznk; dmarc=none; spf=none (imf29.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1672260633; a=rsa-sha256; cv=none; b=hjYSAn2KToNLeuFC3VALBW4o1buK6bZbAnDFMXhTSa1Fg/QN+k9hpObn3KUPW8NYOwjXtA RmtcotqGXWElX5LMTp637xoN3ee4igofHj7oh//PVLvCP4668qWwAxtWfNdZz0t5n4Pz/o FarLYTsG7bVObF/k4A5rtCHhPgARKXE= 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-Rspamd-Queue-Id: DC2DC12000A X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: sgfcu4egmkb7jhfy3xuqihcef9u5ci8n X-HE-Tag: 1672260630-158096 X-HE-Meta: U2FsdGVkX1/Cfd37uTvQuGuMKYGsHBlx1+cSXyrpyqcudoOzRNddxItIqTriIp0ukiY9ZrapSq4dE7fEVTJfVp9QFPjRGwoVl5r82uZy52wqsaPQhJrh4yXL3dHN4MQhHX/Od1//q1aZiRAY667Nq/jCJ6s0XM4yKgpyG4XGS9O8Id30xFowmT+6c4Mqqd8OjTCmKclh1WJ9p4houFKlASlONlak09YXwrCW34RBTxcSD2gcnK/73q5d0coEHkknc67zCKD/85TdI1gJUhUrrzBowunnyPAroSBZykzS5MEJiC1fkNB5VT/3OaocnwWu/sm/Yrbr7xpANvKP97fPUuYeRjugtlTTf0oo6BPPCGgLRboOxNcF5mC+ioiJwB+d+vuNFGwVdUJbWKPvnMvtsnu9slZgGd01cmo2KIPHZqsy38nkqUge0VG1IF1eKTFbBCkC46Z8ZnDCsvrX+sjFt7cQCHimOw8EOtabh4RP3Ulamsnh/mf7KGQsp9mPkSGUV7oxkneJQ4/Vc9Kzqt/kEG3R+3BBQWBVdrZzsDs5lGhY4wzx/85tO6BwmWKEk1jPJOQ7gQo9LUwF3LyWXxiM1OJknGv3P3ePI7QWFuRyln6H2EaS0PHCoRPLiEACKw/rSrbXvv70zGiB0R/bsDe+xIUhW4YqlpkKcQUeFnRf9LRoav+OhFsa90HlWFEhLl1AiHyeF4TdAk8AUfXrCBumzTnYp32o47znZJNFK73qCl8J7Lgn0N8YxXTpz0jgXF2nrNFC/CpgGEouV8qyM9+Aaf2xTpOLQHI4yCdmCXQZNbJ5b99FrqYOx7q5JCfW9DevVR6TKGgXEcYsrDRmhxb56WZJk2bvdhrNigWAbXF+Vx4tXUE347UqruMK5s+nnLoJvECGU4vGdmGe8Z+KnQ60fmWjjyO5QlQ04ArA9C7Zd+bZpWVMyup/8U3L6gYujHwyLfdkD1SIr/+gLv9KN18 98w== 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 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.