Skip to content

Commit 8234722

Browse files
Davidlohr Buesookta-10
authored andcommitted
block/cfq: cache rightmost rb_node
commit f0f1a45f95e85a8ac28c4d62bf2a84db0799efab upstream. 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. [dave@stgolabs.net: brain fart #1] Link: http://lkml.kernel.org/r/20170731155955.GD21328@linux-80c1.suse Link: http://lkml.kernel.org/r/20170719014603.19029-18-dave@stgolabs.net Signed-off-by: Davidlohr Bueso <dbueso@suse.de> Cc: Jens Axboe <axboe@fb.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Harsh Shandilya <harsh@prjkt.io> Signed-off-by: Oktapra Amtono <oktapra.amtono@gmail.com>
1 parent d154a95 commit 8234722

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

block/cfq-iosched.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,13 @@ struct cfq_ttime {
9292
*/
9393
struct cfq_rb_root {
9494
struct rb_root_cached rb;
95+
struct rb_node *rb_rightmost;
9596
unsigned count;
9697
u64 min_vdisktime;
9798
struct cfq_ttime ttime;
9899
};
99100
#define CFQ_RB_ROOT (struct cfq_rb_root) { .rb = RB_ROOT_CACHED, \
101+
.rb_rightmost = NULL, \
100102
.ttime = {.last_end_request = ktime_get_ns(),},}
101103

102104
/*
@@ -1183,6 +1185,9 @@ static struct cfq_group *cfq_rb_first_group(struct cfq_rb_root *root)
11831185

11841186
static void cfq_rb_erase(struct rb_node *n, struct cfq_rb_root *root)
11851187
{
1188+
if (root->rb_rightmost == n)
1189+
root->rb_rightmost = rb_prev(n);
1190+
11861191
rb_erase_cached(n, &root->rb);
11871192
RB_CLEAR_NODE(n);
11881193

@@ -1239,20 +1244,24 @@ __cfq_group_service_tree_add(struct cfq_rb_root *st, struct cfq_group *cfqg)
12391244
struct rb_node *parent = NULL;
12401245
struct cfq_group *__cfqg;
12411246
s64 key = cfqg_key(st, cfqg);
1242-
bool leftmost = true;
1247+
bool leftmost = true, rightmost = true;
12431248

12441249
while (*node != NULL) {
12451250
parent = *node;
12461251
__cfqg = rb_entry_cfqg(parent);
12471252

1248-
if (key < cfqg_key(st, __cfqg))
1253+
if (key < cfqg_key(st, __cfqg)) {
12491254
node = &parent->rb_left;
1250-
else {
1255+
rightmost = false;
1256+
} else {
12511257
node = &parent->rb_right;
12521258
leftmost = false;
12531259
}
12541260
}
12551261

1262+
if (rightmost)
1263+
st->rb_rightmost = &cfqg->rb_node;
1264+
12561265
rb_link_node(&cfqg->rb_node, parent, node);
12571266
rb_insert_color_cached(&cfqg->rb_node, &st->rb, leftmost);
12581267
}
@@ -1355,7 +1364,7 @@ cfq_group_notify_queue_add(struct cfq_data *cfqd, struct cfq_group *cfqg)
13551364
* so that groups get lesser vtime based on their weights, so that
13561365
* if group does not loose all if it was not continuously backlogged.
13571366
*/
1358-
n = rb_last(&st->rb.rb_root);
1367+
n = st->rb_rightmost;
13591368
if (n) {
13601369
__cfqg = rb_entry_cfqg(n);
13611370
cfqg->vdisktime = __cfqg->vdisktime +
@@ -2204,7 +2213,7 @@ static void cfq_service_tree_add(struct cfq_data *cfqd, struct cfq_queue *cfqq,
22042213
st = st_for(cfqq->cfqg, cfqq_class(cfqq), cfqq_type(cfqq));
22052214
if (cfq_class_idle(cfqq)) {
22062215
rb_key = CFQ_IDLE_DELAY;
2207-
parent = rb_last(&st->rb.rb_root);
2216+
parent = st->rb_rightmost;
22082217
if (parent && parent != &cfqq->rb_node) {
22092218
__cfqq = rb_entry(parent, struct cfq_queue, rb_node);
22102219
rb_key += __cfqq->rb_key;

0 commit comments

Comments
 (0)