lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240513120848.2828797-3-yukuai1@huaweicloud.com>
Date: Mon, 13 May 2024 20:08:48 +0800
From: Yu Kuai <yukuai1@...weicloud.com>
To: tj@...nel.org,
	josef@...icpanda.com,
	axboe@...nel.dk
Cc: cgroups@...r.kernel.org,
	linux-block@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	yukuai3@...wei.com,
	yukuai1@...weicloud.com,
	yi.zhang@...wei.com,
	yangerkun@...wei.com
Subject: [PATCH -next 2/2] blk-throttle: fix lower control under super low iops limit

From: Yu Kuai <yukuai3@...wei.com>

User will configure allowed iops limit in 1s, and calculate_io_allowed()
will calculate allowed iops in the slice by:

limit * HZ / throtl_slice

However, if limit is quite low, the result can be 0, then
allowed IO in the slice is 0, this will cause missing dispatch and
control will be lower than limit.

For example, set iops_limit to 5 with HD disk, and test will found that
iops will be 3.

This is usually not a big deal, because user will unlikely to configure
such low iops limit, however, this is still a problem in the extreme
scene.

Fix the problem by using MAX_THROTL_SLICE in this case, so that
calculate_io_allowed() is guaranteed not to return 0, since we don't care
about more smoother control effect in this case.

Signed-off-by: Yu Kuai <yukuai3@...wei.com>
---
 block/blk-throttle.c | 18 ++++++++++++++++++
 block/blk-throttle.h |  6 ++++++
 2 files changed, 24 insertions(+)

diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index 69f1bb91ea78..69429288b50b 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -491,6 +491,8 @@ static bool throtl_schedule_next_dispatch(struct throtl_service_queue *sq,
 
 static unsigned int tg_throtl_slice(struct throtl_grp *tg, int rw)
 {
+	if (tg->throtl_slice[rw])
+		return tg->throtl_slice[rw];
 	return tg->td->throtl_slice;
 }
 
@@ -1169,6 +1171,21 @@ static int tg_print_conf_uint(struct seq_file *sf, void *v)
 	return 0;
 }
 
+static void tg_set_throtl_slice(struct throtl_grp *tg)
+{
+	int rw;
+
+	for (rw = READ; rw <= WRITE; rw++) {
+		u32 limit = tg_iops_limit(tg, rw);
+
+		if (limit == UINT_MAX ||
+		    calculate_io_allowed(limit, tg->td->throtl_slice) != 0)
+			tg->throtl_slice[rw] = tg->td->throtl_slice;
+		else
+			tg->throtl_slice[rw] = MAX_THROTL_SLICE;
+	}
+}
+
 static void tg_conf_updated(struct throtl_grp *tg, bool global)
 {
 	struct throtl_service_queue *sq = &tg->service_queue;
@@ -1200,6 +1217,7 @@ static void tg_conf_updated(struct throtl_grp *tg, bool global)
 	}
 	rcu_read_unlock();
 
+	tg_set_throtl_slice(tg);
 	/*
 	 * We're already holding queue_lock and know @tg is valid.  Let's
 	 * apply the new config directly.
diff --git a/block/blk-throttle.h b/block/blk-throttle.h
index 393c3d134b96..0424d2be90ff 100644
--- a/block/blk-throttle.h
+++ b/block/blk-throttle.h
@@ -126,6 +126,12 @@ struct throtl_grp {
 
 	unsigned long last_check_time;
 
+	/*
+	 * This is usually td->throtl_slice, however, if iops limit is quite
+	 * low that allowed io in that slice is 0, throtl_slice in this tg will
+	 * be set to MAX_THROTL_SLICE.
+	 */
+	unsigned int throtl_slice[2];
 	/* When did we start a new slice */
 	unsigned long slice_start[2];
 	unsigned long slice_end[2];
-- 
2.39.2


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