cgroups.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next 0/4] cleanup and fixes for 'carryover_ios/bytes'
@ 2023-08-15  1:41 Yu Kuai
  2023-08-15  1:41 ` [PATCH -next 1/4] blk-throttle: print signed value 'carryover_bytes/ios' for user Yu Kuai
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Yu Kuai @ 2023-08-15  1:41 UTC (permalink / raw)
  To: tj-DgEjT+Ai2ygdnm+yROfE0A, josef-DigfWCa+lFGyeJad7bwFQA,
	axboe-tSWWG44O7X1aa/9Udqfwiw, yukuai3-hv44wF8Li93QT0dZR+AlfA,
	mkoutny-IBi9RG/b67k
  Cc: cgroups-u79uwXL29TY76Z2rM5mHXA,
	linux-block-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	yukuai1-XF6JlduFytWkHkcT6e4Xnw, yi.zhang-hv44wF8Li93QT0dZR+AlfA,
	yangerkun-hv44wF8Li93QT0dZR+AlfA

From: Yu Kuai <yukuai3-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>

Patch 1 print signed value for 'carryover_ios/bytes' to user.

Patch 2 fix that comparation ”unsigned value < negative value“ will
pass, causing that io won't be throttled in the silce.

Patch 3,4 fix that 'carryover_ios/bytes' is not cleared while
'io/bytes_disp' is cleared, causing that throttle is not accurate.

Yu Kuai (4):
  blk-throttle: print signed value 'carryover_bytes/ios' for user
  blk-throttle: fix wrong comparation while 'carryover_ios/bytes' is
    negative
  blk-throttle: use calculate_io/bytes_allowed() for throtl_trim_slice()
  blk-throttle: consider 'carryover_ios/bytes' in throtl_trim_slice()

 block/blk-throttle.c | 105 +++++++++++++++++++++----------------------
 block/blk-throttle.h |   4 +-
 2 files changed, 54 insertions(+), 55 deletions(-)

-- 
2.39.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH -next 1/4] blk-throttle: print signed value 'carryover_bytes/ios' for user
  2023-08-15  1:41 [PATCH -next 0/4] cleanup and fixes for 'carryover_ios/bytes' Yu Kuai
@ 2023-08-15  1:41 ` Yu Kuai
       [not found] ` <20230815014123.368929-1-yukuai1-XF6JlduFytWkHkcT6e4Xnw@public.gmane.org>
  2023-08-15  1:41 ` [PATCH -next 4/4] blk-throttle: consider 'carryover_ios/bytes' in throtl_trim_slice() Yu Kuai
  2 siblings, 0 replies; 6+ messages in thread
From: Yu Kuai @ 2023-08-15  1:41 UTC (permalink / raw)
  To: tj, josef, axboe, yukuai3, mkoutny
  Cc: cgroups, linux-block, linux-kernel, yukuai1, yi.zhang, yangerkun

From: Yu Kuai <yukuai3@huawei.com>

'carryover_bytes/ios' can be negative, indicate that some bio is
dispatched in advance within slice while configuration is updated.
Print a huge value is not user-friendly.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 block/blk-throttle.c | 2 +-
 block/blk-throttle.h | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index 7397ff199d66..5184f17f5129 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -816,7 +816,7 @@ static void tg_update_carryover(struct throtl_grp *tg)
 		__tg_update_carryover(tg, WRITE);
 
 	/* see comments in struct throtl_grp for meaning of these fields. */
-	throtl_log(&tg->service_queue, "%s: %llu %llu %u %u\n", __func__,
+	throtl_log(&tg->service_queue, "%s: %lld %lld %d %d\n", __func__,
 		   tg->carryover_bytes[READ], tg->carryover_bytes[WRITE],
 		   tg->carryover_ios[READ], tg->carryover_ios[WRITE]);
 }
