05 Dec, 2019

2 commits

  • After move parent assignment out, we can check the color directly.

    Link: http://lkml.kernel.org/r/20191028021442.5450-2-richardw.yang@linux.intel.com
    Signed-off-by: Wei Yang
    Acked-by: Peter Zijlstra (Intel)
    Reviewed-by: Michel Lespinasse
    Reviewed-by: Davidlohr Bueso
    Cc: Thomas Gleixner
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Wei Yang
     
  • Both in Case 2 and 3, we exchange n and s. This mean no matter whether
    child2 is NULL or not, successor's parent should be assigned to node's.

    This patch takes this step out to make it explicit and reduce the
    ambiguity.

    Besides, this step reduces some symbol size like rb_erase().

    KERN_CONFIG upstream patched
    OPT_FOR_PERF 877 870
    OPT_FOR_SIZE 635 621

    Link: http://lkml.kernel.org/r/20191028021442.5450-1-richardw.yang@linux.intel.com
    Signed-off-by: Wei Yang
    Acked-by: Peter Zijlstra (Intel)
    Reviewed-by: Michel Lespinasse
    Reviewed-by: Davidlohr Bueso
    Cc: Thomas Gleixner
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Wei Yang
     

26 Sep, 2019

3 commits

  • Change the definition of the RBCOMPUTE function. The propagate callback
    repeatedly calls RBCOMPUTE as it moves from leaf to root. it wants to
    stop recomputing once the augmented subtree information doesn't change.
    This was previously checked using the == operator, but that only works
    when the augmented subtree information is a scalar field. This commit
    modifies the RBCOMPUTE function so that it now sets the augmented subtree
    information instead of returning it, and returns a boolean value
    indicating if the propagate callback should stop.

    The motivation for this change is that I want to introduce augmented
    rbtree uses where the augmented data for the subtree is a struct instead
    of a scalar.

    Link: http://lkml.kernel.org/r/20190703040156.56953-4-walken@google.com
    Signed-off-by: Michel Lespinasse
    Acked-by: Peter Zijlstra (Intel)
    Cc: David Howells
    Cc: Davidlohr Bueso
    Cc: Uladzislau Rezki
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Michel Lespinasse
     
  • Add RB_DECLARE_CALLBACKS_MAX, which generates augmented rbtree callbacks
    for the case where the augmented value is a scalar whose definition
    follows a max(f(node)) pattern. This actually covers all present uses of
    RB_DECLARE_CALLBACKS, and saves some (source) code duplication in the
    various RBCOMPUTE function definitions.

    [walken@google.com: fix mm/vmalloc.c]
    Link: http://lkml.kernel.org/r/CANN689FXgK13wDYNh1zKxdipeTuALG4eKvKpsdZqKFJ-rvtGiQ@mail.gmail.com
    [walken@google.com: re-add check to check_augmented()]
    Link: http://lkml.kernel.org/r/20190727022027.GA86863@google.com
    Link: http://lkml.kernel.org/r/20190703040156.56953-3-walken@google.com
    Signed-off-by: Michel Lespinasse
    Acked-by: Peter Zijlstra (Intel)
    Cc: David Howells
    Cc: Davidlohr Bueso
    Cc: Uladzislau Rezki
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Michel Lespinasse
     
  • Patch series "make RB_DECLARE_CALLBACKS more generic", v3.

    These changes are intended to make the RB_DECLARE_CALLBACKS macro more
    generic (allowing the aubmented subtree information to be a struct instead
    of a scalar).

    I have verified the compiled lib/interval_tree.o and mm/mmap.o files to
    check that they didn't change. This held as expected for interval_tree.o;
    mmap.o did have some changes which could be reverted by marking
    __vma_link_rb as noinline. I did not add such a change to the patchset; I
    felt it was reasonable enough to leave the inlining decision up to the
    compiler.

    This patch (of 3):

    Add a short comment summarizing the arguments to RB_DECLARE_CALLBACKS.
    The arguments are also now capitalized. This copies the style of the
    INTERVAL_TREE_DEFINE macro.

    No functional changes in this commit, only comments and capitalization.

    Link: http://lkml.kernel.org/r/20190703040156.56953-2-walken@google.com
    Signed-off-by: Michel Lespinasse
    Acked-by: Davidlohr Bueso
    Acked-by: Peter Zijlstra (Intel)
    Cc: David Howells
    Cc: Uladzislau Rezki
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Michel Lespinasse
     

17 Jul, 2019

1 commit

  • As was already noted in rbtree.h, the logic to cache rb_first (or
    rb_last) can easily be implemented externally to the core rbtree api.

    Change the implementation to do just that. Previously the update of
    rb_leftmost was wired deeper into the implmentation, but there were some
    disadvantages to that - mostly, lib/rbtree.c had separate instantiations
    for rb_insert_color() vs rb_insert_color_cached(), as well as rb_erase()
    vs rb_erase_cached(), which were doing exactly the same thing save for
    the rb_leftmost update at the start of either function.

    text data bss dec hex filename
    5405 120 0 5525 1595 lib/rbtree.o-vanilla
    3827 96 0 3923 f53 lib/rbtree.o-patch

    [dave@stgolabs.net: changelog addition]
    Link: http://lkml.kernel.org/r/20190628171416.by5gdizl3rcxk5h5@linux-r8p5
    [akpm@linux-foundation.org: coding-style fixes]
    Link: http://lkml.kernel.org/r/20190628045008.39926-1-walken@google.com
    Signed-off-by: Michel Lespinasse
    Acked-by: Davidlohr Bueso
    Acked-by: Peter Zijlstra (Intel)
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Michel Lespinasse
     

31 May, 2019

1 commit

  • Based on 1 normalized pattern(s):

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license as published by
    the free software foundation either version 2 of the license or at
    your option any later version this program is distributed in the
    hope that it will be useful but without any warranty without even
    the implied warranty of merchantability or fitness for a particular
    purpose see the gnu general public license for more details you
    should have received a copy of the gnu general public license along
    with this program if not write to the free software foundation inc
    59 temple place suite 330 boston ma 02111 1307 usa

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-or-later

    has been chosen to replace the boilerplate/reference in 1334 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Allison Randal
    Reviewed-by: Richard Fontana
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190527070033.113240726@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

31 Oct, 2018

1 commit


12 May, 2018

1 commit

  • Since commit c1adf20052d8 ("Introduce rb_replace_node_rcu()")
    rbtree_augmented.h uses RCU related data structures but does not include
    the header file. It works as long as it gets somehow included before
    that and fails otherwise.

    Link: http://lkml.kernel.org/r/20180504103159.19938-1-bigeasy@linutronix.de
    Signed-off-by: Sebastian Andrzej Siewior
    Reviewed-by: Andrew Morton
    Cc: David Howells
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Sebastian Andrzej Siewior
     

09 Sep, 2017

1 commit

  • Patch series "rbtree: Cache leftmost node internally", v4.

    A series to extending rbtrees to internally cache the leftmost node such
    that we can have fast overlap check optimization for all interval tree
    users[1]. The benefits of this series are that:

    (i) Unify users that do internal leftmost node caching.
    (ii) Optimize all interval tree users.
    (iii) Convert at least two new users (epoll and procfs) to the new interface.

    This patch (of 16):

    Red-black tree semantics imply that nodes with smaller or greater (or
    equal for duplicates) keys always be to the left and right,
    respectively. For the kernel this is extremely evident when considering
    our rb_first() semantics. Enabling lookups for the smallest node in the
    tree in O(1) can save a good chunk of cycles in not having to walk down
    the tree each time. To this end there are a few core users that
    explicitly do this, such as the scheduler and rtmutexes. There is also
    the desire for interval trees to have this optimization allowing faster
    overlap checking.

    This patch introduces a new 'struct rb_root_cached' which is just the
    root with a cached pointer to the leftmost node. The reason why the
    regular rb_root was not extended instead of adding a new structure was
    that this allows the user to have the choice between memory footprint
    and actual tree performance. The new wrappers on top of the regular
    rb_root calls are:

    - rb_first_cached(cached_root) -- which is a fast replacement
    for rb_first.

    - rb_insert_color_cached(node, cached_root, new)

    - rb_erase_cached(node, cached_root)

    In addition, augmented cached interfaces are also added for basic
    insertion and deletion operations; which becomes important for the
    interval tree changes.

    With the exception of the inserts, which adds a bool for updating the
    new leftmost, the interfaces are kept the same. To this end, porting rb
    users to the cached version becomes really trivial, and keeping current
    rbtree semantics for users that don't care about the optimization
    requires zero overhead.

    Link: http://lkml.kernel.org/r/20170719014603.19029-2-dave@stgolabs.net
    Signed-off-by: Davidlohr Bueso
    Reviewed-by: Jan Kara
    Acked-by: Peter Zijlstra (Intel)
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Davidlohr Bueso
     

