linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Hyeonggon Yoo <42.hyeyoo@gmail.com>
To: Matthew Wilcox <willy@infradead.org>
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
Date: Thu, 29 Dec 2022 23:22:28 +0900	[thread overview]
Message-ID: <Y62ipKlWGEbJZKXv@hyeyoo> (raw)
In-Reply-To: <Y6ysHNPvKayTfeq8@casper.infradead.org>

On Wed, Dec 28, 2022 at 08:50:36PM +0000, Matthew Wilcox wrote:
> 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. 

You mean replacing mmap_lock rwsem with a spinlock?
How is that possible if readers can take it for page fault?

> That turned out
> to be too large a change for the moment (and isn't all that important
> compared to enabling RCU readers)

Yeah, better to take one step at a time.

> 
> > ==================================================
> > 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.

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.

> 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.

Thank you for explaining things in an easy and intuitive way.
Okay, I get it's not a big problem to update the value(s) in a
B-tree in RCU-safe way.

> 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.

-- 
Thanks,
Hyeonggon


  reply	other threads:[~2022-12-29 14:22 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-28 12:48 [QUESTION] about the maple tree and current status of mmap_lock scalability Hyeonggon Yoo
2022-12-28 17:10 ` Suren Baghdasaryan
2022-12-29 11:33   ` Hyeonggon Yoo
2022-12-28 20:50 ` Matthew Wilcox
2022-12-29 14:22   ` Hyeonggon Yoo [this message]
2022-12-29 16:51     ` Matthew Wilcox
2022-12-29 17:10       ` Lorenzo Stoakes
2022-12-29 17:21         ` Suren Baghdasaryan
2022-12-29 17:31         ` Matthew Wilcox
2023-01-02 12:04       ` Hyeonggon Yoo
2023-01-02 14:37         ` Matthew Wilcox
2023-02-20 14:26           ` Hyeonggon Yoo
2023-02-20 14:43             ` Matthew Wilcox
2023-02-22 11:38               ` Hyeonggon Yoo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y62ipKlWGEbJZKXv@hyeyoo \
    --to=42.hyeyoo@gmail.com \
    --cc=ldufour@linux.ibm.com \
    --cc=liam.howlett@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=michel@lespinasse.org \
    --cc=surenb@google.com \
    --cc=vbabka@suse.cz \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).