diff --git a/block/blk-throttle.h b/block/blk-throttle.h
index d1ccbfe9f797..bffbc9cfc8ab 100644
--- a/block/blk-throttle.h
+++ b/block/blk-throttle.h
@@ -127,8 +127,8 @@ struct throtl_grp {
 	 * bytes/ios are waited already in previous configuration, and they will
 	 * be used to calculate wait time under new configuration.
 	 */
-	uint64_t carryover_bytes[2];
-	unsigned int carryover_ios[2];
+	long long carryover_bytes[2];
+	int carryover_ios[2];
 
 	unsigned long last_check_time;
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH -next 2/4] blk-throttle: fix wrong comparation while 'carryover_ios/bytes' is negative
       [not found] ` <20230815014123.368929-1-yukuai1-XF6JlduFytWkHkcT6e4Xnw@public.gmane.org>
@ 2023-08-15  1:41   ` Yu Kuai
  2023-08-15  1:41   ` [PATCH -next 3/4] blk-throttle: use calculate_io/bytes_allowed() for throtl_trim_slice() Yu Kuai
  1 sibling, 0 replies; 6+ messages in thread
From: Yu Kuai @ 2023-08-15  1:41 UTC (permalink / raw)
  To: tj-DgEjT+Ai2ygdnm+yROfE0A, josef-DigfWCa+lFGyeJad7bwFQA,
	axboe-tSWWG44O7X1aa/9Udqfwiw, yukuai3-hv44wF8Li93QT0dZR+AlfA,
	mkoutny-IBi9RG/b67k
  Cc: cgroups-u79uwXL29TY76Z2rM5mHXA,
	linux-block-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	yukuai1-XF6JlduFytWkHkcT6e4Xnw, yi.zhang-hv44wF8Li93QT0dZR+AlfA,
	yangerkun-hv44wF8Li93QT0dZR+AlfA

From: Yu Kuai <yukuai3-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>

carryover_ios/bytes[] can be negative in the case that ios are
dispatched in the slice in advance, and then configuration is updated.
For example:

1) set iops limit to 1000, and slice start is 0, slice end is 100ms;
2) current time is 0, and 100 ios are dispatched, those ios will not be
   throttled, hence io_disp is 100;
3) still at current time 0, update iops limit to 100, then carryover_ios
   is (0 - 100) = -100;
4) then, dispatch a new io at time 0, the expected result is that this
   io will wait for 1s. The calculation in tg_within_iops_limit:

   io_disp = 0;
   io_allowed = calculate_io_allowed + carryover_ios
	      = 10 + (-100) = -90;
   io won't be throttled if (io_disp + 1 < io_allowed) passed.

Before this patch, in step 4) (io_disp + 1 < io_allowed) is passed,
because -90 for unsigned value is very huge, and such io won't be
throttled.

Fix this problem by checking if 'io/bytes_allowed' is negative first.

Signed-off-by: Yu Kuai <yukuai3-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
---
 block/blk-throttle.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index 5184f17f5129..7c93144d03da 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -825,7 +825,7 @@ static unsigned long tg_within_iops_limit(struct throtl_grp *tg, struct bio *bio
 				 u32 iops_limit)
 {
 	bool rw = bio_data_dir(bio);
-	unsigned int io_allowed;
+	int io_allowed;
 	unsigned long jiffy_elapsed, jiffy_wait, jiffy_elapsed_rnd;
 
 	if (iops_limit == UINT_MAX) {
@@ -838,9 +838,8 @@ static unsigned long tg_within_iops_limit(struct throtl_grp *tg, struct bio *bio
 	jiffy_elapsed_rnd = roundup(jiffy_elapsed + 1, tg->td->throtl_slice);
 	io_allowed = calculate_io_allowed(iops_limit, jiffy_elapsed_rnd) +
 		     tg->carryover_ios[rw];
-	if (tg->io_disp[rw] + 1 <= io_allowed) {
+	if (io_allowed > 0 && tg->io_disp[rw] + 1 <= io_allowed)
 		return 0;
-	}
 
 	/* Calc approx time to dispatch */
 	jiffy_wait = jiffy_elapsed_rnd - jiffy_elapsed;
@@ -851,7 +850,8 @@ static unsigned long tg_within_bps_limit(struct throtl_grp *tg, struct bio *bio,
 				u64 bps_limit)
 {
 	bool rw = bio_data_dir(bio);
-	u64 bytes_allowed, extra_bytes;
+	long long bytes_allowed;
+	u64 extra_bytes;
 	unsigned long jiffy_elapsed, jiffy_wait, jiffy_elapsed_rnd;
 	unsigned int bio_size = throtl_bio_data_size(bio);
 
@@ -869,9 +869,8 @@ static unsigned long tg_within_bps_limit(struct throtl_grp *tg, struct bio *bio,
 	jiffy_elapsed_rnd = roundup(jiffy_elapsed_rnd, tg->td->throtl_slice);
 	bytes_allowed = calculate_bytes_allowed(bps_limit, jiffy_elapsed_rnd) +
 			tg->carryover_bytes[rw];
-	if (tg->bytes_disp[rw] + bio_size <= bytes_allowed) {
+	if (bytes_allowed > 0 && tg->bytes_disp[rw] + bio_size <= bytes_allowed)
 		return 0;
-	}
 
 	/* Calc approx time to dispatch */
 	extra_bytes = tg->bytes_disp[rw] + bio_size - bytes_allowed;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH -next 3/4] blk-throttle: use calculate_io/bytes_allowed() for throtl_trim_slice()
       [not found] ` <20230815014123.368929-1-yukuai1-XF6JlduFytWkHkcT6e4Xnw@public.gmane.org>
  2023-08-15  1:41   ` [PATCH -next 2/4] blk-throttle: fix wrong comparation while 'carryover_ios/bytes' is negative Yu Kuai
@ 2023-08-15  1:41   ` Yu Kuai
  2023-08-15 15:48     ` kernel test robot
  1 sibling, 1 reply; 6+ messages in thread
From: Yu Kuai @ 2023-08-15  1:41 UTC (permalink / raw)
  To: tj-DgEjT+Ai2ygdnm+yROfE0A, josef-DigfWCa+lFGyeJad7bwFQA,
	axboe-tSWWG44O7X1aa/9Udqfwiw, yukuai3-hv44wF8Li93QT0dZR+AlfA,
	mkoutny-IBi9RG/b67k
  Cc: cgroups-u79uwXL29TY76Z2rM5mHXA,
	linux-block-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	yukuai1-XF6JlduFytWkHkcT6e4Xnw, yi.zhang-hv44wF8Li93QT0dZR+AlfA,
	yangerkun-hv44wF8Li93QT0dZR+AlfA

From: Yu Kuai <yukuai3-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>

There are no functional changes, just make the code cleaner.

Signed-off-by: Yu Kuai <yukuai3-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
---
 block/blk-throttle.c | 81 +++++++++++++++++++++-----------------------
 1 file changed, 38 insertions(+), 43 deletions(-)

diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index 7c93144d03da..e5296960c799 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -697,11 +697,40 @@ static bool throtl_slice_used(struct throtl_grp *tg, bool rw)
 	return true;
 }
 
+static unsigned int calculate_io_allowed(u32 iops_limit,
+					 unsigned long jiffy_elapsed)
+{
+	unsigned int io_allowed;
+	u64 tmp;
+
+	/*
+	 * jiffy_elapsed should not be a big value as minimum iops can be
+	 * 1 then at max jiffy elapsed should be equivalent of 1 second as we
+	 * will allow dispatch after 1 second and after that slice should
+	 * have been trimmed.
+	 */
+
+	tmp = (u64)iops_limit * jiffy_elapsed;
+	do_div(tmp, HZ);
+
+	if (tmp > UINT_MAX)
+		io_allowed = UINT_MAX;
+	else
+		io_allowed = tmp;
+
+	return io_allowed;
+}
+
+static u64 calculate_bytes_allowed(u64 bps_limit, unsigned long jiffy_elapsed)
+{
+	return mul_u64_u64_div_u64(bps_limit, (u64)jiffy_elapsed, (u64)HZ);
+}
+
 /* Trim the used slices and adjust slice start accordingly */
 static inline void throtl_trim_slice(struct throtl_grp *tg, bool rw)
 {
-	unsigned long nr_slices, time_elapsed, io_trim;
-	u64 bytes_trim, tmp;
+	unsigned long time_elapsed, io_trim;
+	u64 bytes_trim;
 
 	BUG_ON(time_before(tg->slice_end[rw], tg->slice_start[rw]));
 
@@ -723,19 +752,14 @@ static inline void throtl_trim_slice(struct throtl_grp *tg, bool rw)
 
 	throtl_set_slice_end(tg, rw, jiffies + tg->td->throtl_slice);
 
-	time_elapsed = jiffies - tg->slice_start[rw];
-
-	nr_slices = time_elapsed / tg->td->throtl_slice;
-
-	if (!nr_slices)
+	time_elapsed = rounddown(jiffies - tg->slice_start[rw],
+				 tg->td->throtl_slice);
+	if (!time_elapsed)
 		return;
-	tmp = tg_bps_limit(tg, rw) * tg->td->throtl_slice * nr_slices;
-	do_div(tmp, HZ);
-	bytes_trim = tmp;
-
-	io_trim = (tg_iops_limit(tg, rw) * tg->td->throtl_slice * nr_slices) /
-		HZ;
 
+	bytes_trim = calculate_bytes_allowed(tg_bps_limit(tg, rw),
+					     time_elapsed);
+	io_trim = calculate_io_allowed(tg_iops_limit(tg, rw), time_elapsed);
 	if (!bytes_trim && !io_trim)
 		return;
 
@@ -749,7 +773,7 @@ static inline void throtl_trim_slice(struct throtl_grp *tg, bool rw)
 	else
 		tg->io_disp[rw] = 0;
 
-	tg->slice_start[rw] += nr_slices * tg->td->throtl_slice;
+	tg->slice_start[rw] += time_elapsed;
 
 	throtl_log(&tg->service_queue,
 		   "[%c] trim slice nr=%lu bytes=%llu io=%lu start=%lu end=%lu jiffies=%lu",
@@ -757,35 +781,6 @@ static inline void throtl_trim_slice(struct throtl_grp *tg, bool rw)
 		   tg->slice_start[rw], tg->slice_end[rw], jiffies);
 }
 
-static unsigned int calculate_io_allowed(u32 iops_limit,
-					 unsigned long jiffy_elapsed)
-{
-	unsigned int io_allowed;
-	u64 tmp;
-
-	/*
-	 * jiffy_elapsed should not be a big value as minimum iops can be
-	 * 1 then at max jiffy elapsed should be equivalent of 1 second as we
-	 * will allow dispatch after 1 second and after that slice should
-	 * have been trimmed.
-	 */
-
-	tmp = (u64)iops_limit * jiffy_elapsed;
-	do_div(tmp, HZ);
-
-	if (tmp > UINT_MAX)
-		io_allowed = UINT_MAX;
-	else
-		io_allowed = tmp;
-
-	return io_allowed;
-}
-
-static u64 calculate_bytes_allowed(u64 bps_limit, unsigned long jiffy_elapsed)
-{
-	return mul_u64_u64_div_u64(bps_limit, (u64)jiffy_elapsed, (u64)HZ);
-}
-
 static void __tg_update_carryover(struct throtl_grp *tg, bool rw)
 {
 	unsigned long jiffy_elapsed = jiffies - tg->slice_start[rw];
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH -next 4/4] blk-throttle: consider 'carryover_ios/bytes' in throtl_trim_slice()
  2023-08-15  1:41 [PATCH -next 0/4] cleanup and fixes for 'carryover_ios/bytes' Yu Kuai
  2023-08-15  1:41 ` [PATCH -next 1/4] blk-throttle: print signed value 'carryover_bytes/ios' for user Yu Kuai
       [not found] ` <20230815014123.368929-1-yukuai1-XF6JlduFytWkHkcT6e4Xnw@public.gmane.org>
@ 2023-08-15  1:41 ` Yu Kuai
  2 siblings, 0 replies; 6+ messages in thread
