Skip to contentSkip to conversation

maple-tree-add-new-data-structure.patch removed from -mm tree

merged mm-stable Andrew Morton 1 participant 1 message Sep 27, 2022

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: Maple Tree: add new data structure
has been removed from the -mm tree. Its filename was
maple-tree-add-new-data-structure.patch

This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: "Liam R. Howlett" <[email protected]>
Subject: Maple Tree: add new data structure
Date: Tue, 6 Sep 2022 19:48:39 +0000

Patch series "Introducing the Maple Tree"

The maple tree is an RCU-safe range based B-tree designed to use modern processor cache efficiently. There are a number of places in the kernel that a non-overlapping range-based tree would be beneficial, especially one with a simple interface. If you use an rbtree with other data structures to improve performance or an interval tree to track non-overlapping ranges, then this is for you.

The tree has a branching factor of 10 for non-leaf nodes and 16 for leaf nodes. With the increased branching factor, it is significantly shorter than the rbtree so it has fewer cache misses. The removal of the linked list between subsequent entries also reduces the cache misses and the need to pull in the previous and next VMA during many tree alterations.

The first user that is covered in this patch set is the vm_area_struct, where three data structures are replaced by the maple tree: the augmented rbtree, the vma cache, and the linked list of VMAs in the mm_struct. The long term goal is to reduce or remove the mmap_lock contention.

The plan is to get to the point where we use the maple tree in RCU mode. Readers will not block for writers. A single write operation will be allowed at a time. A reader re-walks if stale data is encountered. VMAs would be RCU enabled and this mode would be entered once multiple tasks are using the mm_struct.

Davidlor said

: Yes I like the maple tree, and at this stage I don't think we can ask for : more from this series wrt the MM - albeit there seems to still be some : folks reporting breakage. Fundamentally I see Liam's work to (re)move : complexity out of the MM (not to say that the actual maple tree is not : complex) by consolidating the three complimentary data structures very : much worth it considering performance does not take a hit. This was very : much a turn off with the range locking approach, which worst case scenario : incurred in prohibitive overhead. Also as Liam and Matthew have : mentioned, RCU opens up a lot of nice performance opportunities, and in : addition academia[1] has shown outstanding scalability of address spaces : with the foundation of replacing the locked rbtree with RCU aware trees.

A similar work has been discovered in the academic press

https://pdos.csail.mit.edu/papers/rcuvm:asplos12.pdf

Sheer coincidence. We designed our tree with the intention of solving the hardest problem first. Upon settling on a b-tree variant and a rough outline, we researched ranged based b-trees and RCU b-trees and did find that article. So it was nice to find reassurances that we were on the right path, but our design choice of using ranges made that paper unusable for us.

This patch (of 70):

The maple tree is an RCU-safe range based B-tree designed to use modern processor cache efficiently. There are a number of places in the kernel that a non-overlapping range-based tree would be beneficial, especially one with a simple interface. If you use an rbtree with other data structures to improve performance or an interval tree to track non-overlapping ranges, then this is for you.

The tree has a branching factor of 10 for non-leaf nodes and 16 for leaf nodes. With the increased branching factor, it is significantly shorter than the rbtree so it has fewer cache misses. The removal of the linked list between subsequent entries also reduces the cache misses and the need to pull in the previous and next VMA during many tree alterations.

The first user that is covered in this patch set is the vm_area_struct, where three data structures are replaced by the maple tree: the augmented rbtree, the vma cache, and the linked list of VMAs in the mm_struct. The long term goal is to reduce or remove the mmap_lock contention.

The plan is to get to the point where we use the maple tree in RCU mode. Readers will not block for writers. A single write operation will be allowed at a time. A reader re-walks if stale data is encountered. VMAs would be RCU enabled and this mode would be entered once multiple tasks are using the mm_struct.

There is additional BUG_ON() calls added within the tree, most of which are in debug code. These will be replaced with a WARN_ON() call in the future. There is also additional BUG_ON() calls within the code which will also be reduced in number at a later date. These exist to catch things such as out-of-range accesses which would crash anyways.

