Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1690898

[PATCH 17/17] block/cfq: cache rightmost rb_node

From Davidlohr Bueso <dave@stgolabs.net>
Newsgroups linux.kernel
Subject [PATCH 17/17] block/cfq: cache rightmost rb_node
Date 2017-07-19 03:50 +0200
Message-ID <u4MhJ-1Dj-39@gated-at.bofh.it> (permalink)
References <u4MhH-1Dj-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


For the same reasons we already cache the leftmost pointer,
apply the same optimization for rb_last() calls. Users must
explicitly do this as rb_root_cached only deals with the
smallest node.

Cc: axboe@fb.com
Cc: linux-block@vger.kernel.org
Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
---
This is part of the rbtree internal caching series:
https://lwn.net/Articles/726809/

 block/cfq-iosched.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c
index 92c31683a2bb..57ec45fd4590 100644
--- a/block/cfq-iosched.c
+++ b/block/cfq-iosched.c
@@ -94,11 +94,13 @@ struct cfq_ttime {
  */
 struct cfq_rb_root {
 	struct rb_root_cached rb;
+	struct rb_node *rb_rightmost;
 	unsigned count;
 	u64 min_vdisktime;
 	struct cfq_ttime ttime;
 };
 #define CFQ_RB_ROOT	(struct cfq_rb_root) { .rb = RB_ROOT_CACHED, \
+			.rb_rightmost = NULL,			     \
 			.ttime = {.last_end_request = ktime_get_ns(),},}
 
 /*
@@ -1183,6 +1185,9 @@ static struct cfq_group *cfq_rb_first_group(struct cfq_rb_root *root)
 
 static void cfq_rb_erase(struct rb_node *n, struct cfq_rb_root *root)
 {
+	if (root->rb_rightmost == n)
+		root->rb_rightmost = rb_next(n);
+
 	rb_erase_cached(n, &root->rb);
 	RB_CLEAR_NODE(n);
 
@@ -1239,20 +1244,24 @@ __cfq_group_service_tree_add(struct cfq_rb_root *st, struct cfq_group *cfqg)
 	struct rb_node *parent = NULL;
 	struct cfq_group *__cfqg;
 	s64 key = cfqg_key(st, cfqg);
-	bool leftmost = true;
+	bool leftmost = true, rightmost = true;
 
 	while (*node != NULL) {
 		parent = *node;
 		__cfqg = rb_entry_cfqg(parent);
 
-		if (key < cfqg_key(st, __cfqg))
+		if (key < cfqg_key(st, __cfqg)) {
 			node = &parent->rb_left;
-		else {
+			rightmost = false;
+		} else {
 			node = &parent->rb_right;
 			leftmost = false;
 		}
 	}
 
+	if (rightmost)
+		st->rb_rightmost = &cfqg->rb_node;
+
 	rb_link_node(&cfqg->rb_node, parent, node);
 	rb_insert_color_cached(&cfqg->rb_node, &st->rb, leftmost);
 }
@@ -1355,7 +1364,7 @@ cfq_group_notify_queue_add(struct cfq_data *cfqd, struct cfq_group *cfqg)
 	 * so that groups get lesser vtime based on their weights, so that
 	 * if group does not loose all if it was not continuously backlogged.
 	 */
-	n = rb_last(&st->rb.rb_root);
+	n = st->rb_rightmost;
 	if (n) {
 		__cfqg = rb_entry_cfqg(n);
 		cfqg->vdisktime = __cfqg->vdisktime +
@@ -2204,7 +2213,7 @@ static void cfq_service_tree_add(struct cfq_data *cfqd, struct cfq_queue *cfqq,
 	st = st_for(cfqq->cfqg, cfqq_class(cfqq), cfqq_type(cfqq));
 	if (cfq_class_idle(cfqq)) {
 		rb_key = CFQ_IDLE_DELAY;
-		parent = rb_last(&st->rb.rb_root);
+		parent = st->rb_rightmost;
 		if (parent && parent != &cfqq->rb_node) {
 			__cfqq = rb_entry(parent, struct cfq_queue, rb_node);
 			rb_key += __cfqq->rb_key;
-- 
2.12.0

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH -next v4 00/17] rbtree: cache leftmost node internally Davidlohr Bueso <dave@stgolabs.net> - 2017-07-19 03:50 +0200
  [PATCH 09/17] locking/rtmutex: replace top-waiter and pi_waiters leftmost caching Davidlohr Bueso <dave@stgolabs.net> - 2017-07-19 03:50 +0200
  [PATCH 03/17] rbtree: add some additional comments for rebalancing cases Davidlohr Bueso <dave@stgolabs.net> - 2017-07-19 03:50 +0200
  [PATCH 13/17] procfs: use faster rb_first_cached() Davidlohr Bueso <dave@stgolabs.net> - 2017-07-19 03:50 +0200
  [PATCH 16/17] mem/memcg: cache rightmost node Davidlohr Bueso <dave@stgolabs.net> - 2017-07-19 03:50 +0200
    Re: [PATCH 16/17] mem/memcg: cache rightmost node Michal Hocko <mhocko@kernel.org> - 2017-07-19 10:00 +0200
      Re: [PATCH 16/17] mem/memcg: cache rightmost node Andrew Morton <akpm@linux-foundation.org> - 2017-07-26 23:10 +0200
        Re: [PATCH 16/17] mem/memcg: cache rightmost node Michal Hocko <mhocko@kernel.org> - 2017-07-27 09:10 +0200
  [PATCH 01/17] rbtree: cache leftmost node internally Davidlohr Bueso <dave@stgolabs.net> - 2017-07-19 03:50 +0200
  [PATCH 17/17] block/cfq: cache rightmost rb_node Davidlohr Bueso <dave@stgolabs.net> - 2017-07-19 03:50 +0200
    Re: [PATCH 17/17] block/cfq: cache rightmost rb_node Jan Kara <jack@suse.cz> - 2017-07-19 10:00 +0200
  [PATCH 12/17] lib/interval-tree: correct comment wrt generic flavor Davidlohr Bueso <dave@stgolabs.net> - 2017-07-19 03:50 +0200
  [PATCH 10/17] block/cfq: replace cfq_rb_root leftmost caching Davidlohr Bueso <dave@stgolabs.net> - 2017-07-19 03:50 +0200
    Re: [PATCH 10/17] block/cfq: replace cfq_rb_root leftmost caching Jan Kara <jack@suse.cz> - 2017-07-19 09:50 +0200
  [PATCH 05/17] lib/rbtree_test.c: add (inorder) traversal test Davidlohr Bueso <dave@stgolabs.net> - 2017-07-19 04:00 +0200
  [PATCH 04/17] lib/rbtree_test.c: make input module parameters Davidlohr Bueso <dave@stgolabs.net> - 2017-07-19 04:00 +0200
  Re: [PATCH 11/17] lib/interval_tree: fast overlap detection Doug Ledford <dledford@redhat.com> - 2017-07-22 20:00 +0200

csiph-web