@@ -84,8 +84,7 @@ struct throtl_service_queue {
84
84
* RB tree of active children throtl_grp's, which are sorted by
85
85
* their ->disptime.
86
86
*/
87
- struct rb_root pending_tree ; /* RB tree of active tgs */
88
- struct rb_node * first_pending ; /* first node in the tree */
87
+ struct rb_root_cached pending_tree ; /* RB tree of active tgs */
89
88
unsigned int nr_pending ; /* # queued in the tree */
90
89
unsigned long first_pending_disptime ; /* disptime of the first tg */
91
90
struct timer_list pending_timer ; /* fires on first_pending_disptime */
@@ -475,7 +474,7 @@ static void throtl_service_queue_init(struct throtl_service_queue *sq)
475
474
{
476
475
INIT_LIST_HEAD (& sq -> queued [0 ]);
477
476
INIT_LIST_HEAD (& sq -> queued [1 ]);
478
- sq -> pending_tree = RB_ROOT ;
477
+ sq -> pending_tree = RB_ROOT_CACHED ;
479
478
timer_setup (& sq -> pending_timer , throtl_pending_timer_fn , 0 );
480
479
}
481
480
@@ -616,31 +615,23 @@ static void throtl_pd_free(struct blkg_policy_data *pd)
616
615
static struct throtl_grp *
617
616
throtl_rb_first (struct throtl_service_queue * parent_sq )
618
617
{
618
+ struct rb_node * n ;
619
619
/* Service tree is empty */
620
620
if (!parent_sq -> nr_pending )
621
621
return NULL ;
622
622
623
- if (!parent_sq -> first_pending )
624
- parent_sq -> first_pending = rb_first (& parent_sq -> pending_tree );
625
-
626
- if (parent_sq -> first_pending )
627
- return rb_entry_tg (parent_sq -> first_pending );
628
-
629
- return NULL ;
630
- }
631
-
632
- static void rb_erase_init (struct rb_node * n , struct rb_root * root )
633
- {
634
- rb_erase (n , root );
635
- RB_CLEAR_NODE (n );
623
+ n = rb_first_cached (& parent_sq -> pending_tree );
624
+ WARN_ON_ONCE (!n );
625
+ if (!n )
626
+ return NULL ;
627
+ return rb_entry_tg (n );
636
628
}
637
629
638
630
static void throtl_rb_erase (struct rb_node * n ,
639
631
struct throtl_service_queue * parent_sq )
640
632
{
641
- if (parent_sq -> first_pending == n )
642
- parent_sq -> first_pending = NULL ;
643
- rb_erase_init (n , & parent_sq -> pending_tree );
633
+ rb_erase_cached (n , & parent_sq -> pending_tree );
634
+ RB_CLEAR_NODE (n );
644
635
-- parent_sq -> nr_pending ;
645
636
}
646
637
@@ -658,11 +649,11 @@ static void update_min_dispatch_time(struct throtl_service_queue *parent_sq)
658
649
static void tg_service_queue_add (struct throtl_grp * tg )
659
650
{
660
651
struct throtl_service_queue * parent_sq = tg -> service_queue .parent_sq ;
661
- struct rb_node * * node = & parent_sq -> pending_tree .rb_node ;
652
+ struct rb_node * * node = & parent_sq -> pending_tree .rb_root . rb_node ;
662
653
struct rb_node * parent = NULL ;
663
654
struct throtl_grp * __tg ;
664
655
unsigned long key = tg -> disptime ;
665
- int left = 1 ;
656
+ bool leftmost = true ;
666
657
667
658
while (* node != NULL ) {
668
659
parent = * node ;
@@ -672,15 +663,13 @@ static void tg_service_queue_add(struct throtl_grp *tg)
672
663
node = & parent -> rb_left ;
673
664
else {
674
665
node = & parent -> rb_right ;
675
- left = 0 ;
666
+ leftmost = false ;
676
667
}
677
668
}
678
669
679
- if (left )
680
- parent_sq -> first_pending = & tg -> rb_node ;
681
-
682
670
rb_link_node (& tg -> rb_node , parent , node );
683
- rb_insert_color (& tg -> rb_node , & parent_sq -> pending_tree );
671
+ rb_insert_color_cached (& tg -> rb_node , & parent_sq -> pending_tree ,
672
+ leftmost );
684
673
}
685
674
686
675
static void __throtl_enqueue_tg (struct throtl_grp * tg )
0 commit comments