Linux-Block Archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 blktests 0/5] add new tests for blk-throttle
@ 2024-04-20  8:45 Yu Kuai
  2024-04-20  8:45 ` [PATCH v3 blktests 1/5] tests/throtl: add first test " Yu Kuai
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Yu Kuai @ 2024-04-20  8:45 UTC (permalink / raw
  To: saranyamohan, tj, axboe; +Cc: linux-block, yukuai3, yukuai1, yangerkun

From: Yu Kuai <yukuai3@huawei.com>

changes in v3:
 - lots of style changes suggested by Shinichiro

changes in v2:
 - move lots of functions to rc

Yu Kuai (5):
  tests/throtl: add first test for blk-throttle
  tests/throtl: add a new test 002
  tests/throtl: add a new test 003
  tests/throtl: add a new test 004
  tests/throtl: add a new test 005

 tests/throtl/001     | 39 ++++++++++++++++++
 tests/throtl/001.out |  6 +++
 tests/throtl/002     | 30 ++++++++++++++
 tests/throtl/002.out |  4 ++
 tests/throtl/003     | 32 +++++++++++++++
 tests/throtl/003.out |  4 ++
 tests/throtl/004     | 37 +++++++++++++++++
 tests/throtl/004.out |  4 ++
 tests/throtl/005     | 37 +++++++++++++++++
 tests/throtl/005.out |  3 ++
 tests/throtl/rc      | 96 ++++++++++++++++++++++++++++++++++++++++++++
 11 files changed, 292 insertions(+)
 create mode 100755 tests/throtl/001
 create mode 100644 tests/throtl/001.out
 create mode 100755 tests/throtl/002
 create mode 100644 tests/throtl/002.out
 create mode 100755 tests/throtl/003
 create mode 100644 tests/throtl/003.out
 create mode 100755 tests/throtl/004
 create mode 100644 tests/throtl/004.out
 create mode 100755 tests/throtl/005
 create mode 100644 tests/throtl/005.out
 create mode 100644 tests/throtl/rc

-- 
2.39.2


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

* [PATCH v3 blktests 1/5] tests/throtl: add first test for blk-throttle
  2024-04-20  8:45 [PATCH v3 blktests 0/5] add new tests for blk-throttle Yu Kuai
@ 2024-04-20  8:45 ` Yu Kuai
  2024-04-20  8:45 ` [PATCH v3 blktests 2/5] tests/throtl: add a new test 002 Yu Kuai
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Yu Kuai @ 2024-04-20  8:45 UTC (permalink / raw
  To: saranyamohan, tj, axboe; +Cc: linux-block, yukuai3, yukuai1, yangerkun

From: Yu Kuai <yukuai3@huawei.com>

Test basic functionality.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 tests/throtl/001     | 39 ++++++++++++++++++++
 tests/throtl/001.out |  6 +++
 tests/throtl/rc      | 88 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 133 insertions(+)
 create mode 100755 tests/throtl/001
 create mode 100644 tests/throtl/001.out
 create mode 100644 tests/throtl/rc

diff --git a/tests/throtl/001 b/tests/throtl/001
new file mode 100755
index 0000000..835cac2
--- /dev/null
+++ b/tests/throtl/001
@@ -0,0 +1,39 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2024 Yu Kuai
+#
+# Test basic functionality of blk-throttle
+
+. tests/throtl/rc
+
+DESCRIPTION="basic functionality"
+QUICK=1
+
+test() {
+	echo "Running ${TEST_NAME}"
+
+	if ! _set_up_throtl; then
+		return 1;
+	fi
+
+	local bps_limit=$((1024 * 1024))
+
+	_throtl_set_limits wbps=$bps_limit
+	_throtl_test_io write 4k 256
+	_throtl_remove_limits
+
+	_throtl_set_limits wiops=256
+	_throtl_test_io write 4k 256
+	_throtl_remove_limits
+
+	_throtl_set_limits rbps=$bps_limit
+	_throtl_test_io read 4k 256
+	_throtl_remove_limits
+
+	_throtl_set_limits riops=256
+	_throtl_test_io read 4k 256
+	_throtl_remove_limits
+
+	_clean_up_throtl
+	echo "Test complete"
+}
diff --git a/tests/throtl/001.out b/tests/throtl/001.out
new file mode 100644
index 0000000..a3edfdd
--- /dev/null
+++ b/tests/throtl/001.out
@@ -0,0 +1,6 @@
+Running throtl/001
+1
+1
+1
+1
+Test complete
diff --git a/tests/throtl/rc b/tests/throtl/rc
new file mode 100644
index 0000000..2ddbac8
--- /dev/null
+++ b/tests/throtl/rc
@@ -0,0 +1,88 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2024 Yu Kuai
+#
+# Tests for blk-throttle
+
+. common/rc
+. common/null_blk
+. common/cgroup
+
+THROTL_DIR=$(echo "$TEST_NAME" | tr '/' '_')
+THROTL_DEV=dev_nullb
+
+group_requires() {
+	_have_root
+	_have_null_blk
+	_have_kernel_option BLK_DEV_THROTTLING
+	_have_cgroup2_controller io
+	_have_program bc
+}
+
+# Create a new null_blk device, and create a new blk-cgroup for test.
+_set_up_throtl() {
+
+	if ! _configure_null_blk $THROTL_DEV "$@" power=1; then
+		return 1
+	fi
+
+	if ! _init_cgroup2; then
+		_exit_null_blk
+		return 1
+	fi
+
+	echo "+io" > "$(_cgroup2_base_dir)/cgroup.subtree_control"
+	echo "+io" > "$CGROUP2_DIR/cgroup.subtree_control"
+
+	mkdir -p "$CGROUP2_DIR/$THROTL_DIR"
+	return 0;
+}
+
+_clean_up_throtl() {
+	rmdir "$CGROUP2_DIR/$THROTL_DIR"
+	echo "-io" > "$CGROUP2_DIR/cgroup.subtree_control"
+	echo "-io" > "$(_cgroup2_base_dir)/cgroup.subtree_control"
+
+	_exit_cgroup2
+	_exit_null_blk
+}
+
+_throtl_set_limits() {
+	echo "$(cat /sys/block/$THROTL_DEV/dev) $*" > \
+		"$CGROUP2_DIR/$THROTL_DIR/io.max"
+}
+
+_throtl_remove_limits() {
+	echo "$(cat /sys/block/$THROTL_DEV/dev) rbps=max wbps=max riops=max wiops=max" > \
+		"$CGROUP2_DIR/$THROTL_DIR/io.max"
+}
+
+# Create an asynchronous thread and bind it to the specified blk-cgroup, issue
+# IO and then print time elapsed to the second, blk-throttle limits should be
+# set before this function.
+_throtl_test_io() {
+	local pid
+
+	{
+		local start_time
+		local end_time
+		local elapsed
+
+		sleep 0.1
+		start_time=$(date +%s.%N)
+
+		if [ "$1" == "read" ]; then
+			dd if=/dev/$THROTL_DEV of=/dev/null bs="$2" count="$3" iflag=direct status=none
+		elif [ "$1" == "write" ]; then
+			dd of=/dev/$THROTL_DEV if=/dev/zero bs="$2" count="$3" oflag=direct status=none
+		fi
+
+		end_time=$(date +%s.%N)
+		elapsed=$(echo "$end_time - $start_time" | bc)
+		printf "%.0f\n" "$elapsed"
+	} &
+
+	pid=$!
+	echo "$pid" > "$CGROUP2_DIR/$THROTL_DIR/cgroup.procs"
+	wait $pid
+}
-- 
2.39.2


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

* [PATCH v3 blktests 2/5] tests/throtl: add a new test 002
  2024-04-20  8:45 [PATCH v3 blktests 0/5] add new tests for blk-throttle Yu Kuai
  2024-04-20  8:45 ` [PATCH v3 blktests 1/5] tests/throtl: add first test " Yu Kuai