From: Yu Kuai @ 2023-08-15  1:41 UTC (permalink / raw)
  To: tj, josef, axboe, yukuai3, mkoutny
  Cc: cgroups, linux-block, linux-kernel, yukuai1, yi.zhang, yangerkun

From: Yu Kuai <yukuai3@huawei.com>

Currently, 'carryover_ios/bytes' is not handled in throtl_trim_slice(),
for consequence, 'carryover_ios/bytes' will be used to throttle bio
multiple times, for example:

1) set iops limit to 100, and slice start is 0, slice end is 100ms;
2) current time is 0, and 10 ios are dispatched, those io won't be
   throttled and io_disp is 10;
3) still at current time 0, update iops limit to 1000, carryover_ios is
   updated to (0 - 10) = -10;
4) in this slice(0 - 100ms), io_allowed = 100 + (-10) = 90, which means
   only 90 ios can be dispatched without waiting;
5) assume that io is throttled in slice(0 - 100ms), and
   throtl_trim_slice() update silce to (100ms - 200ms). In this case,
   'carryover_ios/bytes' is not cleared and still only 90 ios can be
   dispatched between 100ms - 200ms.

Fix this problem by updating 'carryover_ios/bytes' in
throtl_trim_slice().

Fixes: a880ae93e5b5 ("blk-throttle: fix io hung due to configuration updates")
Reported-by: zhuxiaohui <zhuxiaohui.400@bytedance.com>
Link: https://lore.kernel.org/all/20230812072116.42321-1-zhuxiaohui.400@bytedance.com/
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 block/blk-throttle.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index e5296960c799..75b4a78c1e45 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -729,8 +729,9 @@ static u64 calculate_bytes_allowed(u64 bps_limit, unsigned long jiffy_elapsed)
 /* Trim the used slices and adjust slice start accordingly */
 static inline void throtl_trim_slice(struct throtl_grp *tg, bool rw)
 {
-	unsigned long time_elapsed, io_trim;
-	u64 bytes_trim;
+	unsigned long time_elapsed;
+	long long bytes_trim;
+	int io_trim;
 
 	BUG_ON(time_before(tg->slice_end[rw], tg->slice_start[rw]));
 
@@ -758,17 +759,21 @@ static inline void throtl_trim_slice(struct throtl_grp *tg, bool rw)
 		return;
 
 	bytes_trim = calculate_bytes_allowed(tg_bps_limit(tg, rw),
-					     time_elapsed);
-	io_trim = calculate_io_allowed(tg_iops_limit(tg, rw), time_elapsed);
-	if (!bytes_trim && !io_trim)
+					     time_elapsed) +
+		     tg->carryover_bytes[rw];
+	io_trim = calculate_io_allowed(tg_iops_limit(tg, rw), time_elapsed) +
+		  tg->carryover_ios[rw];
+	if (bytes_trim <= 0 && io_trim <= 0)
 		return;
 
-	if (tg->bytes_disp[rw] >= bytes_trim)
+	tg->carryover_bytes[rw] = 0;
+	if ((long long)tg->bytes_disp[rw] >= bytes_trim)
 		tg->bytes_disp[rw] -= bytes_trim;
 	else
 		tg->bytes_disp[rw] = 0;
 
-	if (tg->io_disp[rw] >= io_trim)
+	tg->carryover_ios[rw] = 0;
+	if ((int)tg->io_disp[rw] >= io_trim)
 		tg->io_disp[rw] -= io_trim;
 	else
 		tg->io_disp[rw] = 0;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH -next 3/4] blk-throttle: use calculate_io/bytes_allowed() for throtl_trim_slice()
  2023-08-15  1:41   ` [PATCH -next 3/4] blk-throttle: use calculate_io/bytes_allowed() for throtl_trim_slice() Yu Kuai
@ 2023-08-15 15:48     ` kernel test robot
  0 siblings, 0 replies; 6+ messages in thread
From: kernel test robot @ 2023-08-15 15:48 UTC (permalink / raw)
  To: tj, josef, axboe, yukuai3, mkoutny
  Cc: oe-kbuild-all, cgroups, linux-block, linux-kernel, yukuai1,
	yi.zhang, yangerkun

Hi Yu,

