Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp609722ybz; Wed, 15 Apr 2020 15:05:28 -0700 (PDT) X-Google-Smtp-Source: APiQypL6PYcdZmNQ47wMYcYEnFRB+Kw4xVwfCtLimmLFzg3ip8M5nOSVgnBg2Xpg6lJvrVjNRgcP X-Received: by 2002:aa7:dd84:: with SMTP id g4mr4432861edv.273.1586988328812; Wed, 15 Apr 2020 15:05:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586988328; cv=none; d=google.com; s=arc-20160816; b=slSAe/tix3nj7n/nQJAdzDMbKUuEQkZfoYfQmV8pU74JORrbvmH+5sikQRJUvHlAUy tZ5IeqYC9p+2zD0CG80Ksa+cFB0DfT0Mb0XkqlLhSei9KMR+dpd7sHJP12vIlgTLD8I8 LPltbFDYJ+oH1T59P5s3saZ9oNQ5Zgl2LPXTyb2e0AlgQiO7WNhNrv0IPtnYN1YhzzLI RrC1TlDJaHka1vWM2ITXwMpTeyajwdicdV2CXEmrElFumv6ssk1rPsyKopafBlTyOalZ jzJHlO3CCPSTys6afnA828i3Um7CulGOz+YlieR6ofQzDGsAdj25RGOz6PQ7ZVKlX4VF vCPw== 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=MKy8Tu7gkaN05KHcqWvWLn00l3sUgPhsFIeSFjRZ1ZY=; b=Hz/Dbv1XB4uU+fXPH2zOCbaFEpY4bTaX0Tkb0HOiu3An3wDWQ0c2qLjOZaMNv73yVH zqg8Bdqge7wOiqpGnImxE0aQOl51rDz2IKOoLSou+xfGZsHEtoylp9ZKOx+Acb5RuqSK LGDJ+CeNDgpJXqFmGey1iUaTljxboEbcMeGGq+ocJPRCu964fu+GI8kfM4WNu4QWspyl VlEspah2TZ686O/est7XTy5WqyPTWJkWHQwTqRIlPIdFMouGi7dj38iXSlbnx1c/Xm1G koX8mwDU4y0gjwRIyU+Ov9mjzQJMhgicmC9EFT6zuDyo/sfhd9oZAlGuQjw23VHL65Ud rZ1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=iq5xDJyJ; 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 e9si4266691eds.63.2020.04.15.15.05.05; Wed, 15 Apr 2020 15:05: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; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=iq5xDJyJ; 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 S2389499AbgDODb5 (ORCPT + 99 others); Tue, 14 Apr 2020 23:31:57 -0400 Received: from mail27.static.mailgun.info ([104.130.122.27]:28015 "EHLO mail27.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727892AbgDODby (ORCPT ); Tue, 14 Apr 2020 23:31:54 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1586921513; h=Message-Id: Date: Subject: Cc: To: From: Sender; bh=MKy8Tu7gkaN05KHcqWvWLn00l3sUgPhsFIeSFjRZ1ZY=; b=iq5xDJyJl6SM10eT3ZznTtO2pkgC0UZXZPjSDiHH+ms13tMaZZinGEFSJqZFn43TVW9NXTAu BvwWAo1iE2a/73zk5eVrsyorDIRGaJxVjF2z46yjLHHH9pXe7rfsJ9YnVkrNCJj5zeprR5Co D0HusCF0SyI5vcxu5oWiIK0Xgms= X-Mailgun-Sending-Ip: 104.130.122.27 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 5e968009.7f330a46ca78-smtp-out-n05; Wed, 15 Apr 2020 03:31:21 -0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 458E1C43636; Wed, 15 Apr 2020 03:31:20 +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 F2789C433F2; Wed, 15 Apr 2020 03:31:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org F2789C433F2 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 v4] f2fs: fix long latency due to discard during umount Date: Wed, 15 Apr 2020 09:01:02 +0530 Message-Id: <1586921462-12972-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. Fix this by submitting a small batch of discard requests so that it won't cause the device queue to be full at any time and thus doesn't incur its wait time in the umount context. Signed-off-by: Sahitya Tummala --- v4: -Implement as per Jaegeuk's Suggestion to control the number of outstanding discard requests. fs/f2fs/segment.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 1a62b27..764bab5 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -1099,7 +1099,6 @@ static void __init_discard_policy(struct f2fs_sb_info *sbi, } else if (discard_type == DPOLICY_FSTRIM) { dpolicy->io_aware = false; } else if (discard_type == DPOLICY_UMOUNT) { - dpolicy->max_requests = UINT_MAX; dpolicy->io_aware = false; /* we need to issue all to keep CP_TRIMMED_FLAG */ dpolicy->granularity = 1; @@ -1470,12 +1469,14 @@ 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, issued; bool io_interrupted = false; if (dpolicy->timeout != 0) f2fs_update_time(sbi, dpolicy->timeout); +retry: + issued = 0; for (i = MAX_PLIST_NUM - 1; i >= 0; i--) { if (dpolicy->timeout != 0 && f2fs_time_over(sbi, dpolicy->timeout)) @@ -1522,6 +1523,11 @@ static int __issue_discard_cmd(struct f2fs_sb_info *sbi, break; } + if (dpolicy->type == DPOLICY_UMOUNT && issued) { + __wait_all_discard_cmd(sbi, dpolicy); + 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.