From nobody Thu Sep 18 04:23:46 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C963C4167B for ; Sun, 11 Dec 2022 12:23:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230217AbiLKMTV (ORCPT ); Sun, 11 Dec 2022 07:19:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229475AbiLKMTS (ORCPT ); Sun, 11 Dec 2022 07:19:18 -0500 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20815101E4 for ; Sun, 11 Dec 2022 04:19:17 -0800 (PST) Received: by mail-pf1-x431.google.com with SMTP id w26so776601pfj.6 for ; Sun, 11 Dec 2022 04:19:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=2gPtb0kZX78YC1crT8EvCgaAOrm2u8F10CNCRPyKjDs=; b=qrIcVpUzXvWXYO3UhPLOnorH/Eu/FHJejqP7uivXntXh0txXkSUgUup7nNojEoAKCa EmCWI3H16krYpIW2w2JWRS7C1LzuS7hcv9S3p34ufjZEexlyIOEWrWFKSZjqscfzEaa7 hz5CVyjz1PHWYOWPxtN+nmHDD0dW1SeWi/DcYir/6H4rhDNT3KkV3ZxeToSkxi9S8VG3 8xb/mCU4fr1rNTrr52nEuGoNCqRHtp3bDZMDSCvA9MR/COJKTGIBRdZuBWt0rkukMBSf NLer25MBEjP0hrAmNKg6xavme1lWhZ1MAEMOt8NigV8ARg9BxQ02Jcx8r2bvQML8/WFV ncMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2gPtb0kZX78YC1crT8EvCgaAOrm2u8F10CNCRPyKjDs=; b=sEmLX/QpAOKgo+eRidslqXzKB56meVMAkbecHH0dHqDITZLUd3Y5nqI+l5rp+hkTWP M6o786j7E4iYvrPdR0+KytjBIeyuXjWBrxTrLxTPA1cxnkxhsugP4FQLUhZVnN4LajlF XbUnLL/X9z5Z6CpAfMf9WqlEtiAjc/Sw3n3uIhvOcWfRo/Vl58473O8XNAut0N9SCZPD uw2TlfA1biqvVdVaDK77wSHPGQDKrDWbSp5vv+n301/eDunbfMFtuTt9fsxXIh8O6Xj4 RAq72zRXPYSuV4KMhA3a8UaSWJEgyiDkdkmU4H5HQkSoTYzEfZaXZBadX53pK01OHGwt Vpkg== X-Gm-Message-State: ANoB5pn2tscZtmpJoksQRqiymZt7HFJr9/Et5TXfnkBpshBX8kxF7a/w RHx3BMMdH4nvSWN4ErLIfuFCwIPVsRh0qg== X-Google-Smtp-Source: AA0mqf4vuuM+wRcWw8X2rkwWqijFrj/G0xljLe1/XMy+uhyQPu5NxN2mrGYn/do9HVRXVBE6izGVRw== X-Received: by 2002:aa7:9050:0:b0:56d:67d7:1eb2 with SMTP id n16-20020aa79050000000b0056d67d71eb2mr12565044pfo.19.1670761156574; Sun, 11 Dec 2022 04:19:16 -0800 (PST) Received: from VirtualBox.. ([129.227.152.6]) by smtp.gmail.com with ESMTPSA id k145-20020a628497000000b00578199ea5afsm2472838pfd.9.2022.12.11.04.19.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Dec 2022 04:19:16 -0800 (PST) From: Yuwei Guan X-Google-Original-From: Yuwei Guan To: jaegeuk@kernel.org, chao@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Yuwei.Guan@zeekrlife.com Subject: [PATCH v2] f2fs: continuous counting for 'issued' in __issue_discard_cmd_orderly() Date: Sun, 11 Dec 2022 20:18:52 +0800 Message-Id: <20221211121852.112127-1-Yuwei.Guan@zeekrlife.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" As the 'dcc->discard_granularity' and 'dcc->max_ordered_discard' can be set at the user space, and if the 'dcc->max_ordered_discard' is set larger than 'dcc->discard_granularity' in DPOLICY_BG mode, or it's a volume device, discard_granularity can be tuned to 1 in f2fs_tuning_parameters(), it will may send more requests than the number of 'dpolicy->max_requests' in issue_discard_thread(). This patch will fix the issue. Signed-off-by: Yuwei Guan --- fs/f2fs/segment.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index a9099a754dd2..908b9a9bd82d 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -1379,8 +1379,8 @@ static void __queue_discard_cmd(struct f2fs_sb_info *= sbi, mutex_unlock(&SM_I(sbi)->dcc_info->cmd_lock); } =20 -static unsigned int __issue_discard_cmd_orderly(struct f2fs_sb_info *sbi, - struct discard_policy *dpolicy) +static void __issue_discard_cmd_orderly(struct f2fs_sb_info *sbi, + struct discard_policy *dpolicy, int *issued) { struct discard_cmd_control *dcc =3D SM_I(sbi)->dcc_info; struct discard_cmd *prev_dc =3D NULL, *next_dc =3D NULL; @@ -1388,7 +1388,6 @@ static unsigned int __issue_discard_cmd_orderly(struc= t f2fs_sb_info *sbi, struct discard_cmd *dc; struct blk_plug plug; unsigned int pos =3D dcc->next_pos; - unsigned int issued =3D 0; bool io_interrupted =3D false; =20 mutex_lock(&dcc->cmd_lock); @@ -1415,9 +1414,9 @@ static unsigned int __issue_discard_cmd_orderly(struc= t f2fs_sb_info *sbi, } =20 dcc->next_pos =3D dc->lstart + dc->len; - err =3D __submit_discard_cmd(sbi, dpolicy, dc, &issued); + err =3D __submit_discard_cmd(sbi, dpolicy, dc, issued); =20 - if (issued >=3D dpolicy->max_requests) + if (*issued >=3D dpolicy->max_requests) break; next: node =3D rb_next(&dc->rb_node); @@ -1433,10 +1432,8 @@ static unsigned int __issue_discard_cmd_orderly(stru= ct f2fs_sb_info *sbi, =20 mutex_unlock(&dcc->cmd_lock); =20 - if (!issued && io_interrupted) - issued =3D -1; - - return issued; + if (!(*issued) && io_interrupted) + *issued =3D -1; } static unsigned int __wait_all_discard_cmd(struct f2fs_sb_info *sbi, struct discard_policy *dpolicy); @@ -1464,8 +1461,10 @@ static int __issue_discard_cmd(struct f2fs_sb_info *= sbi, if (i + 1 < dpolicy->granularity) break; =20 - if (i + 1 < dcc->max_ordered_discard && dpolicy->ordered) - return __issue_discard_cmd_orderly(sbi, dpolicy); + if (i + 1 < dcc->max_ordered_discard && dpolicy->ordered) { + __issue_discard_cmd_orderly(sbi, dpolicy, &issued); + return issued; + } =20 pend_list =3D &dcc->pend_list[i]; =20 --=20 2.34.1