Linux block layer
 help / color / mirror / Atom feed
* [PATCH blktests v2] throtl/008: Add a test for the iocost cgroup controller
@ 2026-06-04 17:54 Bart Van Assche
  2026-06-14  6:30 ` Shin'ichiro Kawasaki
  0 siblings, 1 reply; 2+ messages in thread
From: Bart Van Assche @ 2026-06-04 17:54 UTC (permalink / raw)
  To: Shin'ichiro Kawasaki; +Cc: Damien Le Moal, linux-block, Bart Van Assche

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

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

end of thread, other threads:[~2026-06-14  6:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-04 17:54 [PATCH blktests v2] throtl/008: Add a test for the iocost cgroup controller Bart Van Assche
2026-06-14  6:30 ` Shin'ichiro Kawasaki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox