Commit Graph

6 Commits

Author SHA1 Message Date
Nico Pache d5392be061 maple_tree: reorganize testing to restore module testing
Conflicts:
       lib/Kconfig.debug: was not expecting TEST_XARRAY config

commit 120b116208a0877227fc82e3f0df81e7a3ed4ab1
Author: Liam Howlett <liam.howlett@oracle.com>
Date:   Fri Oct 28 18:04:30 2022 +0000

    maple_tree: reorganize testing to restore module testing

    Along the development cycle, the testing code support for module/in-kernel
    compiles was removed.  Restore this functionality by moving any internal
    API tests to the userspace side, as well as threading tests.  Fix the
    lockdep issues and add a way to reduce memory usage so the tests can
    complete with KASAN + memleak detection.  Make the tests work on 32 bit
    hosts where possible and detect 32 bit hosts in the radix test suite.

    [akpm@linux-foundation.org: fix module export]
    [akpm@linux-foundation.org: fix it some more]
    [liam.howlett@oracle.com: fix compile warnings on 32bit build in check_find()]
      Link: https://lkml.kernel.org/r/20221107203816.1260327-1-Liam.Howlett@oracle.com
    Link: https://lkml.kernel.org/r/20221028180415.3074673-1-Liam.Howlett@oracle.com
    Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2166668
Signed-off-by: Nico Pache <npache@redhat.com>
2023-03-07 01:23:55 -07:00
Nico Pache d0b81c5b5a Maple Tree: add new data structure
Conflicts:
       lib/Makefile: slight makefile conflict

commit 54a611b605901c7d5d05b6b8f5d04a6ceb0962aa
Author: Liam R. Howlett <Liam.Howlett@Oracle.com>
Date:   Tue Sep 6 19:48:39 2022 +0000

    Maple Tree: add new data structure

    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.

    Link: https://lkml.kernel.org/r/20220906194824.2110408-1-Liam.Howlett@oracle.com
    Link: https://lkml.kernel.org/r/20220906194824.2110408-2-Liam.Howlett@oracle.com
    Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
    Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
    Tested-by: David Howells <dhowells@redhat.com>
    Tested-by: Sven Schnelle <svens@linux.ibm.com>
    Tested-by: Yu Zhao <yuzhao@google.com>
    Cc: Vlastimil Babka <vbabka@suse.cz>
    Cc: David Hildenbrand <david@redhat.com>
    Cc: Davidlohr Bueso <dave@stgolabs.net>
    Cc: Catalin Marinas <catalin.marinas@arm.com>
    Cc: SeongJae Park <sj@kernel.org>
    Cc: Will Deacon <will@kernel.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2166668
Signed-off-by: Nico Pache <npache@redhat.com>
2023-03-07 01:23:54 -07:00
Matthew Wilcox 3a08cd52c3 radix tree: Remove multiorder support
All users have now been converted to the XArray.  Removing the support
reduces code size and ensures new users will use the XArray instead.

Signed-off-by: Matthew Wilcox <willy@infradead.org>
2018-10-21 10:46:48 -04:00
Matthew Wilcox 02c02bf12c xarray: Change definition of sibling entries
Instead of storing a pointer to the slot containing the canonical entry,
store the offset of the slot.  Produces slightly more efficient code
(~300 bytes) and simplifies the implementation.

Signed-off-by: Matthew Wilcox <willy@infradead.org>
Reviewed-by: Josef Bacik <jbacik@fb.com>
2018-09-29 22:47:49 -04:00
Matthew Wilcox bfa11193c4 radix tree test suite: Remove obsolete CONFIG
radix-tree.c doesn't use these CONFIG options any more.

Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
Reviewed-by: Rehas Sachdeva <aquannie@gmail.com>
2017-02-13 16:09:43 -05:00
Ross Zwisler 21ef533931 radix-tree: add support for multi-order iterating
This enables the macros radix_tree_for_each_slot() and friends to be
used with multi-order entries.

The way that this works is that we treat all entries in a given slots[]
array as a single chunk.  If the index given to radix_tree_next_chunk()
happens to point us to a sibling entry, we will back up iter->index so
that it points to the canonical entry, and that will be the place where
we start our iteration.

As we're processing a chunk in radix_tree_next_slot(), we process
canonical entries, skip over sibling entries, and restart the chunk
lookup if we find a non-sibling indirect pointer.  This drops back to
the radix_tree_next_chunk() code, which will re-walk the tree and look
for another chunk.

This allows us to properly handle multi-order entries mixed with other
entries that are at various heights in the radix tree.

Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
Signed-off-by: Matthew Wilcox <willy@linux.intel.com>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Kirill Shutemov <kirill.shutemov@linux.intel.com>
Cc: Jan Kara <jack@suse.com>
Cc: Neil Brown <neilb@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-05-20 17:58:30 -07:00