25 Feb, 2017

1 commit

  • Prepare to mark sensitive kernel structures for randomization by making
    sure they're using designated initializers. These were identified
    during allyesconfig builds of x86, arm, and arm64, with most initializer
    fixes extracted from grsecurity.

    Link: http://lkml.kernel.org/r/20161217010253.GA140470@beast
    Signed-off-by: Kees Cook
    Acked-by: Peter Zijlstra (Intel)
    Cc: David Howells
    Cc: Jie Chen
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kees Cook
     

06 Jul, 2016

1 commit


28 May, 2015

1 commit

  • Change the insert and erase code such that lockless searches are
    non-fatal.

    In and of itself an rbtree cannot be correctly searched while
    in-modification, we can however provide weaker guarantees that will
    allow the rbtree to be used in conjunction with other techniques, such
    as latches; see 9b0fd802e8c0 ("seqcount: Add raw_write_seqcount_latch()").

    For this to work we need the following guarantees from the rbtree
    code:

    1) a lockless reader must not see partial stores, this would allow it
    to observe nodes that are invalid memory.

    2) there must not be (temporary) loops in the tree structure in the
    modifier's program order, this would cause a lookup which
    interrupts the modifier to get stuck indefinitely.

    For 1) we must use WRITE_ONCE() for all updates to the tree structure;
    in particular this patch only does rb_{left,right} as those are the
    only element required for simple searches.

    It generates slightly worse code, probably because volatile. But in
    pointer chasing heavy code a few instructions more should not matter.

    For 2) I have carefully audited the code and drawn every intermediate
    link state and not found a loop.

    Cc: Mathieu Desnoyers
    Cc: "Paul E. McKenney"
    Cc: Oleg Nesterov
    Cc: Andrea Arcangeli
    Cc: David Woodhouse
    Cc: Rik van Riel
    Reviewed-by: Michel Lespinasse
    Signed-off-by: Peter Zijlstra (Intel)
    Signed-off-by: Rusty Russell

    Peter Zijlstra
     

14 Oct, 2014

1 commit


12 Jan, 2013

1 commit

  • lib/rbtree.c declared __rb_erase_color() as __always_inline void, and
    then exported it with EXPORT_SYMBOL.

    This was because __rb_erase_color() must be exported for augmented
    rbtree users, but it must also be inlined into rb_erase() so that the
    dummy callback can get optimized out of that call site.

    (Actually with a modern compiler, none of the dummy callback functions
    should even be generated as separate text functions).

    The above usage is legal C, but it was unusual enough for some compilers
    to warn about it. This change makes things more explicit, with a static
    __always_inline ____rb_erase_color function for use in rb_erase(), and a
    separate non-inline __rb_erase_color function for use in
    rb_erase_augmented call sites.

    Signed-off-by: Michel Lespinasse
    Reported-by: Wu Fengguang
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Michel Lespinasse
     

26 Oct, 2012

1 commit

  • rb_erase_augmented() is a static function annotated with
    __always_inline. This causes a compile failure when attempting to use
    the rbtree implementation as a library (e.g. kvm tool):

    rbtree_augmented.h:125:24: error: expected `=', `,', `;', `asm' or `__attribute__' before `void'

    Include linux/compiler.h in rbtree_augmented.h so that the __always_inline
    macro is resolved correctly.

    Signed-off-by: Will Deacon
    Cc: Pekka Enberg
    Reviewed-by: Michel Lespinasse
    Cc: Ingo Molnar
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Will Deacon
     

09 Oct, 2012

1 commit

  • Provide rb_insert_augmented() and rb_erase_augmented() through a new
    rbtree_augmented.h include file. rb_erase_augmented() is defined there as
    an __always_inline function, in order to allow inlining of augmented
    rbtree callbacks into it. Since this generates a relatively large
    function, each augmented rbtree user should make sure to have a single
    call site.

    Signed-off-by: Michel Lespinasse
    Cc: Rik van Riel
    Cc: Hillf Danton
    Cc: Peter Zijlstra
    Cc: Catalin Marinas
    Cc: Andrea Arcangeli
    Cc: David Woodhouse
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Michel Lespinasse