diff options
author | Davidlohr Bueso <dave@stgolabs.net> | 2017-09-08 19:15:25 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-09-08 21:26:49 -0400 |
commit | f0f1a45f95e85a8ac28c4d62bf2a84db0799efab (patch) | |
tree | c41b7ab10cf999b45aa3563afe2a4961b4d68129 /block | |
parent | fa90b2fd300f38cc7b3e416974116c83f3953465 (diff) |
block/cfq: cache rightmost rb_node
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>
Diffstat (limited to 'block')
-rw-r--r-- | block/cfq-iosched.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c index 9ba5345ebc9a..9f342ef1ad42 100644 --- a/block/cfq-iosched.c +++ b/block/cfq-iosched.c | |||
@@ -94,11 +94,13 @@ struct cfq_ttime { | |||
94 | */ | 94 | */ |
95 | struct cfq_rb_root { | 95 | struct cfq_rb_root { |
96 | struct rb_root_cached rb; | 96 | struct rb_root_cached rb; |
97 | struct rb_node *rb_rightmost; | ||
97 | unsigned count; | 98 | unsigned count; |
98 | u64 min_vdisktime; | 99 | u64 min_vdisktime; |
99 | struct cfq_ttime ttime; | 100 | struct cfq_ttime ttime; |
100 | }; | 101 | }; |
101 | #define CFQ_RB_ROOT (struct cfq_rb_root) { .rb = RB_ROOT_CACHED, \ | 102 | #define CFQ_RB_ROOT (struct cfq_rb_root) { .rb = RB_ROOT_CACHED, \ |
103 | .rb_rightmost = NULL, \ | ||
102 | .ttime = {.last_end_request = ktime_get_ns(),},} | 104 | .ttime = {.last_end_request = ktime_get_ns(),},} |
103 | 105 | ||
104 | /* | 106 | /* |
@@ -1180,6 +1182,9 @@ static struct cfq_group *cfq_rb_first_group(struct cfq_rb_root *root) | |||
1180 | 1182 | ||
1181 | static void cfq_rb_erase(struct rb_node *n, struct cfq_rb_root *root) | 1183 | static void cfq_rb_erase(struct rb_node *n, struct cfq_rb_root *root) |
1182 | { | 1184 | { |
1185 | if (root->rb_rightmost == n) | ||
1186 | root->rb_rightmost = rb_prev(n); | ||
1187 | |||
1183 | rb_erase_cached(n, &root->rb); | 1188 | rb_erase_cached(n, &root->rb); |
1184 | RB_CLEAR_NODE(n); | 1189 | RB_CLEAR_NODE(n); |
1185 | 1190 | ||
@@ -1236,20 +1241,24 @@ __cfq_group_service_tree_add(struct cfq_rb_root *st, struct cfq_group *cfqg) | |||
1236 | struct rb_node *parent = NULL; | 1241 | struct rb_node *parent = NULL; |
1237 | struct cfq_group *__cfqg; | 1242 | struct cfq_group *__cfqg; |
1238 | s64 key = cfqg_key(st, cfqg); | 1243 | s64 key = cfqg_key(st, cfqg); |
1239 | bool leftmost = true; | 1244 | bool leftmost = true, rightmost = true; |
1240 | 1245 | ||
1241 | while (*node != NULL) { | 1246 | while (*node != NULL) { |
1242 | parent = *node; | 1247 | parent = *node; |
1243 | __cfqg = rb_entry_cfqg(parent); | 1248 | __cfqg = rb_entry_cfqg(parent); |
1244 | 1249 | ||
1245 | if (key < cfqg_key(st, __cfqg)) | 1250 | if (key < cfqg_key(st, __cfqg)) { |
1246 | node = &parent->rb_left; | 1251 | node = &parent->rb_left; |
1247 | else { | 1252 | rightmost = false; |
1253 | } else { | ||
1248 | node = &parent->rb_right; | 1254 | node = &parent->rb_right; |
1249 | leftmost = false; | 1255 | leftmost = false; |
1250 | } | 1256 | } |
1251 | } | 1257 | } |
1252 | 1258 | ||
1259 | if (rightmost) | ||
1260 | st->rb_rightmost = &cfqg->rb_node; | ||
1261 | |||
1253 | rb_link_node(&cfqg->rb_node, parent, node); | 1262 | rb_link_node(&cfqg->rb_node, parent, node); |
1254 | rb_insert_color_cached(&cfqg->rb_node, &st->rb, leftmost); | 1263 | rb_insert_color_cached(&cfqg->rb_node, &st->rb, leftmost); |
1255 | } | 1264 | } |
@@ -1352,7 +1361,7 @@ cfq_group_notify_queue_add(struct cfq_data *cfqd, struct cfq_group *cfqg) | |||
1352 | * so that groups get lesser vtime based on their weights, so that | 1361 | * so that groups get lesser vtime based on their weights, so that |
1353 | * if group does not loose all if it was not continuously backlogged. | 1362 | * if group does not loose all if it was not continuously backlogged. |
1354 | */ | 1363 | */ |
1355 | n = rb_last(&st->rb.rb_root); | 1364 | n = st->rb_rightmost; |
1356 | if (n) { | 1365 | if (n) { |
1357 | __cfqg = rb_entry_cfqg(n); | 1366 | __cfqg = rb_entry_cfqg(n); |
1358 | cfqg->vdisktime = __cfqg->vdisktime + | 1367 | cfqg->vdisktime = __cfqg->vdisktime + |
@@ -2201,7 +2210,7 @@ static void cfq_service_tree_add(struct cfq_data *cfqd, struct cfq_queue *cfqq, | |||
2201 | st = st_for(cfqq->cfqg, cfqq_class(cfqq), cfqq_type(cfqq)); | 2210 | st = st_for(cfqq->cfqg, cfqq_class(cfqq), cfqq_type(cfqq)); |
2202 | if (cfq_class_idle(cfqq)) { | 2211 | if (cfq_class_idle(cfqq)) { |
2203 | rb_key = CFQ_IDLE_DELAY; | 2212 | rb_key = CFQ_IDLE_DELAY; |
2204 | parent = rb_last(&st->rb.rb_root); | 2213 | parent = st->rb_rightmost; |
2205 | if (parent && parent != &cfqq->rb_node) { | 2214 | if (parent && parent != &cfqq->rb_node) { |
2206 | __cfqq = rb_entry(parent, struct cfq_queue, rb_node); | 2215 | __cfqq = rb_entry(parent, struct cfq_queue, rb_node); |
2207 | rb_key += __cfqq->rb_key; | 2216 | rb_key += __cfqq->rb_key; |