From: Bart Van Assche <bvanassche@acm.org>
To: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Cc: Damien Le Moal <dlemoal@kernel.org>,
linux-block@vger.kernel.org, Bart Van Assche <bvanassche@acm.org>
Subject: [PATCH blktests v2] throtl/008: Add a test for the iocost cgroup controller
Date: Thu, 4 Jun 2026 10:54:23 -0700 [thread overview]
Message-ID: <20260604175423.3809638-1-bvanassche@acm.org> (raw)
Add a test for read and write IOPS throttling.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
Changes compared to v1:
- Changed ". tests/block/rc" into ". tests/throtl/rc".
- Split test() into run_test() and test() to eliminate duplicate error handling
code.
- Made the test whether the iocost controller is supported more robust.
- Made the test easier to debug.
tests/throtl/008 | 104 +++++++++++++++++++++++++++++++++++++++++++
tests/throtl/008.out | 2 +
2 files changed, 106 insertions(+)
create mode 100755 tests/throtl/008
create mode 100644 tests/throtl/008.out
diff --git a/tests/throtl/008 b/tests/throtl/008
new file mode 100755
index 000000000000..f4d3b080797a
--- /dev/null
+++ b/tests/throtl/008
@@ -0,0 +1,104 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2026 Google LLC
+#
+# Test cgroup iocost IOPS limiting.
+
+. tests/throtl/rc
+. common/fio
+
+DESCRIPTION="test cgroup iocost controller limits"
+
+requires() {
+ _have_fio
+ _have_program bc
+ _have_kernel_option BLK_CGROUP_IOCOST
+}
+
+run_test() {
+ # dev_t is global to make it available in the caller.
+ dev_t=$(<"/sys/block/${THROTL_DEV}/dev")
+ if [[ -z "$dev_t" ]]; then
+ echo "Failed to get major:minor for ${THROTL_DEV}"
+ return 1
+ fi
+
+ # Configure iocost controller globally for the device
+ # min=100.00 max=100.00 forces vrate to be fixed at 100%
+ if ! echo "$dev_t enable=1 min=100.00 max=100.00" > "$(_cgroup2_base_dir)/io.cost.qos"; then
+ echo "Failed to configure io.cost.qos"
+ return 1
+ fi
+
+ # Limit read iops to 100 and write iops to 10.
+ # Setting rbps/wbps to 0 means they are ignored (costs calculated purely based on IOPS)
+ if ! echo "$dev_t ctrl=user model=linear rbps=0 rseqiops=100 rrandiops=100 wbps=0 wseqiops=10 wrandiops=10" > "$(_cgroup2_base_dir)/io.cost.model"; then
+ echo "Failed to configure io.cost.model"
+ return 1
+ fi
+
+ # 1. Run FIO read test
+ local -a FIO_PERF_FIELDS
+ FIO_PERF_FIELDS=("read iops")
+ if ! _fio_perf --bs=4k --rw=randread --name=read-test --filename="/dev/${THROTL_DEV}" \
+ --ioengine=libaio --direct=1 --iodepth=64 --time_based --runtime=10 \
+ --cgroup="blktests/${THROTL_DIR}" &> "${FULL}"; then
+ echo "FIO read test failed"
+ return 1
+ fi
+ cat "$TMPDIR/fio_perf" >> "$FULL"
+ local read_iops=${TEST_RUN["read iops"]}
+ if [[ -z "$read_iops" ]]; then
+ echo "Read IOPS is empty"
+ return 1
+ elif (( "$(echo "$read_iops < 90 || $read_iops > 110" | bc -l)" )); then
+ echo "Read IOPS $read_iops not in expected range [90, 110]"
+ return 1
+ fi
+
+ # 2. Run FIO write test
+ FIO_PERF_FIELDS=("write iops")
+ if ! _fio_perf --bs=4k --rw=randwrite --name=write-test --filename="/dev/${THROTL_DEV}" \
+ --ioengine=libaio --direct=1 --iodepth=64 --time_based --runtime=10 \
+ --cgroup="blktests/${THROTL_DIR}" &> "${FULL}"; then
+ echo "FIO write test failed"
+ return 1
+ fi
+ cat "$TMPDIR/fio_perf" >> "$FULL"
+ local write_iops=${TEST_RUN["write iops"]}
+ if [[ -z "$write_iops" ]]; then
+ echo "Write IOPS is empty"
+ return 1
+ elif (( "$(echo "$write_iops < 8 || $write_iops > 12" | bc -l)" )); then
+ echo "Write IOPS $write_iops not in expected range [8, 12]"
+ return 1
+ fi
+}
+
+test() {
+ local test_status
+
+ echo "Running ${TEST_NAME}"
+
+ if ! _set_up_throtl; then
+ echo "_set_up_throtl failed"
+ return 1
+ fi
+
+ run_test
+ test_status=$?
+
+ if [ -n "$dev_t" ]; then
+ echo "$dev_t enable=0" > "$(_cgroup2_base_dir)/io.cost.qos"
+ echo "$dev_t ctrl=auto" > "$(_cgroup2_base_dir)/io.cost.model"
+ fi
+
+ _clean_up_throtl
+
+ if [ "$test_status" -eq 0 ]; then
+ echo "Test complete"
+ else
+ echo "Test failed"
+ return 1
+ fi
+}
diff --git a/tests/throtl/008.out b/tests/throtl/008.out
new file mode 100644
index 000000000000..890ff7f226d1
--- /dev/null
+++ b/tests/throtl/008.out
@@ -0,0 +1,2 @@
+Running throtl/008
+Test complete
next reply other threads:[~2026-06-04 17:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-04 17:54 Bart Van Assche [this message]
2026-06-14 6:30 ` [PATCH blktests v2] throtl/008: Add a test for the iocost cgroup controller Shin'ichiro Kawasaki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260604175423.3809638-1-bvanassche@acm.org \
--to=bvanassche@acm.org \
--cc=dlemoal@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=shinichiro.kawasaki@wdc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox