Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2140216ybb; Sun, 29 Mar 2020 23:47:39 -0700 (PDT) X-Google-Smtp-Source: ADFU+vs94xBFrbV/vLsNp/PodKixxidT/hfwwgAsesu18AdwgL+OKkNfrWllm8iGPwROrSiP0pTr X-Received: by 2002:a05:6830:239b:: with SMTP id l27mr8218351ots.278.1585550859808; Sun, 29 Mar 2020 23:47:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585550859; cv=none; d=google.com; s=arc-20160816; b=1CNDH0r+L9UIulRkHdaZ90/ffz065XmJA3smW+BmT2x8FPEkuSra16dOs5IIdZgrX5 rNkEmNP5LOW+sid1JqMc3taQwuPu40YGgVNYJ1mky+BOniqRQKDp46N/Vq/3fw2NBNbR eUVAdnx4ImVWdY35Tp5Y/HiPKdHA4n9tvpDfgbQefg5z97j5ptslI6n+atNwIr5Tbsnt VVNjFIFLpAXEC6+cb2Vs5GJpbU0v+QaZQgFL8qdyi21dYTifdGsVslgWuu+yJ/V328ZR gUNWmm47uuL/lzQWLnh82mbX2bBEdGKMNfBfyz8BXSAym26X4OQ0xNnjxjUimMFA0jT6 sU+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dmarc-filter:dkim-signature; bh=URzNECvAI1Ghk10GnUEl6Jn6n1Bg3PLrHrv0MX+tgvo=; b=ORM9FV+OndkOM5EELBwn8E0R6g1HI8z1+OHNMBQoBt3znExZdFTd+I1Ae5PJIvh1eH 1MMDgede3Ls1vbPxF7YGFF/ymdwZ3n95rb4rxwoKyWXL1Pdzva0AFWNY1PIkm2Io3r2W nRwphfnPEWZcvdO/KWX4LvnGwxyasihfLdOvZEijM8Za7XxppJ/L0bsxsM3mDbpoFf2W zVs+G8WCOH9v8t+c3KLDDHhioZU0sCOnPd50Y7pDOW2hQlN8b/sptkeA5pnIQk+/2thZ 3znKt7f2gavTopn9uNuyMH/gFcAoiMdd3clfkpjO+Cdpk+qHEi3XSoPj3Ynbyn8f/Mcl 90Tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=lQKOepWZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n4si5400770oie.121.2020.03.29.23.47.27; Sun, 29 Mar 2020 23:47:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=lQKOepWZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729202AbgC3Gpv (ORCPT + 99 others); Mon, 30 Mar 2020 02:45:51 -0400 Received: from mail26.static.mailgun.info ([104.130.122.26]:15972 "EHLO mail26.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728964AbgC3Gpv (ORCPT ); Mon, 30 Mar 2020 02:45:51 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1585550750; h=Message-Id: Date: Subject: Cc: To: From: Sender; bh=URzNECvAI1Ghk10GnUEl6Jn6n1Bg3PLrHrv0MX+tgvo=; b=lQKOepWZsDurrUnlESXCozudINfoAqk9g4yltyZl4NsxOFXVvWKttYofn5XFDWld5LAv5Fz1 aatfsF5N0Q6xdhEu7DtxFIN7FsUz6oRPAZRejUXC8Gf8XZTa9fMC0K3xtMxDebdksHqLvvNR YdeYPQorcydvwFm4GKuqg0cPSs0= X-Mailgun-Sending-Ip: 104.130.122.26 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by mxa.mailgun.org with ESMTP id 5e819597.7f8c311e5df8-smtp-out-n05; Mon, 30 Mar 2020 06:45:43 -0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1001) id D57AEC4478C; Mon, 30 Mar 2020 06:45:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=2.0 tests=ALL_TRUSTED,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.0 Received: from codeaurora.org (blr-c-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: stummala) by smtp.codeaurora.org (Postfix) with ESMTPSA id 573B4C433D2; Mon, 30 Mar 2020 06:45:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 573B4C433D2 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=stummala@codeaurora.org From: Sahitya Tummala To: Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net Cc: Sahitya Tummala , linux-kernel@vger.kernel.org Subject: [PATCH v3] f2fs: fix long latency due to discard during umount Date: Mon, 30 Mar 2020 12:15:30 +0530 Message-Id: <1585550730-1858-1-git-send-email-stummala@codeaurora.org> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org F2FS already has a default timeout of 5 secs for discards that can be issued during umount, but it can take more than the 5 sec timeout if the underlying UFS device queue is already full and there are no more available free tags to be used. In that case, submit_bio() will wait for the already queued discard requests to complete to get a free tag, which can potentially take way more than 5 sec. Fix this by submitting the discard requests with REQ_NOWAIT flags during umount. This will return -EAGAIN for UFS queue/tag full scenario without waiting in the context of submit_bio(). The FS can then handle these requests by retrying again within the stipulated discard timeout period to avoid long latencies. Signed-off-by: Sahitya Tummala --- v3: -Handle the regression reported by Chao with v2. -simplify the logic to split the dc with multiple bios incase any bio returns EAGAIN and retry those new dc within 5 sec timeout. fs/f2fs/segment.c | 65 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 14 deletions(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index fb3e531..55d18c7 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -1029,13 +1029,16 @@ static void f2fs_submit_discard_endio(struct bio *bio) struct discard_cmd *dc = (struct discard_cmd *)bio->bi_private; unsigned long flags; - dc->error = blk_status_to_errno(bio->bi_status); - spin_lock_irqsave(&dc->lock, flags); + if (!dc->error) + dc->error = blk_status_to_errno(bio->bi_status); + dc->bio_ref--; - if (!dc->bio_ref && dc->state == D_SUBMIT) { - dc->state = D_DONE; - complete_all(&dc->wait); + if (!dc->bio_ref) { + if (dc->error || dc->state == D_SUBMIT) { + dc->state = D_DONE; + complete_all(&dc->wait); + } } spin_unlock_irqrestore(&dc->lock, flags); bio_put(bio); @@ -1124,10 +1127,13 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi, struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; struct list_head *wait_list = (dpolicy->type == DPOLICY_FSTRIM) ? &(dcc->fstrim_list) : &(dcc->wait_list); - int flag = dpolicy->sync ? REQ_SYNC : 0; + int flag; block_t lstart, start, len, total_len; int err = 0; + flag = dpolicy->sync ? REQ_SYNC : 0; + flag |= dpolicy->type == DPOLICY_UMOUNT ? REQ_NOWAIT : 0; + if (dc->state != D_PREP) return 0; @@ -1192,10 +1198,6 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi, dc->bio_ref++; spin_unlock_irqrestore(&dc->lock, flags); - atomic_inc(&dcc->queued_discard); - dc->queued++; - list_move_tail(&dc->list, wait_list); - /* sanity check on discard range */ __check_sit_bitmap(sbi, lstart, lstart + len); @@ -1203,6 +1205,29 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi, bio->bi_end_io = f2fs_submit_discard_endio; bio->bi_opf |= flag; submit_bio(bio); + if (flag & REQ_NOWAIT) { + if (dc->error == -EAGAIN) { + spin_lock_irqsave(&dc->lock, flags); + dc->len -= len; + if (!dc->len) { + dc->len = total_len; + dc->state = D_PREP; + reinit_completion(&dc->wait); + } else { + dcc->undiscard_blks -= total_len; + if (dc->state == D_PARTIAL) + dc->state = D_SUBMIT; + } + err = dc->error; + dc->error = 0; + spin_unlock_irqrestore(&dc->lock, flags); + break; + } + } + + atomic_inc(&dcc->queued_discard); + dc->queued++; + list_move_tail(&dc->list, wait_list); atomic_inc(&dcc->issued_discard); @@ -1214,8 +1239,9 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi, len = total_len; } - if (!err && len) - __update_discard_tree_range(sbi, bdev, lstart, start, len); + if ((!err || err == -EAGAIN) && total_len && dc->start != start) + __update_discard_tree_range(sbi, bdev, lstart, start, + total_len); return err; } @@ -1470,12 +1496,15 @@ static int __issue_discard_cmd(struct f2fs_sb_info *sbi, struct list_head *pend_list; struct discard_cmd *dc, *tmp; struct blk_plug plug; - int i, issued = 0; + int i, err, issued = 0; bool io_interrupted = false; + bool retry; if (dpolicy->timeout != 0) f2fs_update_time(sbi, dpolicy->timeout); +retry: + retry = false; for (i = MAX_PLIST_NUM - 1; i >= 0; i--) { if (dpolicy->timeout != 0 && f2fs_time_over(sbi, dpolicy->timeout)) @@ -1509,7 +1538,12 @@ static int __issue_discard_cmd(struct f2fs_sb_info *sbi, break; } - __submit_discard_cmd(sbi, dpolicy, dc, &issued); + err = __submit_discard_cmd(sbi, dpolicy, dc, &issued); + if (err == -EAGAIN) { + congestion_wait(BLK_RW_ASYNC, + DEFAULT_IO_TIMEOUT); + retry = true; + } if (issued >= dpolicy->max_requests) break; @@ -1522,6 +1556,9 @@ static int __issue_discard_cmd(struct f2fs_sb_info *sbi, break; } + if (retry) + goto retry; + if (!issued && io_interrupted) issued = -1; -- Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.