@@ -27,6 +27,17 @@ static struct blkcg_policy blkcg_policy_throtl;
2727static struct workqueue_struct * kthrotld_workqueue ;
2828
2929struct throtl_service_queue {
30+ /*
31+ * Bios queued directly to this service_queue or dispatched from
32+ * children throtl_grp's.
33+ */
34+ struct bio_list bio_lists [2 ]; /* queued bios [READ/WRITE] */
35+ unsigned int nr_queued [2 ]; /* number of queued bios */
36+
37+ /*
38+ * RB tree of active children throtl_grp's, which are sorted by
39+ * their ->disptime.
40+ */
3041 struct rb_root pending_tree ; /* RB tree of active tgs */
3142 struct rb_node * first_pending ; /* first node in the tree */
3243 unsigned int nr_pending ; /* # queued in the tree */
@@ -69,12 +80,6 @@ struct throtl_grp {
6980
7081 unsigned int flags ;
7182
72- /* Two lists for READ and WRITE */
73- struct bio_list bio_lists [2 ];
74-
75- /* Number of queued bios on READ and WRITE lists */
76- unsigned int nr_queued [2 ];
77-
7883 /* bytes per second rate limits */
7984 uint64_t bps [2 ];
8085
@@ -193,6 +198,8 @@ static void tg_stats_alloc_fn(struct work_struct *work)
193198/* init a service_queue, assumes the caller zeroed it */
194199static void throtl_service_queue_init (struct throtl_service_queue * sq )
195200{
201+ bio_list_init (& sq -> bio_lists [0 ]);
202+ bio_list_init (& sq -> bio_lists [1 ]);
196203 sq -> pending_tree = RB_ROOT ;
197204}
198205
@@ -204,8 +211,6 @@ static void throtl_pd_init(struct blkcg_gq *blkg)
204211 throtl_service_queue_init (& tg -> service_queue );
205212 RB_CLEAR_NODE (& tg -> rb_node );
206213 tg -> td = blkg -> q -> td ;
207- bio_list_init (& tg -> bio_lists [0 ]);
208- bio_list_init (& tg -> bio_lists [1 ]);
209214
210215 tg -> bps [READ ] = -1 ;
211216 tg -> bps [WRITE ] = -1 ;
@@ -624,7 +629,8 @@ static bool tg_may_dispatch(struct throtl_grp *tg, struct bio *bio,
624629 * this function with a different bio if there are other bios
625630 * queued.
626631 */
627- BUG_ON (tg -> nr_queued [rw ] && bio != bio_list_peek (& tg -> bio_lists [rw ]));
632+ BUG_ON (tg -> service_queue .nr_queued [rw ] &&
633+ bio != bio_list_peek (& tg -> service_queue .bio_lists [rw ]));
628634
629635 /* If tg->bps = -1, then BW is unlimited */
630636 if (tg -> bps [rw ] == -1 && tg -> iops [rw ] == -1 ) {
@@ -703,26 +709,28 @@ static void throtl_charge_bio(struct throtl_grp *tg, struct bio *bio)
703709static void throtl_add_bio_tg (struct bio * bio , struct throtl_grp * tg ,
704710 struct throtl_service_queue * parent_sq )
705711{
712+ struct throtl_service_queue * sq = & tg -> service_queue ;
706713 bool rw = bio_data_dir (bio );
707714
708- bio_list_add (& tg -> bio_lists [rw ], bio );
715+ bio_list_add (& sq -> bio_lists [rw ], bio );
709716 /* Take a bio reference on tg */
710717 blkg_get (tg_to_blkg (tg ));
711- tg -> nr_queued [rw ]++ ;
718+ sq -> nr_queued [rw ]++ ;
712719 tg -> td -> nr_queued [rw ]++ ;
713720 throtl_enqueue_tg (tg , parent_sq );
714721}
715722
716723static void tg_update_disptime (struct throtl_grp * tg ,
717724 struct throtl_service_queue * parent_sq )
718725{
726+ struct throtl_service_queue * sq = & tg -> service_queue ;
719727 unsigned long read_wait = -1 , write_wait = -1 , min_wait = -1 , disptime ;
720728 struct bio * bio ;
721729
722- if ((bio = bio_list_peek (& tg -> bio_lists [READ ])))
730+ if ((bio = bio_list_peek (& sq -> bio_lists [READ ])))
723731 tg_may_dispatch (tg , bio , & read_wait );
724732
725- if ((bio = bio_list_peek (& tg -> bio_lists [WRITE ])))
733+ if ((bio = bio_list_peek (& sq -> bio_lists [WRITE ])))
726734 tg_may_dispatch (tg , bio , & write_wait );
727735
728736 min_wait = min (read_wait , write_wait );
@@ -737,10 +745,11 @@ static void tg_update_disptime(struct throtl_grp *tg,
737745static void tg_dispatch_one_bio (struct throtl_grp * tg , bool rw ,
738746 struct bio_list * bl )
739747{
748+ struct throtl_service_queue * sq = & tg -> service_queue ;
740749 struct bio * bio ;
741750
742- bio = bio_list_pop (& tg -> bio_lists [rw ]);
743- tg -> nr_queued [rw ]-- ;
751+ bio = bio_list_pop (& sq -> bio_lists [rw ]);
752+ sq -> nr_queued [rw ]-- ;
744753 /* Drop bio reference on blkg */
745754 blkg_put (tg_to_blkg (tg ));
746755
@@ -756,14 +765,15 @@ static void tg_dispatch_one_bio(struct throtl_grp *tg, bool rw,
756765
757766static int throtl_dispatch_tg (struct throtl_grp * tg , struct bio_list * bl )
758767{
768+ struct throtl_service_queue * sq = & tg -> service_queue ;
759769 unsigned int nr_reads = 0 , nr_writes = 0 ;
760770 unsigned int max_nr_reads = throtl_grp_quantum * 3 /4 ;
761771 unsigned int max_nr_writes = throtl_grp_quantum - max_nr_reads ;
762772 struct bio * bio ;
763773
764774 /* Try to dispatch 75% READS and 25% WRITES */
765775
766- while ((bio = bio_list_peek (& tg -> bio_lists [READ ])) &&
776+ while ((bio = bio_list_peek (& sq -> bio_lists [READ ])) &&
767777 tg_may_dispatch (tg , bio , NULL )) {
768778
769779 tg_dispatch_one_bio (tg , bio_data_dir (bio ), bl );
@@ -773,7 +783,7 @@ static int throtl_dispatch_tg(struct throtl_grp *tg, struct bio_list *bl)
773783 break ;
774784 }
775785
776- while ((bio = bio_list_peek (& tg -> bio_lists [WRITE ])) &&
786+ while ((bio = bio_list_peek (& sq -> bio_lists [WRITE ])) &&
777787 tg_may_dispatch (tg , bio , NULL )) {
778788
779789 tg_dispatch_one_bio (tg , bio_data_dir (bio ), bl );
@@ -790,10 +800,10 @@ static int throtl_select_dispatch(struct throtl_service_queue *parent_sq,
790800 struct bio_list * bl )
791801{
792802 unsigned int nr_disp = 0 ;
793- struct throtl_grp * tg ;
794803
795804 while (1 ) {
796- tg = throtl_rb_first (parent_sq );
805+ struct throtl_grp * tg = throtl_rb_first (parent_sq );
806+ struct throtl_service_queue * sq = & tg -> service_queue ;
797807
798808 if (!tg )
799809 break ;
@@ -805,7 +815,7 @@ static int throtl_select_dispatch(struct throtl_service_queue *parent_sq,
805815
806816 nr_disp += throtl_dispatch_tg (tg , bl );
807817
808- if (tg -> nr_queued [0 ] || tg -> nr_queued [1 ])
818+ if (sq -> nr_queued [0 ] || sq -> nr_queued [1 ])
809819 tg_update_disptime (tg , parent_sq );
810820
811821 if (nr_disp >= throtl_quantum )
@@ -1043,6 +1053,7 @@ bool blk_throtl_bio(struct request_queue *q, struct bio *bio)
10431053{
10441054 struct throtl_data * td = q -> td ;
10451055 struct throtl_grp * tg ;
1056+ struct throtl_service_queue * sq ;
10461057 bool rw = bio_data_dir (bio ), update_disptime = true;
10471058 struct blkcg * blkcg ;
10481059 bool throttled = false;
@@ -1077,7 +1088,9 @@ bool blk_throtl_bio(struct request_queue *q, struct bio *bio)
10771088 if (unlikely (!tg ))
10781089 goto out_unlock ;
10791090
1080- if (tg -> nr_queued [rw ]) {
1091+ sq = & tg -> service_queue ;
1092+
1093+ if (sq -> nr_queued [rw ]) {
10811094 /*
10821095 * There is already another bio queued in same dir. No
10831096 * need to update dispatch time.
@@ -1112,7 +1125,7 @@ bool blk_throtl_bio(struct request_queue *q, struct bio *bio)
11121125 rw == READ ? 'R' : 'W' ,
11131126 tg -> bytes_disp [rw ], bio -> bi_size , tg -> bps [rw ],
11141127 tg -> io_disp [rw ], tg -> iops [rw ],
1115- tg -> nr_queued [READ ], tg -> nr_queued [WRITE ]);
1128+ sq -> nr_queued [READ ], sq -> nr_queued [WRITE ]);
11161129
11171130 bio_associate_current (bio );
11181131 throtl_add_bio_tg (bio , tg , & q -> td -> service_queue );
@@ -1151,11 +1164,13 @@ void blk_throtl_drain(struct request_queue *q)
11511164 bio_list_init (& bl );
11521165
11531166 while ((tg = throtl_rb_first (parent_sq ))) {
1167+ struct throtl_service_queue * sq = & tg -> service_queue ;
1168+
11541169 throtl_dequeue_tg (tg , parent_sq );
11551170
1156- while ((bio = bio_list_peek (& tg -> bio_lists [READ ])))
1171+ while ((bio = bio_list_peek (& sq -> bio_lists [READ ])))
11571172 tg_dispatch_one_bio (tg , bio_data_dir (bio ), & bl );
1158- while ((bio = bio_list_peek (& tg -> bio_lists [WRITE ])))
1173+ while ((bio = bio_list_peek (& sq -> bio_lists [WRITE ])))
11591174 tg_dispatch_one_bio (tg , bio_data_dir (bio ), & bl );
11601175 }
11611176 spin_unlock_irq (q -> queue_lock );
0 commit comments