From: Nilay Shroff <nilay@linux.ibm.com>
To: linux-block@vger.kernel.org
Cc: yukuai3@huawei.com, shinichiro.kawasaki@wdc.com,
yi.zhang@redhat.com, bvanassche@acm.org, gjoyce@ibm.com
Subject: [PATCHv2 blktests 2/2] throtl: fix the race between submitting IO and setting cgroup.procs
Date: Wed, 18 Dec 2024 19:13:22 +0530 [thread overview]
Message-ID: <20241218134326.2164105-3-nilay@linux.ibm.com> (raw)
In-Reply-To: <20241218134326.2164105-1-nilay@linux.ibm.com>
The throttle test cases uses _throtl_issue_io function to submit IO
to the device. This function typically runs in the background process
however before this function starts execution and submit IO, we need
to set the PID of the background process into cgroup.procs. The current
implementation adds sleep 0.1 before _throtl_issue_io and it's assumed
that during this sleep time of 0.1 second, we shall be able to write the
PID of the background process to cgroup.procs. However this may not be
always true as background process might starts running after sleep of 0.1
seconds (and hence start submitting IO) before we could actually write
the PID of background process into cgroup.procs from the parent shell.
This commit helps fix the above race condition by writing pid of the
background/child process using $BASHPID into cgroup.procs. The $BASHPID
returns the pid of the current bash process. So we leverage $BASHPID to
first write the pid of the background/child job/process into cgroup.procs
from within the child sub-shell and then start submitting IO. This way we
eliminate the need of any communication between parent shell and the
background/child shell process and that helps avoid the race.
Signed-off-by: Nilay Shroff <nilay@linux.ibm.com>
---
tests/throtl/004 | 7 ++-----
tests/throtl/005 | 7 ++-----
tests/throtl/rc | 7 ++-----
3 files changed, 6 insertions(+), 15 deletions(-)
diff --git a/tests/throtl/004 b/tests/throtl/004
index 6e28612..d1461b9 100755
--- a/tests/throtl/004
+++ b/tests/throtl/004
@@ -21,16 +21,13 @@ test() {
_throtl_set_limits wbps=$((1024 * 1024))
{
- sleep 0.1
+ echo "$BASHPID" > "$CGROUP2_DIR/$THROTL_DIR/cgroup.procs"
_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"
+ wait $!
_clean_up_throtl
echo "Test complete"
diff --git a/tests/throtl/005 b/tests/throtl/005
index 0778258..86e52b3 100755
--- a/tests/throtl/005
+++ b/tests/throtl/005
@@ -20,16 +20,13 @@ test() {
_throtl_set_limits wbps=$((512 * 1024))
{
- sleep 0.1
+ echo "$BASHPID" > "$CGROUP2_DIR/$THROTL_DIR/cgroup.procs"
_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
+ wait $!
_throtl_remove_limits
_clean_up_throtl
diff --git a/tests/throtl/rc b/tests/throtl/rc
index 330e6b9..df54cb9 100644
--- a/tests/throtl/rc
+++ b/tests/throtl/rc
@@ -97,18 +97,15 @@ _throtl_issue_io() {
# IO and then print time elapsed to the second, blk-throttle limits should be
# set before this function.
_throtl_test_io() {
- local pid
{
local rw=$1
local bs=$2
local count=$3
- sleep 0.1
+ echo "$BASHPID" > "$CGROUP2_DIR/$THROTL_DIR/cgroup.procs"
_throtl_issue_io "$rw" "$bs" "$count"
} &
- pid=$!
- echo "$pid" > "$CGROUP2_DIR/$THROTL_DIR/cgroup.procs"
- wait $pid
+ wait $!
}
--
2.45.2
next prev parent reply other threads:[~2024-12-18 13:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-18 13:43 [PATCHv2 blktests 0/2] throtl: fix IO block-size and race while submitting IO Nilay Shroff
2024-12-18 13:43 ` [PATCHv2 blktests 1/2] throtl/002: calculate block-size based on device max-sectors setting Nilay Shroff
2024-12-26 7:30 ` Yi Zhang
2024-12-18 13:43 ` Nilay Shroff [this message]
2024-12-25 2:55 ` [PATCHv2 blktests 2/2] throtl: fix the race between submitting IO and setting cgroup.procs Yu Kuai
2024-12-24 8:26 ` [PATCHv2 blktests 0/2] throtl: fix IO block-size and race while submitting IO Shinichiro Kawasaki
2025-01-16 11:22 ` Nilay Shroff
2025-01-17 0:35 ` Shinichiro 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=20241218134326.2164105-3-nilay@linux.ibm.com \
--to=nilay@linux.ibm.com \
--cc=bvanassche@acm.org \
--cc=gjoyce@ibm.com \
--cc=linux-block@vger.kernel.org \
--cc=shinichiro.kawasaki@wdc.com \
--cc=yi.zhang@redhat.com \
--cc=yukuai3@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.