Skip to content

Commit c4eda7e

Browse files
Davidlohr BuesoDennySPB
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: mydongistiny <jaysonedson@gmail.com> Change-Id: If8cf333c3c269b16fc577dc139a2f6bb7d60671c Signed-off-by: mydongistiny <jaysonedson@gmail.com>
1 parent 9e1ec29 commit c4eda7e

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

block/cfq-iosched.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,13 @@ struct cfq_ttime {
8787
*/
8888
struct cfq_rb_root {
8989
struct rb_root_cached rb;
90+
struct rb_node *rb_rightmost;
9091
unsigned count;
9192
u64 min_vdisktime;
9293
struct cfq_ttime ttime;
9394
};
9495
#define CFQ_RB_ROOT (struct cfq_rb_root) { .rb = RB_ROOT_CACHED, \
96+
.rb_rightmost = NULL, \
9597
.ttime = {.last_end_request = ktime_get_ns(),},}
9698

9799
/*
@@ -1182,6 +1184,9 @@ static struct cfq_group *cfq_rb_first_group(struct cfq_rb_root *root)
11821184

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

@@ -1238,20 +1243,24 @@ __cfq_group_service_tree_add(struct cfq_rb_root *st, struct cfq_group *cfqg)
12381243
struct rb_node *parent = NULL;
12391244
struct cfq_group *__cfqg;
12401245
s64 key = cfqg_key(st, cfqg);
1241-
bool leftmost = true;
1246+
bool leftmost = true, rightmost = true;
12421247

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

1247-
if (key < cfqg_key(st, __cfqg))
1252+
if (key < cfqg_key(st, __cfqg)) {
12481253
node = &parent->rb_left;
1249-
else {
1254+
rightmost = false;
1255+
} else {
12501256
node = &parent->rb_right;
12511257
leftmost = false;
12521258
}
12531259
}
12541260

1261+
if (rightmost)
1262+
st->rb_rightmost = &cfqg->rb_node;
1263+
12551264
rb_link_node(&cfqg->rb_node, parent, node);
12561265
rb_insert_color_cached(&cfqg->rb_node, &st->rb, leftmost);
12571266
}
@@ -1354,7 +1363,7 @@ cfq_group_notify_queue_add(struct cfq_data *cfqd, struct cfq_group *cfqg)
13541363
* so that groups get lesser vtime based on their weights, so that
13551364
* if group does not loose all if it was not continuously backlogged.
13561365
*/
1357-
n = rb_last(&st->rb.rb_root);
1366+
n = st->rb_rightmost;
13581367
if (n) {
13591368
__cfqg = rb_entry_cfqg(n);
13601369
cfqg->vdisktime = __cfqg->vdisktime +
@@ -2027,7 +2036,7 @@ static void cfq_service_tree_add(struct cfq_data *cfqd, struct cfq_queue *cfqq,
20272036
st = st_for(cfqq->cfqg, cfqq_class(cfqq), cfqq_type(cfqq));
20282037
if (cfq_class_idle(cfqq)) {
20292038
rb_key = CFQ_IDLE_DELAY;
2030-
parent = rb_last(&st->rb.rb_root);
2039+
parent = st->rb_rightmost;
20312040
if (parent && parent != &cfqq->rb_node) {
20322041
__cfqq = rb_entry(parent, struct cfq_queue, rb_node);
20332042
rb_key += __cfqq->rb_key;

0 commit comments

Comments
 (0)