kernel test robot noticed the following build errors:

[auto build test ERROR on next-20230809]

url:    https://github.com/intel-lab-lkp/linux/commits/Yu-Kuai/blk-throttle-print-signed-value-carryover_bytes-ios-for-user/20230815-095025
base:   next-20230809
patch link:    https://lore.kernel.org/r/20230815014123.368929-4-yukuai1%40huaweicloud.com
patch subject: [PATCH -next 3/4] blk-throttle: use calculate_io/bytes_allowed() for throtl_trim_slice()
config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20230815/202308152351.JdDlpV4Q-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: (https://download.01.org/0day-ci/archive/20230815/202308152351.JdDlpV4Q-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202308152351.JdDlpV4Q-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from block/blk-throttle.c:12:
   block/blk-throttle.c: In function 'throtl_trim_slice':
>> block/blk-throttle.c:780:44: error: 'nr_slices' undeclared (first use in this function)
     780 |                    rw == READ ? 'R' : 'W', nr_slices, bytes_trim, io_trim,
         |                                            ^~~~~~~~~
   include/linux/blktrace_api.h:56:66: note: in definition of macro 'blk_add_cgroup_trace_msg'
      56 |                         __blk_trace_note_message(bt, css, fmt, ##__VA_ARGS__);\
         |                                                                  ^~~~~~~~~~~
   block/blk-throttle.c:778:9: note: in expansion of macro 'throtl_log'
     778 |         throtl_log(&tg->service_queue,
         |         ^~~~~~~~~~
   block/blk-throttle.c:780:44: note: each undeclared identifier is reported only once for each function it appears in
     780 |                    rw == READ ? 'R' : 'W', nr_slices, bytes_trim, io_trim,
         |                                            ^~~~~~~~~
   include/linux/blktrace_api.h:56:66: note: in definition of macro 'blk_add_cgroup_trace_msg'
      56 |                         __blk_trace_note_message(bt, css, fmt, ##__VA_ARGS__);\
         |                                                                  ^~~~~~~~~~~
   block/blk-throttle.c:778:9: note: in expansion of macro 'throtl_log'
     778 |         throtl_log(&tg->service_queue,
         |         ^~~~~~~~~~


vim +/nr_slices +780 block/blk-throttle.c

1a46ae7773b475 Yu Kuai     2023-08-15  728  
e43473b7f223ec Vivek Goyal 2010-09-15  729  /* Trim the used slices and adjust slice start accordingly */
0f3457f60edc57 Tejun Heo   2013-05-14  730  static inline void throtl_trim_slice(struct throtl_grp *tg, bool rw)
e43473b7f223ec Vivek Goyal 2010-09-15  731  {
1a46ae7773b475 Yu Kuai     2023-08-15  732  	unsigned long time_elapsed, io_trim;
1a46ae7773b475 Yu Kuai     2023-08-15  733  	u64 bytes_trim;
e43473b7f223ec Vivek Goyal 2010-09-15  734  
e43473b7f223ec Vivek Goyal 2010-09-15  735  	BUG_ON(time_before(tg->slice_end[rw], tg->slice_start[rw]));
e43473b7f223ec Vivek Goyal 2010-09-15  736  
e43473b7f223ec Vivek Goyal 2010-09-15  737  	/*
e43473b7f223ec Vivek Goyal 2010-09-15  738  	 * If bps are unlimited (-1), then time slice don't get
e43473b7f223ec Vivek Goyal 2010-09-15  739  	 * renewed. Don't try to trim the slice if slice is used. A new
e43473b7f223ec Vivek Goyal 2010-09-15  740  	 * slice will start when appropriate.
e43473b7f223ec Vivek Goyal 2010-09-15  741  	 */
0f3457f60edc57 Tejun Heo   2013-05-14  742  	if (throtl_slice_used(tg, rw))
e43473b7f223ec Vivek Goyal 2010-09-15  743  		return;
e43473b7f223ec Vivek Goyal 2010-09-15  744  
d1ae8ffdfaa16b Vivek Goyal 2010-12-01  745  	/*
d1ae8ffdfaa16b Vivek Goyal 2010-12-01  746  	 * A bio has been dispatched. Also adjust slice_end. It might happen
d1ae8ffdfaa16b Vivek Goyal 2010-12-01  747  	 * that initially cgroup limit was very low resulting in high
b53b072c4bb579 Baolin Wang 2020-09-07  748  	 * slice_end, but later limit was bumped up and bio was dispatched
d1ae8ffdfaa16b Vivek Goyal 2010-12-01  749  	 * sooner, then we need to reduce slice_end. A high bogus slice_end
d1ae8ffdfaa16b Vivek Goyal 2010-12-01  750  	 * is bad because it does not allow new slice to start.
d1ae8ffdfaa16b Vivek Goyal 2010-12-01  751  	 */
d1ae8ffdfaa16b Vivek Goyal 2010-12-01  752  
297e3d85478482 Shaohua Li  2017-03-27  753  	throtl_set_slice_end(tg, rw, jiffies + tg->td->throtl_slice);
d1ae8ffdfaa16b Vivek Goyal 2010-12-01  754  
1a46ae7773b475 Yu Kuai     2023-08-15  755  	time_elapsed = rounddown(jiffies - tg->slice_start[rw],
1a46ae7773b475 Yu Kuai     2023-08-15  756  				 tg->td->throtl_slice);
1a46ae7773b475 Yu Kuai     2023-08-15  757  	if (!time_elapsed)
e43473b7f223ec Vivek Goyal 2010-09-15  758  		return;
e43473b7f223ec Vivek Goyal 2010-09-15  759  
1a46ae7773b475 Yu Kuai     2023-08-15  760  	bytes_trim = calculate_bytes_allowed(tg_bps_limit(tg, rw),
1a46ae7773b475 Yu Kuai     2023-08-15  761  					     time_elapsed);
1a46ae7773b475 Yu Kuai     2023-08-15  762  	io_trim = calculate_io_allowed(tg_iops_limit(tg, rw), time_elapsed);
8e89d13f4ede24 Vivek Goyal 2010-09-15  763  	if (!bytes_trim && !io_trim)
e43473b7f223ec Vivek Goyal 2010-09-15  764  		return;
e43473b7f223ec Vivek Goyal 2010-09-15  765  
e43473b7f223ec Vivek Goyal 2010-09-15  766  	if (tg->bytes_disp[rw] >= bytes_trim)
e43473b7f223ec Vivek Goyal 2010-09-15  767  		tg->bytes_disp[rw] -= bytes_trim;
e43473b7f223ec Vivek Goyal 2010-09-15  768  	else
e43473b7f223ec Vivek Goyal 2010-09-15  769  		tg->bytes_disp[rw] = 0;
e43473b7f223ec Vivek Goyal 2010-09-15  770  
8e89d13f4ede24 Vivek Goyal 2010-09-15  771  	if (tg->io_disp[rw] >= io_trim)
8e89d13f4ede24 Vivek Goyal 2010-09-15  772  		tg->io_disp[rw] -= io_trim;
8e89d13f4ede24 Vivek Goyal 2010-09-15  773  	else
8e89d13f4ede24 Vivek Goyal 2010-09-15  774  		tg->io_disp[rw] = 0;
8e89d13f4ede24 Vivek Goyal 2010-09-15  775  
1a46ae7773b475 Yu Kuai     2023-08-15  776  	tg->slice_start[rw] += time_elapsed;
e43473b7f223ec Vivek Goyal 2010-09-15  777  
fda6f272c77a7a Tejun Heo   2013-05-14  778  	throtl_log(&tg->service_queue,
fda6f272c77a7a Tejun Heo   2013-05-14  779  		   "[%c] trim slice nr=%lu bytes=%llu io=%lu start=%lu end=%lu jiffies=%lu",
8e89d13f4ede24 Vivek Goyal 2010-09-15 @780  		   rw == READ ? 'R' : 'W', nr_slices, bytes_trim, io_trim,
e43473b7f223ec Vivek Goyal 2010-09-15  781  		   tg->slice_start[rw], tg->slice_end[rw], jiffies);
e43473b7f223ec Vivek Goyal 2010-09-15  782  }
e43473b7f223ec Vivek Goyal 2010-09-15  783  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-08-15 15:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-15  1:41 [PATCH -next 0/4] cleanup and fixes for 'carryover_ios/bytes' Yu Kuai
2023-08-15  1:41 ` [PATCH -next 1/4] blk-throttle: print signed value 'carryover_bytes/ios' for user Yu Kuai
     [not found] ` <20230815014123.368929-1-yukuai1-XF6JlduFytWkHkcT6e4Xnw@public.gmane.org>
2023-08-15  1:41   ` [PATCH -next 2/4] blk-throttle: fix wrong comparation while 'carryover_ios/bytes' is negative Yu Kuai
2023-08-15  1:41   ` [PATCH -next 3/4] blk-throttle: use calculate_io/bytes_allowed() for throtl_trim_slice() Yu Kuai
2023-08-15 15:48     ` kernel test robot
2023-08-15  1:41 ` [PATCH -next 4/4] blk-throttle: consider 'carryover_ios/bytes' in throtl_trim_slice() Yu Kuai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).