---

 Documentation/core-api/index.rst                   |    1 
 Documentation/core-api/maple_tree.rst              |  217 
 MAINTAINERS                                        |   12 
 include/linux/maple_tree.h                         |  685 +
 include/trace/events/maple_tree.h                  |  123 
 init/main.c                                        |    2 
 lib/Kconfig.debug                                  |   15 
 lib/Makefile                                       |    2 
 lib/maple_tree.c                                   | 7130 +++++++++++
 tools/testing/radix-tree/.gitignore                |    2 
 tools/testing/radix-tree/generated/autoconf.h      |    1 
 tools/testing/radix-tree/linux/maple_tree.h        |    7 
 tools/testing/radix-tree/maple.c                   |   59 
 tools/testing/radix-tree/trace/events/maple_tree.h |    5 
 14 files changed, 8260 insertions(+), 1 deletion(-)
Documentation/core-api/index.rst renamed from Documentation/core-api/index.rst~maple-tree-add-new-data-structure +1 -0
@@ -36,6 +36,7 @@ Library functionality that is used throu
    kref
    assoc_array
    xarray
+   maple_tree
    idr
    circular-buffers
    rbtree
Documentation/core-api/maple_tree.rst new file +217 -0

217 lines not on this page · raw message

include/linux/maple_tree.h new file +685 -0

685 lines not on this page · raw message

include/trace/events/maple_tree.h new file +123 -0

123 lines not on this page · raw message

init/main.c renamed from init/main.c~maple-tree-add-new-data-structure +2 -0
@@ -117,6 +117,7 @@ static int kernel_init(void *);
 
 extern void init_IRQ(void);
 extern void radix_tree_init(void);
+extern void maple_tree_init(void);
 
 /*
  * Debug helper: via this flag we know that we are in 'early bootup code'
@@ -1005,6 +1006,7 @@ asmlinkage __visible void __init __no_sa
 		 "Interrupts were enabled *very* early, fixing it\n"))
 		local_irq_disable();
 	radix_tree_init();
+	maple_tree_init();
 
 	/*
 	 * Set up housekeeping before setting up workqueues to allow the unbound
lib/Kconfig.debug renamed from lib/Kconfig.debug~maple-tree-add-new-data-structure +15 -0
@@ -820,6 +820,13 @@ config DEBUG_VM_VMACACHE
 	  can cause significant overhead, so only enable it in non-production
 	  environments.
 
+config DEBUG_VM_MAPLE_TREE
+	bool "Debug VM maple trees"
+	depends on DEBUG_VM
+	select DEBUG_MAPLE_TREE
+	help
+	  Enable VM maple tree debugging information and extra validations.
+
 	  If unsure, say N.
 
 config DEBUG_VM_RB
@@ -1635,6 +1642,14 @@ config BUG_ON_DATA_CORRUPTION
 
 	  If unsure, say N.
 
+config DEBUG_MAPLE_TREE
+	bool "Debug maple trees"
+	depends on DEBUG_KERNEL
+	help
+	  Enable maple tree debugging information and extra validations.
+
+	  If unsure, say N.
+
 endmenu
 
 config DEBUG_CREDENTIALS
lib/Makefile renamed from lib/Makefile~maple-tree-add-new-data-structure +1 -1
@@ -29,7 +29,7 @@ endif
 
 lib-y := ctype.o string.o vsprintf.o cmdline.o \
 	 rbtree.o radix-tree.o timerqueue.o xarray.o \
-	 idr.o extable.o irq_regs.o argv_split.o \
+	 maple_tree.o idr.o extable.o irq_regs.o argv_split.o \
 	 flex_proportions.o ratelimit.o show_mem.o \
 	 is_single_threaded.o plist.o decompress.o kobject_uevent.o \
 	 earlycpio.o seq_buf.o siphash.o dec_and_lock.o \
lib/maple_tree.c new file +7130 -0

1,919 lines not on this page · raw message

MAINTAINERS renamed from MAINTAINERS~maple-tree-add-new-data-structure +12 -0

Lines of this file are not shown. View the raw message.

tools/testing/radix-tree/generated/autoconf.h renamed from tools/testing/radix-tree/generated/autoconf.h~maple-tree-add-new-data-structure +1 -0

Lines of this file are not shown. View the raw message.

tools/testing/radix-tree/.gitignore renamed from tools/testing/radix-tree/.gitignore~maple-tree-add-new-data-structure +2 -0

Lines of this file are not shown. View the raw message.

tools/testing/radix-tree/linux/maple_tree.h new file +7 -0

Lines of this file are not shown. View the raw message.

tools/testing/radix-tree/maple.c new file +59 -0

59 lines not on this page · raw message

tools/testing/radix-tree/trace/events/maple_tree.h new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

_

Patches currently in -mm which might be from [email protected] are

Part of the diff is not shown here. View the raw message.