Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

blk-throttle: Rename tg_may_dispatch() to tg_dispatch_time()

tg_may_dispatch() can directly indicate whether bio can be dispatched by
returning the time to wait, without the need for the redundant "wait"
parameter. Remove it and modify the function's return type accordingly.

Since we have determined by the return time whether bio can be dispatched,
rename tg_may_dispatch() to tg_dispatch_time().

Signed-off-by: Zizhi Wo <wozizhi@huawei.com>
Reviewed-by: Yu Kuai <yukuai3@huawei.com>
Signed-off-by: Zizhi Wo <wozizhi@huaweicloud.com>
Link: https://lore.kernel.org/r/20250506020935.655574-2-wozizhi@huaweicloud.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Zizhi Wo and committed by
Jens Axboe
fd6c08b2 cf724e5e

+15 -25
+15 -25
block/blk-throttle.c
··· 794 794 } 795 795 796 796 /* 797 - * Returns whether one can dispatch a bio or not. Also returns approx number 798 - * of jiffies to wait before this bio is with-in IO rate and can be dispatched 797 + * Returns approx number of jiffies to wait before this bio is with-in IO rate 798 + * and can be dispatched. 799 799 */ 800 - static bool tg_may_dispatch(struct throtl_grp *tg, struct bio *bio, 801 - unsigned long *wait) 800 + static unsigned long tg_dispatch_time(struct throtl_grp *tg, struct bio *bio) 802 801 { 803 802 bool rw = bio_data_dir(bio); 804 - unsigned long bps_wait = 0, iops_wait = 0, max_wait = 0; 803 + unsigned long bps_wait, iops_wait, max_wait; 805 804 u64 bps_limit = tg_bps_limit(tg, rw); 806 805 u32 iops_limit = tg_iops_limit(tg, rw); 807 806 ··· 815 816 816 817 /* If tg->bps = -1, then BW is unlimited */ 817 818 if ((bps_limit == U64_MAX && iops_limit == UINT_MAX) || 818 - tg->flags & THROTL_TG_CANCELING) { 819 - if (wait) 820 - *wait = 0; 821 - return true; 822 - } 819 + tg->flags & THROTL_TG_CANCELING) 820 + return 0; 823 821 824 822 /* 825 823 * If previous slice expired, start a new one otherwise renew/extend ··· 836 840 837 841 bps_wait = tg_within_bps_limit(tg, bio, bps_limit); 838 842 iops_wait = tg_within_iops_limit(tg, bio, iops_limit); 839 - if (bps_wait + iops_wait == 0) { 840 - if (wait) 841 - *wait = 0; 842 - return true; 843 - } 843 + if (bps_wait + iops_wait == 0) 844 + return 0; 844 845 845 846 max_wait = max(bps_wait, iops_wait); 846 - 847 - if (wait) 848 - *wait = max_wait; 849 847 850 848 if (time_before(tg->slice_end[rw], jiffies + max_wait)) 851 849 throtl_extend_slice(tg, rw, jiffies + max_wait); 852 850 853 - return false; 851 + return max_wait; 854 852 } 855 853 856 854 static void throtl_charge_bio(struct throtl_grp *tg, struct bio *bio) ··· 895 905 static void tg_update_disptime(struct throtl_grp *tg) 896 906 { 897 907 struct throtl_service_queue *sq = &tg->service_queue; 898 - unsigned long read_wait = -1, write_wait = -1, min_wait = -1, disptime; 908 + unsigned long read_wait = -1, write_wait = -1, min_wait, disptime; 899 909 struct bio *bio; 900 910 901 911 bio = throtl_peek_queued(&sq->queued[READ]); 902 912 if (bio) 903 - tg_may_dispatch(tg, bio, &read_wait); 913 + read_wait = tg_dispatch_time(tg, bio); 904 914 905 915 bio = throtl_peek_queued(&sq->queued[WRITE]); 906 916 if (bio) 907 - tg_may_dispatch(tg, bio, &write_wait); 917 + write_wait = tg_dispatch_time(tg, bio); 908 918 909 919 min_wait = min(read_wait, write_wait); 910 920 disptime = jiffies + min_wait; ··· 982 992 /* Try to dispatch 75% READS and 25% WRITES */ 983 993 984 994 while ((bio = throtl_peek_queued(&sq->queued[READ])) && 985 - tg_may_dispatch(tg, bio, NULL)) { 995 + tg_dispatch_time(tg, bio) == 0) { 986 996 987 997 tg_dispatch_one_bio(tg, READ); 988 998 nr_reads++; ··· 992 1002 } 993 1003 994 1004 while ((bio = throtl_peek_queued(&sq->queued[WRITE])) && 995 - tg_may_dispatch(tg, bio, NULL)) { 1005 + tg_dispatch_time(tg, bio) == 0) { 996 1006 997 1007 tg_dispatch_one_bio(tg, WRITE); 998 1008 nr_writes++; ··· 1651 1661 if (tg->service_queue.nr_queued[rw]) 1652 1662 return false; 1653 1663 1654 - return tg_may_dispatch(tg, bio, NULL); 1664 + return tg_dispatch_time(tg, bio) == 0; 1655 1665 } 1656 1666 1657 1667 bool __blk_throtl_bio(struct bio *bio)