From: Jan Kara <jack@suse.cz>
To: Davidlohr Bueso <dave@stgolabs.net>
Cc: mingo@kernel.org, peterz@infradead.org,
akpm@linux-foundation.org, jack@suse.cz,
kirill.shutemov@linux.intel.com, ldufour@linux.vnet.ibm.com,
mhocko@suse.com, mgorman@techsingularity.net,
linux-kernel@vger.kernel.org, Davidlohr Bueso <dbueso@suse.de>
Subject: Re: [PATCH 1/8] rbtree: Cache leftmost node internally
Date: Fri, 9 Jun 2017 09:43:47 +0200 [thread overview]
Message-ID: <20170609074347.GA15968@quack2.suse.cz> (raw)
In-Reply-To: <20170608180329.11457-2-dave@stgolabs.net>
On Thu 08-06-17 11:03:22, Davidlohr Bueso wrote:
> 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.
>
> Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
Looks good to me. Just one nit below:
> @@ -150,6 +161,7 @@ extern void __rb_erase_color(struct rb_node *parent, struct rb_root *root,
>
> static __always_inline struct rb_node *
> __rb_erase_augmented(struct rb_node *node, struct rb_root *root,
> + struct rb_node **leftmost,
> const struct rb_augment_callbacks *augment)
> {
> struct rb_node *child = node->rb_right;
> @@ -157,6 +169,9 @@ __rb_erase_augmented(struct rb_node *node, struct rb_root *root,
> struct rb_node *parent, *rebalance;
> unsigned long pc;
>
> + if (leftmost && node == *leftmost)
> + *leftmost = rb_next(node);
> +
> if (!tmp) {
> /*
> * Case 1: node to erase has no more than 1 child (easy!)
Why do you propagate e.g. 'leftmost' down to __rb_erase_augmented() when
you could just handle everything within rb_erase_augmented_cached?
Similarly for other functions like __rb_insert()... It would seem like less
churn and I don't see downside to it...
Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
next prev parent reply other threads:[~2017-06-09 7:43 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-08 18:03 [PATCH -next v2 0/8] " Davidlohr Bueso
2017-06-08 18:03 ` [PATCH 1/8] " Davidlohr Bueso
2017-06-09 7:43 ` Jan Kara [this message]
2017-06-09 14:32 ` Davidlohr Bueso
2017-06-12 9:47 ` Jan Kara
2017-06-08 18:03 ` [PATCH 2/8] sched/fair: Replace cfs_rq->rb_leftmost Davidlohr Bueso
2017-06-08 18:03 ` [PATCH 3/8] sched/deadline: Replace earliest dl and rq leftmost caching Davidlohr Bueso
2017-06-08 18:03 ` [PATCH 4/8] locking/rtmutex: Replace top-waiter and pi_waiters " Davidlohr Bueso
2017-06-08 18:03 ` [PATCH 5/8] lib/interval_tree: Fast overlap detection Davidlohr Bueso
2017-06-09 8:15 ` Christian König
2017-06-08 18:03 ` [PATCH 6/8] lib/interval-tree: Correct comment wrt generic flavor Davidlohr Bueso
2017-06-08 18:03 ` [PATCH 7/8] procfs: Use faster rb_first_cached() Davidlohr Bueso
2017-06-08 18:03 ` [PATCH 8/8] fs/epoll: " Davidlohr Bueso
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=20170609074347.GA15968@quack2.suse.cz \
--to=jack@suse.cz \
--cc=akpm@linux-foundation.org \
--cc=dave@stgolabs.net \
--cc=dbueso@suse.de \
--cc=kirill.shutemov@linux.intel.com \
--cc=ldufour@linux.vnet.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@techsingularity.net \
--cc=mhocko@suse.com \
--cc=mingo@kernel.org \
--cc=peterz@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
all inboxes | Powered by JetHome®