*/
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(),},}
/*
static void cfq_rb_erase(struct rb_node *n, struct cfq_rb_root *root)
{
+ if (root->rb_rightmost == n)
+ root->rb_rightmost = rb_prev(n);
+
rb_erase_cached(n, &root->rb);
RB_CLEAR_NODE(n);
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);
}
* 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 +
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;