@@ -86,13 +86,12 @@ struct cfq_ttime {
8686 * move this into the elevator for the rq sorting as well.
8787 */
8888struct cfq_rb_root {
89- struct rb_root rb ;
90- struct rb_node * left ;
89+ struct rb_root_cached rb ;
9190 unsigned count ;
9291 u64 min_vdisktime ;
9392 struct cfq_ttime ttime ;
9493};
95- #define CFQ_RB_ROOT (struct cfq_rb_root) { .rb = RB_ROOT , \
94+ #define CFQ_RB_ROOT (struct cfq_rb_root) { .rb = RB_ROOT_CACHED , \
9695 .ttime = {.last_end_request = ktime_get_ns(),},}
9796
9897/*
@@ -983,10 +982,9 @@ static inline u64 max_vdisktime(u64 min_vdisktime, u64 vdisktime)
983982
984983static void update_min_vdisktime (struct cfq_rb_root * st )
985984{
986- struct cfq_group * cfqg ;
985+ if (!RB_EMPTY_ROOT (& st -> rb .rb_root )) {
986+ struct cfq_group * cfqg = rb_entry_cfqg (st -> rb .rb_leftmost );
987987
988- if (st -> left ) {
989- cfqg = rb_entry_cfqg (st -> left );
990988 st -> min_vdisktime = max_vdisktime (st -> min_vdisktime ,
991989 cfqg -> vdisktime );
992990 }
@@ -1168,46 +1166,25 @@ cfq_choose_req(struct cfq_data *cfqd, struct request *rq1, struct request *rq2,
11681166 }
11691167}
11701168
1171- /*
1172- * The below is leftmost cache rbtree addon
1173- */
11741169static struct cfq_queue * cfq_rb_first (struct cfq_rb_root * root )
11751170{
11761171 /* Service tree is empty */
11771172 if (!root -> count )
11781173 return NULL ;
11791174
1180- if (!root -> left )
1181- root -> left = rb_first (& root -> rb );
1182-
1183- if (root -> left )
1184- return rb_entry (root -> left , struct cfq_queue , rb_node );
1185-
1186- return NULL ;
1175+ return rb_entry (rb_first_cached (& root -> rb ), struct cfq_queue , rb_node );
11871176}
11881177
11891178static struct cfq_group * cfq_rb_first_group (struct cfq_rb_root * root )
11901179{
1191- if (!root -> left )
1192- root -> left = rb_first (& root -> rb );
1193-
1194- if (root -> left )
1195- return rb_entry_cfqg (root -> left );
1196-
1197- return NULL ;
1180+ return rb_entry_cfqg (rb_first_cached (& root -> rb ));
11981181}
11991182
1200- static void rb_erase_init (struct rb_node * n , struct rb_root * root )
1183+ static void cfq_rb_erase (struct rb_node * n , struct cfq_rb_root * root )
12011184{
1202- rb_erase (n , root );
1185+ rb_erase_cached (n , & root -> rb );
12031186 RB_CLEAR_NODE (n );
1204- }
12051187
1206- static void cfq_rb_erase (struct rb_node * n , struct cfq_rb_root * root )
1207- {
1208- if (root -> left == n )
1209- root -> left = NULL ;
1210- rb_erase_init (n , & root -> rb );
12111188 -- root -> count ;
12121189}
12131190
@@ -1257,11 +1234,11 @@ cfqg_key(struct cfq_rb_root *st, struct cfq_group *cfqg)
12571234static void
12581235__cfq_group_service_tree_add (struct cfq_rb_root * st , struct cfq_group * cfqg )
12591236{
1260- struct rb_node * * node = & st -> rb .rb_node ;
1237+ struct rb_node * * node = & st -> rb .rb_root . rb_node ;
12611238 struct rb_node * parent = NULL ;
12621239 struct cfq_group * __cfqg ;
12631240 s64 key = cfqg_key (st , cfqg );
1264- int left = 1 ;
1241+ bool leftmost = true ;
12651242
12661243 while (* node != NULL ) {
12671244 parent = * node ;
@@ -1271,15 +1248,12 @@ __cfq_group_service_tree_add(struct cfq_rb_root *st, struct cfq_group *cfqg)
12711248 node = & parent -> rb_left ;
12721249 else {
12731250 node = & parent -> rb_right ;
1274- left = 0 ;
1251+ leftmost = false ;
12751252 }
12761253 }
12771254
1278- if (left )
1279- st -> left = & cfqg -> rb_node ;
1280-
12811255 rb_link_node (& cfqg -> rb_node , parent , node );
1282- rb_insert_color (& cfqg -> rb_node , & st -> rb );
1256+ rb_insert_color_cached (& cfqg -> rb_node , & st -> rb , leftmost );
12831257}
12841258
12851259/*
@@ -1380,7 +1354,7 @@ cfq_group_notify_queue_add(struct cfq_data *cfqd, struct cfq_group *cfqg)
13801354 * so that groups get lesser vtime based on their weights, so that
13811355 * if group does not loose all if it was not continuously backlogged.
13821356 */
1383- n = rb_last (& st -> rb );
1357+ n = rb_last (& st -> rb . rb_root );
13841358 if (n ) {
13851359 __cfqg = rb_entry_cfqg (n );
13861360 cfqg -> vdisktime = __cfqg -> vdisktime +
@@ -2046,14 +2020,14 @@ static void cfq_service_tree_add(struct cfq_data *cfqd, struct cfq_queue *cfqq,
20462020 struct cfq_queue * __cfqq ;
20472021 u64 rb_key ;
20482022 struct cfq_rb_root * st ;
2049- int left ;
2023+ bool leftmost = true ;
20502024 int new_cfqq = 1 ;
20512025 u64 now = ktime_get_ns ();
20522026
20532027 st = st_for (cfqq -> cfqg , cfqq_class (cfqq ), cfqq_type (cfqq ));
20542028 if (cfq_class_idle (cfqq )) {
20552029 rb_key = CFQ_IDLE_DELAY ;
2056- parent = rb_last (& st -> rb );
2030+ parent = rb_last (& st -> rb . rb_root );
20572031 if (parent && parent != & cfqq -> rb_node ) {
20582032 __cfqq = rb_entry (parent , struct cfq_queue , rb_node );
20592033 rb_key += __cfqq -> rb_key ;
@@ -2087,10 +2061,9 @@ static void cfq_service_tree_add(struct cfq_data *cfqd, struct cfq_queue *cfqq,
20872061 cfqq -> service_tree = NULL ;
20882062 }
20892063
2090- left = 1 ;
20912064 parent = NULL ;
20922065 cfqq -> service_tree = st ;
2093- p = & st -> rb .rb_node ;
2066+ p = & st -> rb .rb_root . rb_node ;
20942067 while (* p ) {
20952068 parent = * p ;
20962069 __cfqq = rb_entry (parent , struct cfq_queue , rb_node );
@@ -2102,16 +2075,13 @@ static void cfq_service_tree_add(struct cfq_data *cfqd, struct cfq_queue *cfqq,
21022075 p = & parent -> rb_left ;
21032076 else {
21042077 p = & parent -> rb_right ;
2105- left = 0 ;
2078+ leftmost = false ;
21062079 }
21072080 }
21082081
2109- if (left )
2110- st -> left = & cfqq -> rb_node ;
2111-
21122082 cfqq -> rb_key = rb_key ;
21132083 rb_link_node (& cfqq -> rb_node , parent , p );
2114- rb_insert_color (& cfqq -> rb_node , & st -> rb );
2084+ rb_insert_color_cached (& cfqq -> rb_node , & st -> rb , leftmost );
21152085 st -> count ++ ;
21162086 if (add_front || !new_cfqq )
21172087 return ;
@@ -2551,7 +2521,7 @@ static struct cfq_queue *cfq_get_next_queue(struct cfq_data *cfqd)
25512521 /* There is nothing to dispatch */
25522522 if (!st )
25532523 return NULL ;
2554- if (RB_EMPTY_ROOT (& st -> rb ))
2524+ if (RB_EMPTY_ROOT (& st -> rb . rb_root ))
25552525 return NULL ;
25562526 return cfq_rb_first (st );
25572527}
@@ -3039,7 +3009,7 @@ static struct cfq_group *cfq_get_next_cfqg(struct cfq_data *cfqd)
30393009 struct cfq_rb_root * st = & cfqd -> grp_service_tree ;
30403010 struct cfq_group * cfqg ;
30413011
3042- if (RB_EMPTY_ROOT (& st -> rb ))
3012+ if (RB_EMPTY_ROOT (& st -> rb . rb_root ))
30433013 return NULL ;
30443014 cfqg = cfq_rb_first_group (st );
30453015 update_min_vdisktime (st );
0 commit comments