From: Xianting Tian <tian.xianting@h3c.com>
To: <clm@fb.com>, <josef@toxicpanda.com>, <dsterba@suse.com>
Cc: <linux-btrfs@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
Xianting Tian <tian.xianting@h3c.com>
Subject: [PATCH] btrfs: prevent hung check firing during long sync IO
Date: Wed, 19 Aug 2020 18:14:51 +0800 [thread overview]
Message-ID: <20200819101451.24266-1-tian.xianting@h3c.com> (raw)
For sync and flush io, it may take long time to complete.
So it's better to use wait_for_completion_io_timeout() in a
while loop to avoid prevent hung check and crash(when set
/proc/sys/kernel/hung_task_panic).
This is similar to prevent hung task check in submit_bio_wait(),
blk_execute_rq().
Signed-off-by: Xianting Tian <tian.xianting@h3c.com>
---
fs/btrfs/disk-io.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 9ae25f632..1eb560de0 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -17,6 +17,7 @@
#include <linux/error-injection.h>
#include <linux/crc32c.h>
#include <linux/sched/mm.h>
+#include <linux/sched/sysctl.h>
#include <asm/unaligned.h>
#include <crypto/hash.h>
#include "ctree.h"
@@ -3699,12 +3700,21 @@ static void write_dev_flush(struct btrfs_device *device)
static blk_status_t wait_dev_flush(struct btrfs_device *device)
{
struct bio *bio = device->flush_bio;
+ unsigned long hang_check;
if (!test_bit(BTRFS_DEV_STATE_FLUSH_SENT, &device->dev_state))
return BLK_STS_OK;
clear_bit(BTRFS_DEV_STATE_FLUSH_SENT, &device->dev_state);
- wait_for_completion_io(&device->flush_wait);
+
+ /* Prevent hang_check timer from firing at us during very long I/O */
+ hang_check = sysctl_hung_task_timeout_secs;
+ if (hang_check)
+ while (!wait_for_completion_io_timeout(&device->flush_wait,
+ hang_check * (HZ/2)))
+ ;
+ else
+ wait_for_completion_io(&device->flush_wait);
return bio->bi_status;
}
--
2.17.1
next reply other threads:[~2020-08-19 11:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-19 10:14 Xianting Tian [this message]
2020-08-19 13:28 ` [PATCH] btrfs: prevent hung check firing during long sync IO David Sterba
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=20200819101451.24266-1-tian.xianting@h3c.com \
--to=tian.xianting@h3c.com \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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