Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp357530pxa; Wed, 19 Aug 2020 03:23:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwn5UHMaRKj1v3oGluBabzrdVaV4YYmvB/Y4FwFBlEky9+JtnL3oBVkXtTTaNPr2Kah8wIF X-Received: by 2002:a17:906:845:: with SMTP id f5mr3455853ejd.34.1597832608154; Wed, 19 Aug 2020 03:23:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597832608; cv=none; d=google.com; s=arc-20160816; b=yshB5iGvwJvyAsTW8cWFJEZj6K4r+HiL4uBTX8ytGRbAy4Cp228mi4qqcIsgoFIf4k Nc/XvEHZQ59Gdsf904djIINBHNrzqiSl/M6OPC8LKnEplmF2mBpCrA3y89u6L0sfGQrn fkMVeZtZ6FNjEFQ+WFqZCb1Y+4eAcpMFtNOiSto/rWzzobubUytNL5nsh117fgRoW/Wo 3U8sPxp4lFfIhKGdBAZuQx6ClMm5kpPhgTSB/n42QYRV/bD7YXB1VBdivdH7vyTnHZWq vYlNu4AdIojbf8nAhf06nqToxwngh/id7GAR1v73turYd6RVFsiMuUNErJ992mIu0vGF AH0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=ednKISw7bnGFMRj+GfS7T5JWzCixCh8wjChwAN2HagI=; b=hssoz0j0e4d0Y/cWpol6ReTY17lkJjS/7JmLvQTS1JzHEeV+60mqHocmgBHIPqbzUC P2TTNEXSyuQ6gOnVcmcAHfbUbSFR6O5aTGEn4EUezH61HACn6GCdf4ISLoiZ9lMnje8v x28FLjvjSx+8n0zlfXmFH21Quiz0XfuCSDsNZEutCPg/r10A5gLAkBWVwBrcQOQK4cFl xNRZ0UJYu/vA3avbHf8byUil1810zgvDA6L/jYEZQqWlj9m0SpGVhOeOy4DLXtx4eiOp zV96IC9jD5HjB6tQYnUrPDS01MAbkAmik1iuRxfa1fuHdB/hnH1RUVVBpYdHIllTLEck tL2w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h20si3485118ejy.449.2020.08.19.03.23.04; Wed, 19 Aug 2020 03:23:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727782AbgHSKWV (ORCPT + 99 others); Wed, 19 Aug 2020 06:22:21 -0400 Received: from smtp.h3c.com ([60.191.123.56]:17713 "EHLO h3cspam01-ex.h3c.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726923AbgHSKWU (ORCPT ); Wed, 19 Aug 2020 06:22:20 -0400 Received: from DAG2EX03-BASE.srv.huawei-3com.com ([10.8.0.66]) by h3cspam01-ex.h3c.com with ESMTPS id 07JALZed012120 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 19 Aug 2020 18:21:35 +0800 (GMT-8) (envelope-from tian.xianting@h3c.com) Received: from localhost.localdomain (10.99.212.201) by DAG2EX03-BASE.srv.huawei-3com.com (10.8.0.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Wed, 19 Aug 2020 18:21:38 +0800 From: Xianting Tian To: , , CC: , , Xianting Tian Subject: [PATCH] btrfs: prevent hung check firing during long sync IO Date: Wed, 19 Aug 2020 18:14:51 +0800 Message-ID: <20200819101451.24266-1-tian.xianting@h3c.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.99.212.201] X-ClientProxiedBy: BJSMTP02-EX.srv.huawei-3com.com (10.63.20.133) To DAG2EX03-BASE.srv.huawei-3com.com (10.8.0.66) X-DNSRBL: X-MAIL: h3cspam01-ex.h3c.com 07JALZed012120 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 #include #include +#include #include #include #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