@@ -27,6 +27,8 @@ static struct blkcg_policy blkcg_policy_throtl;
2727static struct workqueue_struct * kthrotld_workqueue ;
2828
2929struct throtl_service_queue {
30+ struct throtl_service_queue * parent_sq ; /* the parent service_queue */
31+
3032 /*
3133 * Bios queued directly to this service_queue or dispatched from
3234 * children throtl_grp's.
@@ -197,21 +199,24 @@ static void tg_stats_alloc_fn(struct work_struct *work)
197199}
198200
199201/* init a service_queue, assumes the caller zeroed it */
200- static void throtl_service_queue_init (struct throtl_service_queue * sq )
202+ static void throtl_service_queue_init (struct throtl_service_queue * sq ,
203+ struct throtl_service_queue * parent_sq )
201204{
202205 bio_list_init (& sq -> bio_lists [0 ]);
203206 bio_list_init (& sq -> bio_lists [1 ]);
204207 sq -> pending_tree = RB_ROOT ;
208+ sq -> parent_sq = parent_sq ;
205209}
206210
207211static void throtl_pd_init (struct blkcg_gq * blkg )
208212{
209213 struct throtl_grp * tg = blkg_to_tg (blkg );
214+ struct throtl_data * td = blkg -> q -> td ;
210215 unsigned long flags ;
211216
212- throtl_service_queue_init (& tg -> service_queue );
217+ throtl_service_queue_init (& tg -> service_queue , & td -> service_queue );
213218 RB_CLEAR_NODE (& tg -> rb_node );
214- tg -> td = blkg -> q -> td ;
219+ tg -> td = td ;
215220
216221 tg -> bps [READ ] = -1 ;
217222 tg -> bps [WRITE ] = -1 ;
@@ -339,9 +344,9 @@ static void update_min_dispatch_time(struct throtl_service_queue *parent_sq)
339344 parent_sq -> first_pending_disptime = tg -> disptime ;
340345}
341346
342- static void tg_service_queue_add (struct throtl_grp * tg ,
343- struct throtl_service_queue * parent_sq )
347+ static void tg_service_queue_add (struct throtl_grp * tg )
344348{
349+ struct throtl_service_queue * parent_sq = tg -> service_queue .parent_sq ;
345350 struct rb_node * * node = & parent_sq -> pending_tree .rb_node ;
346351 struct rb_node * parent = NULL ;
347352 struct throtl_grp * __tg ;
@@ -367,33 +372,29 @@ static void tg_service_queue_add(struct throtl_grp *tg,
367372 rb_insert_color (& tg -> rb_node , & parent_sq -> pending_tree );
368373}
369374
370- static void __throtl_enqueue_tg (struct throtl_grp * tg ,
371- struct throtl_service_queue * parent_sq )
375+ static void __throtl_enqueue_tg (struct throtl_grp * tg )
372376{
373- tg_service_queue_add (tg , parent_sq );
377+ tg_service_queue_add (tg );
374378 tg -> flags |= THROTL_TG_PENDING ;
375- parent_sq -> nr_pending ++ ;
379+ tg -> service_queue . parent_sq -> nr_pending ++ ;
376380}
377381
378- static void throtl_enqueue_tg (struct throtl_grp * tg ,
379- struct throtl_service_queue * parent_sq )
382+ static void throtl_enqueue_tg (struct throtl_grp * tg )
380383{
381384 if (!(tg -> flags & THROTL_TG_PENDING ))
382- __throtl_enqueue_tg (tg , parent_sq );
385+ __throtl_enqueue_tg (tg );
383386}
384387
385- static void __throtl_dequeue_tg (struct throtl_grp * tg ,
386- struct throtl_service_queue * parent_sq )
388+ static void __throtl_dequeue_tg (struct throtl_grp * tg )
387389{
388- throtl_rb_erase (& tg -> rb_node , parent_sq );
390+ throtl_rb_erase (& tg -> rb_node , tg -> service_queue . parent_sq );
389391 tg -> flags &= ~THROTL_TG_PENDING ;
390392}
391393
392- static void throtl_dequeue_tg (struct throtl_grp * tg ,
393- struct throtl_service_queue * parent_sq )
394+ static void throtl_dequeue_tg (struct throtl_grp * tg )
394395{
395396 if (tg -> flags & THROTL_TG_PENDING )
396- __throtl_dequeue_tg (tg , parent_sq );
397+ __throtl_dequeue_tg (tg );
397398}
398399
399400/* Call with queue lock held */
@@ -707,8 +708,7 @@ static void throtl_charge_bio(struct throtl_grp *tg, struct bio *bio)
707708 throtl_update_dispatch_stats (tg_to_blkg (tg ), bio -> bi_size , bio -> bi_rw );
708709}
709710
710- static void throtl_add_bio_tg (struct bio * bio , struct throtl_grp * tg ,
711- struct throtl_service_queue * parent_sq )
711+ static void throtl_add_bio_tg (struct bio * bio , struct throtl_grp * tg )
712712{
713713 struct throtl_service_queue * sq = & tg -> service_queue ;
714714 bool rw = bio_data_dir (bio );
@@ -727,11 +727,10 @@ static void throtl_add_bio_tg(struct bio *bio, struct throtl_grp *tg,
727727 blkg_get (tg_to_blkg (tg ));
728728 sq -> nr_queued [rw ]++ ;
729729 tg -> td -> nr_queued [rw ]++ ;
730- throtl_enqueue_tg (tg , parent_sq );
730+ throtl_enqueue_tg (tg );
731731}
732732
733- static void tg_update_disptime (struct throtl_grp * tg ,
734- struct throtl_service_queue * parent_sq )
733+ static void tg_update_disptime (struct throtl_grp * tg )
735734{
736735 struct throtl_service_queue * sq = & tg -> service_queue ;
737736 unsigned long read_wait = -1 , write_wait = -1 , min_wait = -1 , disptime ;
@@ -747,16 +746,15 @@ static void tg_update_disptime(struct throtl_grp *tg,
747746 disptime = jiffies + min_wait ;
748747
749748 /* Update dispatch time */
750- throtl_dequeue_tg (tg , parent_sq );
749+ throtl_dequeue_tg (tg );
751750 tg -> disptime = disptime ;
752- throtl_enqueue_tg (tg , parent_sq );
751+ throtl_enqueue_tg (tg );
753752
754753 /* see throtl_add_bio_tg() */
755754 tg -> flags &= ~THROTL_TG_WAS_EMPTY ;
756755}
757756
758- static void tg_dispatch_one_bio (struct throtl_grp * tg , bool rw ,
759- struct throtl_service_queue * parent_sq )
757+ static void tg_dispatch_one_bio (struct throtl_grp * tg , bool rw )
760758{
761759 struct throtl_service_queue * sq = & tg -> service_queue ;
762760 struct bio * bio ;
@@ -770,14 +768,13 @@ static void tg_dispatch_one_bio(struct throtl_grp *tg, bool rw,
770768 tg -> td -> nr_queued [rw ]-- ;
771769
772770 throtl_charge_bio (tg , bio );
773- bio_list_add (& parent_sq -> bio_lists [rw ], bio );
771+ bio_list_add (& sq -> parent_sq -> bio_lists [rw ], bio );
774772 bio -> bi_rw |= REQ_THROTTLED ;
775773
776774 throtl_trim_slice (tg , rw );
777775}
778776
779- static int throtl_dispatch_tg (struct throtl_grp * tg ,
780- struct throtl_service_queue * parent_sq )
777+ static int throtl_dispatch_tg (struct throtl_grp * tg )
781778{
782779 struct throtl_service_queue * sq = & tg -> service_queue ;
783780 unsigned int nr_reads = 0 , nr_writes = 0 ;
@@ -790,7 +787,7 @@ static int throtl_dispatch_tg(struct throtl_grp *tg,
790787 while ((bio = bio_list_peek (& sq -> bio_lists [READ ])) &&
791788 tg_may_dispatch (tg , bio , NULL )) {
792789
793- tg_dispatch_one_bio (tg , bio_data_dir (bio ), parent_sq );
790+ tg_dispatch_one_bio (tg , bio_data_dir (bio ));
794791 nr_reads ++ ;
795792
796793 if (nr_reads >= max_nr_reads )
@@ -800,7 +797,7 @@ static int throtl_dispatch_tg(struct throtl_grp *tg,
800797 while ((bio = bio_list_peek (& sq -> bio_lists [WRITE ])) &&
801798 tg_may_dispatch (tg , bio , NULL )) {
802799
803- tg_dispatch_one_bio (tg , bio_data_dir (bio ), parent_sq );
800+ tg_dispatch_one_bio (tg , bio_data_dir (bio ));
804801 nr_writes ++ ;
805802
806803 if (nr_writes >= max_nr_writes )
@@ -824,12 +821,12 @@ static int throtl_select_dispatch(struct throtl_service_queue *parent_sq)
824821 if (time_before (jiffies , tg -> disptime ))
825822 break ;
826823
827- throtl_dequeue_tg (tg , parent_sq );
824+ throtl_dequeue_tg (tg );
828825
829- nr_disp += throtl_dispatch_tg (tg , parent_sq );
826+ nr_disp += throtl_dispatch_tg (tg );
830827
831828 if (sq -> nr_queued [0 ] || sq -> nr_queued [1 ])
832- tg_update_disptime (tg , parent_sq );
829+ tg_update_disptime (tg );
833830
834831 if (nr_disp >= throtl_quantum )
835832 break ;
@@ -991,7 +988,7 @@ static int tg_set_conf(struct cgroup *cgrp, struct cftype *cft, const char *buf,
991988 throtl_start_new_slice (tg , 1 );
992989
993990 if (tg -> flags & THROTL_TG_PENDING ) {
994- tg_update_disptime (tg , & td -> service_queue );
991+ tg_update_disptime (tg );
995992 throtl_schedule_next_dispatch (td );
996993 }
997994
@@ -1142,12 +1139,12 @@ bool blk_throtl_bio(struct request_queue *q, struct bio *bio)
11421139 sq -> nr_queued [READ ], sq -> nr_queued [WRITE ]);
11431140
11441141 bio_associate_current (bio );
1145- throtl_add_bio_tg (bio , tg , & q -> td -> service_queue );
1142+ throtl_add_bio_tg (bio , tg );
11461143 throttled = true;
11471144
11481145 /* update @tg's dispatch time if @tg was empty before @bio */
11491146 if (tg -> flags & THROTL_TG_WAS_EMPTY ) {
1150- tg_update_disptime (tg , & td -> service_queue );
1147+ tg_update_disptime (tg );
11511148 throtl_schedule_next_dispatch (td );
11521149 }
11531150
@@ -1179,12 +1176,12 @@ void blk_throtl_drain(struct request_queue *q)
11791176 while ((tg = throtl_rb_first (parent_sq ))) {
11801177 struct throtl_service_queue * sq = & tg -> service_queue ;
11811178
1182- throtl_dequeue_tg (tg , parent_sq );
1179+ throtl_dequeue_tg (tg );
11831180
11841181 while ((bio = bio_list_peek (& sq -> bio_lists [READ ])))
1185- tg_dispatch_one_bio (tg , bio_data_dir (bio ), parent_sq );
1182+ tg_dispatch_one_bio (tg , bio_data_dir (bio ));
11861183 while ((bio = bio_list_peek (& sq -> bio_lists [WRITE ])))
1187- tg_dispatch_one_bio (tg , bio_data_dir (bio ), parent_sq );
1184+ tg_dispatch_one_bio (tg , bio_data_dir (bio ));
11881185 }
11891186 spin_unlock_irq (q -> queue_lock );
11901187
@@ -1205,7 +1202,7 @@ int blk_throtl_init(struct request_queue *q)
12051202 return - ENOMEM ;
12061203
12071204 INIT_DELAYED_WORK (& td -> dispatch_work , blk_throtl_dispatch_work_fn );
1208- throtl_service_queue_init (& td -> service_queue );
1205+ throtl_service_queue_init (& td -> service_queue , NULL );
12091206
12101207 q -> td = td ;
12111208 td -> queue = q ;
0 commit comments