Skip to contentSkip to conversation

blk-throttle: fix zero wait time for iops throttled group

PATCH Applied Konstantin Khlebnikov 3 participants 7 messages Jul 8, 2019 – Jul 10, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 blk-throttle: fix zero wait time for iops throttled group

After commit 991f61fe7e1d ("Blk-throttle: reduce tail io latency when iops limit is enforced") wait time could be zero even if group is throttled and cannot issue requests right now. As a result throtl_select_dispatch() turns into busy-loop under irq-safe queue spinlock.

Fix is simple: always round up target time to the next throttle slice.

Fixes 991f61fe7e1d ("Blk-throttle: reduce tail io latency when iops limit is enforced")
Cc [email protected] # v4.19+
---
 block/blk-throttle.c |    9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
block/blk-throttle.c +3 -6
index 9ea7c0ecad10..8ab6c8153223 100644
@@ -881,13 +881,10 @@ static bool tg_with_in_iops_limit(struct throtl_grp *tg, struct bio *bio,
 	unsigned long jiffy_elapsed, jiffy_wait, jiffy_elapsed_rnd;
 	u64 tmp;
 
-	jiffy_elapsed = jiffy_elapsed_rnd = jiffies - tg->slice_start[rw];
-
-	/* Slice has just started. Consider one slice interval */
-	if (!jiffy_elapsed)
-		jiffy_elapsed_rnd = tg->td->throtl_slice;
+	jiffy_elapsed = jiffies - tg->slice_start[rw];
 
-	jiffy_elapsed_rnd = roundup(jiffy_elapsed_rnd, tg->td->throtl_slice);
+	/* Round up to the next throttle slice, wait time must be nonzero */
+	jiffy_elapsed_rnd = roundup(jiffy_elapsed + 1, tg->td->throtl_slice);
 
 	/*
 	 * jiffy_elapsed_rnd should not be a big value as minimum iops can be
#1 lore raw
Quoted 25 lines · Konstantin Khlebnikov

After commit 991f61fe7e1d ("Blk-throttle: reduce tail io latency when iops limit is enforced") wait time could be zero even if group is throttled and cannot issue requests right now. As a result throtl_select_dispatch() turns into busy-loop under irq-safe queue spinlock.

Fix is simple: always round up target time to the next throttle slice.

Fixes 991f61fe7e1d ("Blk-throttle: reduce tail io latency when iops limit is enforced")
Cc [email protected] # v4.19+
---
 block/blk-throttle.c |    9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
block/blk-throttle.c +0 -3
index 9ea7c0ecad10..8ab6c8153223 100644
@@ -881,13 +881,10 @@ static bool tg_with_in_iops_limit(struct throtl_grp *tg, struct bio *bio,
 	unsigned long jiffy_elapsed, jiffy_wait, jiffy_elapsed_rnd;
 	u64 tmp;
 
-	jiffy_elapsed = jiffy_elapsed_rnd = jiffies - tg->slice_start[rw];
-
-	/* Slice has just started. Consider one slice interval */

block/blk-throttle.c static bool tg_with_in_iops_limit(struct throtl_grp *tg, struct bio *bio, · line 890

Quoted 10 lines
block/blk-throttle.c +3 -3
-	if (!jiffy_elapsed)
-		jiffy_elapsed_rnd = tg->td->throtl_slice;
+	jiffy_elapsed = jiffies - tg->slice_start[rw];
 
-	jiffy_elapsed_rnd = roundup(jiffy_elapsed_rnd, tg->td->throtl_slice);
+	/* Round up to the next throttle slice, wait time must be nonzero */
+	jiffy_elapsed_rnd = roundup(jiffy_elapsed + 1, tg->td->throtl_slice);
 
 	/*
 	 * jiffy_elapsed_rnd should not be a big value as minimum iops can be

Did you use a tiny iops limit to run into this?

thanks,
-liubo

#2 lore raw
Quoted 30 lines · Liu Bo
Quoted 29 lines · Konstantin Khlebnikov

After commit 991f61fe7e1d ("Blk-throttle: reduce tail io latency when iops limit is enforced") wait time could be zero even if group is throttled and cannot issue requests right now. As a result throtl_select_dispatch() turns into busy-loop under irq-safe queue spinlock.

Fix is simple: always round up target time to the next throttle slice.

Fixes 991f61fe7e1d ("Blk-throttle: reduce tail io latency when iops limit is enforced")
Cc [email protected] # v4.19+
---
  block/blk-throttle.c |    9 +++------
  1 file changed, 3 insertions(+), 6 deletions(-)
block/blk-throttle.c +1 -5
index 9ea7c0ecad10..8ab6c8153223 100644
@@ -881,13 +881,10 @@ static bool tg_with_in_iops_limit(struct throtl_grp *tg, struct bio *bio,
  	unsigned long jiffy_elapsed, jiffy_wait, jiffy_elapsed_rnd;
  	u64 tmp;
 
-	jiffy_elapsed = jiffy_elapsed_rnd = jiffies - tg->slice_start[rw];
-
-	/* Slice has just started. Consider one slice interval */
-	if (!jiffy_elapsed)
-		jiffy_elapsed_rnd = tg->td->throtl_slice;
+	jiffy_elapsed = jiffies - tg->slice_start[rw];
 
Quoted 8 lines

block/blk-throttle.c static bool tg_with_in_iops_limit(struct throtl_grp *tg, struct bio *bio, · line 890

Quoted 6 lines
block/blk-throttle.c +2 -1
-	jiffy_elapsed_rnd = roundup(jiffy_elapsed_rnd, tg->td->throtl_slice);
+	/* Round up to the next throttle slice, wait time must be nonzero */
+	jiffy_elapsed_rnd = roundup(jiffy_elapsed + 1, tg->td->throtl_slice);
 
  	/*
  	 * jiffy_elapsed_rnd should not be a big value as minimum iops can be

Did you use a tiny iops limit to run into this?

Yep. 25 iops

also kernel built with HZ=250, this might be related

Quoted 4 lines

thanks,
-liubo

#3 lore raw
In reply to Konstantin Khlebnikov
Quoted 4 lines · Konstantin Khlebnikov

After commit 991f61fe7e1d ("Blk-throttle: reduce tail io latency when iops limit is enforced") wait time could be zero even if group is throttled and cannot issue requests right now. As a result throtl_select_dispatch() turns into busy-loop under irq-safe queue spinlock.

To be clear: this almost instantly kills entire machine - other cpus stuck at sending ipi.

Quoted 32 lines

Fix is simple: always round up target time to the next throttle slice.

Fixes 991f61fe7e1d ("Blk-throttle: reduce tail io latency when iops limit is enforced")
Cc [email protected] # v4.19+
---
  block/blk-throttle.c |    9 +++------
  1 file changed, 3 insertions(+), 6 deletions(-)
block/blk-throttle.c +3 -6
index 9ea7c0ecad10..8ab6c8153223 100644
@@ -881,13 +881,10 @@ static bool tg_with_in_iops_limit(struct throtl_grp *tg, struct bio *bio,
  	unsigned long jiffy_elapsed, jiffy_wait, jiffy_elapsed_rnd;
  	u64 tmp;
 
-	jiffy_elapsed = jiffy_elapsed_rnd = jiffies - tg->slice_start[rw];
-
-	/* Slice has just started. Consider one slice interval */
-	if (!jiffy_elapsed)
-		jiffy_elapsed_rnd = tg->td->throtl_slice;
+	jiffy_elapsed = jiffies - tg->slice_start[rw];
 
-	jiffy_elapsed_rnd = roundup(jiffy_elapsed_rnd, tg->td->throtl_slice);
+	/* Round up to the next throttle slice, wait time must be nonzero */
+	jiffy_elapsed_rnd = roundup(jiffy_elapsed + 1, tg->td->throtl_slice);
 
  	/*
  	 * jiffy_elapsed_rnd should not be a big value as minimum iops can be
maintainer Applied
#4 lore raw
In reply to Konstantin Khlebnikov
Quoted 6 lines · Konstantin Khlebnikov

After commit 991f61fe7e1d ("Blk-throttle: reduce tail io latency when iops limit is enforced") wait time could be zero even if group is throttled and cannot issue requests right now. As a result throtl_select_dispatch() turns into busy-loop under irq-safe queue spinlock.

Fix is simple: always round up target time to the next throttle slice.

Applied, thanks. In the future, please break lines at 72 chars in commit messages, I fixed it up.

Signature · 1 line
Jens Axboe
#5 lore raw
Quoted 11 lines · Jens Axboe
Quoted 6 lines · Konstantin Khlebnikov

After commit 991f61fe7e1d ("Blk-throttle: reduce tail io latency when iops limit is enforced") wait time could be zero even if group is throttled and cannot issue requests right now. As a result throtl_select_dispatch() turns into busy-loop under irq-safe queue spinlock.

Fix is simple: always round up target time to the next throttle slice.

Applied, thanks. In the future, please break lines at 72 chars in commit messages, I fixed it up.

Ok, but Documentation/process/submitting-patches.rst and scripts/checkpatch.pl recommends 75 chars per line.

maintainer
#6 lore raw
Quoted 7 lines · Konstantin Khlebnikov
Quoted 6 lines · Jens Axboe
Quoted 5 lines · Konstantin Khlebnikov

After commit 991f61fe7e1d ("Blk-throttle: reduce tail io latency when iops limit is enforced") wait time could be zero even if group is throttled and cannot issue requests right now. As a result throtl_select_dispatch() turns into busy-loop under irq-safe queue spinlock.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Fix is simple: always round up target time to the next throttle slice.

Applied, thanks. In the future, please break lines at 72 chars in commit messages, I fixed it up.

Ok, but Documentation/process/submitting-patches.rst and scripts/checkpatch.pl recommends 75 chars per line.

Huh, oh well. Not a big deal for me, line breaking is easily automated.

Signature · 1 line
Jens Axboe