[03/11] blk-throttle: ignore cgroup without io queued in blk_throtl_cancel_bios

Message ID 20221123060401.20392-4-shikemeng@huawei.com
State New
Headers
Series A few bugfix and cleanup patches for blk-throttle |

Commit Message

Kemeng Shi Nov. 23, 2022, 6:03 a.m. UTC
  Ignore cgroup without io queued in blk_throtl_cancel_bios for two
reasons:
1. Save cpu cycle for trying to dispatch cgroup which is no io queued.
2. Avoid non-consistent state that cgroup is inserted to service queue
without THROTL_TG_PENDING set as tg_update_disptime will unconditional
re-insert cgroup to service queue. If we are on the default hierarchy,
IO dispatched from child in tg_dispatch_one_bio will trigger inserting
cgroup to service queue without erase first and ruin the tree.

Signed-off-by: Kemeng Shi <shikemeng@huawei.com>
---
 block/blk-throttle.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
  

Comments

Tejun Heo Nov. 23, 2022, 6:13 p.m. UTC | #1
On Wed, Nov 23, 2022 at 02:03:53PM +0800, Kemeng Shi wrote:
> Ignore cgroup without io queued in blk_throtl_cancel_bios for two
> reasons:
> 1. Save cpu cycle for trying to dispatch cgroup which is no io queued.
> 2. Avoid non-consistent state that cgroup is inserted to service queue
> without THROTL_TG_PENDING set as tg_update_disptime will unconditional
> re-insert cgroup to service queue. If we are on the default hierarchy,
> IO dispatched from child in tg_dispatch_one_bio will trigger inserting
> cgroup to service queue without erase first and ruin the tree.
> 
> Signed-off-by: Kemeng Shi <shikemeng@huawei.com>
> ---
>  block/blk-throttle.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/block/blk-throttle.c b/block/blk-throttle.c
> index b33bcf53b36e..acfac916ed99 100644
> --- a/block/blk-throttle.c
> +++ b/block/blk-throttle.c
> @@ -1728,7 +1728,12 @@ void blk_throtl_cancel_bios(struct gendisk *disk)
>  		 * Set the flag to make sure throtl_pending_timer_fn() won't
>  		 * stop until all throttled bios are dispatched.
>  		 */
> -		blkg_to_tg(blkg)->flags |= THROTL_TG_CANCELING;
> +		tg->flags |= THROTL_TG_CANCELING;
> +
> +		/* No need to dispatch cgroup without io queued */

It's probably more important to mention that putting this in without PENDING
set can corrupt the tree in the future through double insertion.

> +		if (!(tg->flags & THROTL_TG_PENDING))
> +			continue;
> +

Other than than the above comment,

  Acked-by: Tejun Heo <tj@kernel.org>

Thanks.
  

Patch

diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index b33bcf53b36e..acfac916ed99 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -1728,7 +1728,12 @@  void blk_throtl_cancel_bios(struct gendisk *disk)
 		 * Set the flag to make sure throtl_pending_timer_fn() won't
 		 * stop until all throttled bios are dispatched.
 		 */
-		blkg_to_tg(blkg)->flags |= THROTL_TG_CANCELING;
+		tg->flags |= THROTL_TG_CANCELING;
+
+		/* No need to dispatch cgroup without io queued */
+		if (!(tg->flags & THROTL_TG_PENDING))
+			continue;
+
 		/*
 		 * Update disptime after setting the above flag to make sure
 		 * throtl_select_dispatch() won't exit without dispatching.