@ 2024-04-20  8:45 ` Yu Kuai
  2024-04-20  8:45 ` [PATCH v3 blktests 3/5] tests/throtl: add a new test 003 Yu Kuai
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Yu Kuai @ 2024-04-20  8:45 UTC (permalink / raw
  To: saranyamohan, tj, axboe; +Cc: linux-block, yukuai3, yukuai1, yangerkun

From: Yu Kuai <yukuai3@huawei.com>

Test iops limit over IO split, regression tests for:

commit 9f5ede3c01f9 ("block: throttle split bio in case of iops limit")

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 tests/throtl/002     | 30 ++++++++++++++++++++++++++++++
 tests/throtl/002.out |  4 ++++
 2 files changed, 34 insertions(+)
 create mode 100755 tests/throtl/002
 create mode 100644 tests/throtl/002.out

diff --git a/tests/throtl/002 b/tests/throtl/002
new file mode 100755
index 0000000..8bbe18b
--- /dev/null
+++ b/tests/throtl/002
@@ -0,0 +1,30 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2024 Yu Kuai
+#
+# Test iops limit work correctly for big IO of blk-throttle, regression test
+# for commit 9f5ede3c01f9 ("block: throttle split bio in case of iops limit")
+
+. tests/throtl/rc
+
+DESCRIPTION="iops limit over IO split"
+QUICK=1
+
+test() {
+	echo "Running ${TEST_NAME}"
+
+	if ! _set_up_throtl max_sectors=8; then
+		return 1;
+	fi
+
+	_throtl_set_limits wiops=256
+	_throtl_test_io write 1M 1
+	_throtl_remove_limits
+
+	_throtl_set_limits riops=256
+	_throtl_test_io read 1M 1
+	_throtl_remove_limits
+
+	_clean_up_throtl
+	echo "Test complete"
+}
diff --git a/tests/throtl/002.out b/tests/throtl/002.out
new file mode 100644
index 0000000..7e1ae85
--- /dev/null
+++ b/tests/throtl/002.out
@@ -0,0 +1,4 @@
+Running throtl/002
+1
+1
+Test complete
-- 
2.39.2


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

* [PATCH v3 blktests 3/5] tests/throtl: add a new test 003
  2024-04-20  8:45 [PATCH v3 blktests 0/5] add new tests for blk-throttle Yu Kuai
  2024-04-20  8:45 ` [PATCH v3 blktests 1/5] tests/throtl: add first test " Yu Kuai
  2024-04-20  8:45 ` [PATCH v3 blktests 2/5] tests/throtl: add a new test 002 Yu Kuai
@ 2024-04-20  8:45 ` Yu Kuai
  2024-04-20  8:45 ` [PATCH v3 blktests 4/5] tests/throtl: add a new test 004 Yu Kuai
  2024-04-20  8:45 ` [PATCH v3 blktests 5/5] tests/throtl: add a new test 005 Yu Kuai
  4 siblings, 0 replies; 6+ messages in thread
From: Yu Kuai @ 2024-04-20  8:45 UTC (permalink / raw
  To: saranyamohan, tj, axboe; +Cc: linux-block, yukuai3, yukuai1, yangerkun

From: Yu Kuai <yukuai3@huawei.com>

Test bps limit over IO split, regression tests for:

commit 111be8839817 ("block-throttle: avoid double charge")

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 tests/throtl/003     | 32 ++++++++++++++++++++++++++++++++
 tests/throtl/003.out |  4 ++++
 2 files changed, 36 insertions(+)
 create mode 100755 tests/throtl/003
 create mode 100644 tests/throtl/003.out

diff --git a/tests/throtl/003 b/tests/throtl/003
new file mode 100755
index 0000000..da4342e
--- /dev/null
+++ b/tests/throtl/003
@@ -0,0 +1,32 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2024 Yu Kuai
+#
+# Test bps limit work correctly for big IO of blk-throttle, regression test for
+# commit 111be8839817 ("block-throttle: avoid double charge")
+
+. tests/throtl/rc
+
+DESCRIPTION="bps limit over IO split"
+QUICK=1
+
+test() {
+	echo "Running ${TEST_NAME}"
+
+	if ! _set_up_throtl max_sectors=8; then
+		return 1;
+	fi
+
+	local limit=$((1024 * 1024))
+
+	_throtl_set_limits wbps=$limit
+	_throtl_test_io write 1M 1
+	_throtl_remove_limits
+
+	_throtl_set_limits rbps=$limit
+	_throtl_test_io read 1M 1
+	_throtl_remove_limits
+
+	_clean_up_throtl
+	echo "Test complete"
+}
diff --git a/tests/throtl/003.out b/tests/throtl/003.out
new file mode 100644
index 0000000..07a80b3
--- /dev/null
+++ b/tests/throtl/003.out
@@ -0,0 +1,4 @@
+Running throtl/003
+1
+1
+Test complete
-- 
2.39.2


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

* [PATCH v3 blktests 4/5] tests/throtl: add a new test 004
  2024-04-20  8:45 [PATCH v3 blktests 0/5] add new tests for blk-throttle Yu Kuai
                   ` (2 preceding siblings ...)
  2024-04-20  8:45 ` [PATCH v3 blktests 3/5] tests/throtl: add a new test 003 Yu Kuai
@ 2024-04-20  8:45 ` Yu Kuai
  2024-04-20  8:45 ` [PATCH v3 blktests 5/5] tests/throtl: add a new test 005 Yu Kuai
  4 siblings, 0 replies; 6+ messages in thread
From: Yu Kuai @ 2024-04-20  8:45 UTC (permalink / raw
  To: saranyamohan, tj, axboe; +Cc: linux-block, yukuai3, yukuai1, yangerkun

From: Yu Kuai <yukuai3@huawei.com>

Test delete the disk while IO is throttled, regression test for:

commit 884f0e84f1e3 ("blk-throttle: fix UAF by deleteing timer in blk_throtl_exit()")
commit 8f9e7b65f833 ("block: cancel all throttled bios in del_gendisk()")

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 tests/throtl/004     | 37 +++++++++++++++++++++++++++++++++++++
 tests/throtl/004.out |  4 ++++
 tests/throtl/rc      | 36 ++++++++++++++++++++++--------------
 3 files changed, 63 insertions(+), 14 deletions(-)
 create mode 100755 tests/throtl/004
 create mode 100644 tests/throtl/004.out

diff --git a/tests/throtl/004 b/tests/throtl/004
new file mode 100755
index 0000000..6e28612
--- /dev/null
+++ b/tests/throtl/004
@@ -0,0 +1,37 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2024 Yu Kuai
+#
+# Test delete the disk while IO is throttled, regerssion test for
+# commit 884f0e84f1e3 ("blk-throttle: fix UAF by deleteing timer in blk_throtl_exit()")
+# commit 8f9e7b65f833 ("block: cancel all throttled bios in del_gendisk()")
+
+. tests/throtl/rc
+
+DESCRIPTION="delete disk while IO is throttled"
+QUICK=1
+
+test() {
+	echo "Running ${TEST_NAME}"
+
+	if ! _set_up_throtl; then
+		return 1;
+	fi
+
+	_throtl_set_limits wbps=$((1024 * 1024))
+
+	{
+		sleep 0.1
+		_throtl_issue_io write 10M 1
+	} &
+
+	local pid=$!
+	echo "$pid" > "$CGROUP2_DIR/$THROTL_DIR/cgroup.procs"
+
+	sleep 0.6
+	echo 0 > "/sys/kernel/config/nullb/$THROTL_DEV/power"
+	wait "$pid"
+
+	_clean_up_throtl
+	echo "Test complete"
+}
diff --git a/tests/throtl/004.out b/tests/throtl/004.out
new file mode 100644
index 0000000..e76ec3a
--- /dev/null
+++ b/tests/throtl/004.out
@@ -0,0 +1,4 @@
+Running throtl/004
+dd: error writing '/dev/dev_nullb': Input/output error
+1
+Test complete
diff --git a/tests/throtl/rc b/tests/throtl/rc
index 2ddbac8..2e26fd2 100644
--- a/tests/throtl/rc
+++ b/tests/throtl/rc
@@ -57,6 +57,24 @@ _throtl_remove_limits() {
 		"$CGROUP2_DIR/$THROTL_DIR/io.max"
 }
 
+_throtl_issue_io() {
+	local start_time
+	local end_time
+	local elapsed
+
+	start_time=$(date +%s.%N)
+
+	if [ "$1" == "read" ]; then
+		dd if=/dev/$THROTL_DEV of=/dev/null bs="$2" count="$3" iflag=direct status=none
+	elif [ "$1" == "write" ]; then
+		dd of=/dev/$THROTL_DEV if=/dev/zero bs="$2" count="$3" oflag=direct status=none
+	fi
+
+	end_time=$(date +%s.%N)
+	elapsed=$(echo "$end_time - $start_time" | bc)
+	printf "%.0f\n" "$elapsed"
+}
+
 # Create an asynchronous thread and bind it to the specified blk-cgroup, issue
 # IO and then print time elapsed to the second, blk-throttle limits should be
 # set before this function.
@@ -64,22 +82,12 @@ _throtl_test_io() {
 	local pid
 
 	{
-		local start_time
-		local end_time
-		local elapsed
+		local rw=$1
+		local bs=$2
+		local count=$3
 
 		sleep 0.1
-		start_time=$(date +%s.%N)
-
-		if [ "$1" == "read" ]; then
-			dd if=/dev/$THROTL_DEV of=/dev/null bs="$2" count="$3" iflag=direct status=none
-		elif [ "$1" == "write" ]; then
-			dd of=/dev/$THROTL_DEV if=/dev/zero bs="$2" count="$3" oflag=direct status=none
-		fi
-
-		end_time=$(date +%s.%N)
-		elapsed=$(echo "$end_time - $start_time" | bc)
-		printf "%.0f\n" "$elapsed"
+		_throtl_issue_io "$rw" "$bs" "$count"
 	} &
 
 	pid=$!
-- 
2.39.2


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

* [PATCH v3 blktests 5/5] tests/throtl: add a new test 005
  2024-04-20  8:45 [PATCH v3 blktests 0/5] add new tests for blk-throttle Yu Kuai
                   ` (3 preceding siblings ...)
  2024-04-20  8:45 ` [PATCH v3 blktests 4/5] tests/throtl: add a new test 004 Yu Kuai
@ 2024-04-20  8:45 ` Yu Kuai
  4 siblings, 0 replies; 6+ messages in thread
From: Yu Kuai @ 2024-04-20  8:45 UTC (permalink / raw
  To: saranyamohan, tj, axboe; +Cc: linux-block, yukuai3, yukuai1, yangerkun

From: Yu Kuai <yukuai3@huawei.com>

Test change config while IO is throttled, regression test for:

commit a880ae93e5b5 ("blk-throttle: fix io hung due to configuration updates")

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 tests/throtl/005     | 37 +++++++++++++++++++++++++++++++++++++
 tests/throtl/005.out |  3 +++
 2 files changed, 40 insertions(+)
 create mode 100755 tests/throtl/005
 create mode 100644 tests/throtl/005.out

diff --git a/tests/throtl/005 b/tests/throtl/005
new file mode 100755
index 0000000..0778258
--- /dev/null
+++ b/tests/throtl/005
@@ -0,0 +1,37 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2024 Yu Kuai
+#
+# Test change config while IO is throttled, regression test for
+# commit a880ae93e5b5 ("blk-throttle: fix io hung due to configuration updates")
+
+. tests/throtl/rc
+
+DESCRIPTION="change config with throttled IO"
+QUICK=1
+
+test() {
+	echo "Running ${TEST_NAME}"
+
+	if ! _set_up_throtl; then
+		return 1;
+	fi
+
+	_throtl_set_limits wbps=$((512 * 1024))
+
+	{
+		sleep 0.1
+		_throtl_issue_io write 1M 1
+	} &
+
+	local pid=$!
+	echo "$pid" > "$CGROUP2_DIR/$THROTL_DIR/cgroup.procs"
+
+	sleep 1
+	_throtl_set_limits wbps=$((256 * 1024))
+	wait $pid
+	_throtl_remove_limits
+
+	_clean_up_throtl
+	echo "Test complete"
+}
diff --git a/tests/throtl/005.out b/tests/throtl/005.out
new file mode 100644
index 0000000..1d23210
--- /dev/null
+++ b/tests/throtl/005.out
@@ -0,0 +1,3 @@
+Running throtl/005
+3
+Test complete
-- 
2.39.2


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

end of thread, other threads:[~2024-04-20  8:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-20  8:45 [PATCH v3 blktests 0/5] add new tests for blk-throttle Yu Kuai
2024-04-20  8:45 ` [PATCH v3 blktests 1/5] tests/throtl: add first test " Yu Kuai
2024-04-20  8:45 ` [PATCH v3 blktests 2/5] tests/throtl: add a new test 002 Yu Kuai
2024-04-20  8:45 ` [PATCH v3 blktests 3/5] tests/throtl: add a new test 003 Yu Kuai
2024-04-20  8:45 ` [PATCH v3 blktests 4/5] tests/throtl: add a new test 004 Yu Kuai
2024-04-20  8:45 ` [PATCH v3 blktests 5/5] tests/throtl: add a new test 005 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 read-only IMAP folder(s) and NNTP newsgroup(s).