From nobody Wed Apr 15 19:44:53 2026 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 ACEBAC4332F for ; Mon, 21 Nov 2022 08:28:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230013AbiKUI2W (ORCPT ); Mon, 21 Nov 2022 03:28:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230012AbiKUI2S (ORCPT ); Mon, 21 Nov 2022 03:28:18 -0500 Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01on2134.outbound.protection.outlook.com [40.107.215.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E3E118392 for ; Mon, 21 Nov 2022 00:28:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B+o2naJHGUnRRZYaJK74UMrlyKkvvGjexQVUJRB6qqY8B7CvSDVVegECoifwdQigJOPHcDEpUWWCIWVQVWd+DQj1OPq7xqJ2N/x7Jc++/3by4gN/s/gfsPA+2bzTXWHGDgvfns/UKZbqgCrWDXPIJ3RWeAp0FlTWrx+M015wmh9/A7cezxVitgcpWuBTbyF2nmrmIP8G4kVuY142ihfSJUfyT9vKIvqo1SXhzrUS1rpiYp/HaQegk4d+KJ8s22PNiJxOO+qa8r/PGR8zC1C6MWir2AjCgn6n4uGCNqUB10LMcqLS6AGdPsrFgulotNy2JtwSt5Vq0tZ+OStpGgxNFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=IlU4dUKddj8QxH0PxMegnX3So+QtXEqwfW6MRmxiMwc=; b=kObnySPn/PbU0vPi8Ya+JEeiphNcYJIPov5L1p2XZf2ArKRlDadY6Ho2wumPOx4GTIaWVDDuD3xEeybzpA2NEy2NV8HBm0ZVrOqUzKpMp4d1XDPufkkp5iABu6h7ZZuSKUuHH9Roe4IugbcAAbEaXGhpLP+omgNmWyCnURcA7TLJMV7nyyuwA8G45mfs8NVc65CSzsmoYFfhvjpWDeUBto3W5JB86naMRKcK2UK3eOAe80WPv/rWUcuC5458xyOUKVD7ujl969L6zm6xn/qQ+NJemUViVGDw44ZY50l5sd2I43mrDx89PEfPrC/tOCRGTdWPAZ4glPAZQSVLe4GHYQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IlU4dUKddj8QxH0PxMegnX3So+QtXEqwfW6MRmxiMwc=; b=d6N4yE0LAKFzq0zsOFwjCAP0R3t9KVH+9QZ5yoaC0tgRleFGgGHl7Ju5Foj2fwSAdFhWBi16MC4Vb0rjpLMuELOhRf6yJWfXGqC3pd7H790Dhu9O0H7+F52LjTbFbHhTF7Vy1Ee5Q4ccjnsQAguR2hy6utzZ3eGdmYojW9Sp1cuJrv3W2oqSVMSzPSxrL3IFYQMFVkDrui6GTb3B2FcXbLSOaNkyJYrLXkJDczg1ntfMQhbzcRC1ygIBJ4Grs5J4TTEOGi3ouEnUcB4eM/s/40/zPDmrwP9413C4c6JHBGl3ZvoH/ykgUx6bZTV1oe9aBumDhhTJsSrAOpn1Gt55dQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from SEZPR06MB5269.apcprd06.prod.outlook.com (2603:1096:101:78::6) by TYZPR06MB5001.apcprd06.prod.outlook.com (2603:1096:400:1ce::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5834.15; Mon, 21 Nov 2022 08:28:14 +0000 Received: from SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::1230:5f04:fe98:d139]) by SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::1230:5f04:fe98:d139%8]) with mapi id 15.20.5834.011; Mon, 21 Nov 2022 08:28:13 +0000 From: Yangtao Li To: jaegeuk@kernel.org, chao@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Yangtao Li Subject: [PATCH] f2fs: introduce discard_submit sysfs node Date: Mon, 21 Nov 2022 16:28:03 +0800 Message-Id: <20221121082803.58694-1-frank.li@vivo.com> X-Mailer: git-send-email 2.35.1 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SI1PR02CA0057.apcprd02.prod.outlook.com (2603:1096:4:1f5::10) To SEZPR06MB5269.apcprd06.prod.outlook.com (2603:1096:101:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEZPR06MB5269:EE_|TYZPR06MB5001:EE_ X-MS-Office365-Filtering-Correlation-Id: 6ca5f25c-261a-47e3-984d-08dacb9a54c6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +FvCgUqeekKxMTXzO+cn7V5oSa0XuX8dnn3sVojL8Kws7lMBFnVj5wkT0bEErAu7sj8xPEdHxvRtc04NU4hzGusYKNGflCNTLHJuiwQsWq2jslWdau2IbP/Yy8V9+hJdjdc/YnSzUPk9btudHRLwOA52yO8BSR+JfgjKrUoPv2U2Iv14HuDkP/dogSpTdewKCcI4UELwKSWEz3cWCw2Sx7XQK7nOqwdJefGmKRWDGiJd3acPEl2sIOX8r0GSm0BB+gcvl2vKQ7oFv18QPKyEh35MJDlzErrSO1hJxguWtbB4oSZtqTTyNl+YfEvBSLhZouT30wUYVVMxsnNh4b9lVu3kV9qDAQYbdyEIsbLeb6jSqj+qWX3YNbwJLiew9jXhaWjc6IvN137HOqIqwZ3LCg8uL9bOTu5lWwVIq95Ssyas78pTzDGh53ZLZHYFop5f9lRJQEcb4J97Wf6H3o1xtPEnk0vaKw8dzruDtKIyyAh/iDr+Jt6dcAQsthA0ZrF+dVhX9kPvjcKVXEW909dNPMYApnjvVQnWPVBZ45k2d3jlBbbN8ntdSvg2FLEpQPoRxDfgU5FnbmUqzOGXOcpmFzKouShsLSzKEPcPmy4j46KxMiWaw66PefkotPK6uBeXJTh4suEWppSdkxn42XUCHxZN9Zefos09A6YEDAuUcv0hnOgYZNpLJlW7mHY3A4vUtVvUU9XiEcYEIwRVPVxNUoVpI5mIHT/h00o4Hlb9AB8= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SEZPR06MB5269.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(366004)(376002)(39850400004)(396003)(136003)(451199015)(6486002)(478600001)(6506007)(52116002)(6666004)(107886003)(86362001)(6512007)(38350700002)(316002)(26005)(38100700002)(19627235002)(83380400001)(2906002)(66946007)(4326008)(66476007)(66556008)(8676002)(41300700001)(8936002)(186003)(2616005)(36756003)(1076003)(5660300002)(309714004);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?I2AgKfoR2COIp5YrbYjmxp5ayEDbZMfVPOlRu8s6+r5kzYpNDqx+7AMtoZRi?= =?us-ascii?Q?zZB7oDqOfNx+TfIYUx73mXFpN2xdmu1A7E2GEDVfGfyHk8fmX7ZsNrbbcFgR?= =?us-ascii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Enw4tSnv4Z6lvsigE63pec?= =?us-ascii?Q?1nPfmEydqVnfwdMv6XA8Q38UUifjJ+G2a4mJ7vb8JFzWF73xzvUX4IIBLebG?= =?us-ascii?Q?krioY4lSzSyszyXqyT5Hqx0qi5yGPlkLqxEnL0PgVrrxuIWC5ISpfJ3hQFfk?= =?us-ascii?Q?MYmnPCNyQ/RK4IyxYEYqwktxWVDgt+M4K2zVvL4qeZpruRLPMN+4xBjA+cH1?= =?us-ascii?Q?Ws2RWreUZn4P8+flKmnBPMP/1x7uMj8mC10YKpaIx5mecmd73qvs+WjA/Grw?= =?us-ascii?Q?zi43QmaXTclxI2wKdn/S5dIZ5G609NTCjI57wYkQ76IaVwRWfx5RGd6lLwie?= =?us-ascii?Q?nrSqVMd+q5gPQeWf7beLUSjfjbIYpJVDVt6KiDJJb1HJEYeJjQhklHeeEt2e?= =?us-ascii?Q?7JJxI6rYeJdrmO/GK93zvoKZ1ujRUBtcmVAot67A2NJs/+fkzNBSocfiCuHY?= =?us-ascii?Q?ku9WHKKzqPJyTx/65+vpW9EsAmEa+fhUfvIRFI9SDBgO5uKb+6n6FuTCK197?= =?us-ascii?Q?K6JSyv9nciLe0ZPfMC9mGyrCN80RQg9GZM/tKKk3N+qOrXiPs4BDyhtDEXTV?= =?us-ascii?Q?kv7/yCGcPBVGnBAuoJ+bTAn2K5qVUxBHgY9ECfye?= X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6ca5f25c-261a-47e3-984d-08dacb9a54c6 X-MS-Exchange-CrossTenant-AuthSource: SEZPR06MB5269.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2022 08:28:13.5612 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: jMV9TKMAq6e9Bcai402pFZ1rwZJ2Wj7o4am8rbdN/z+XgWjvnZjVa/RbwjZCtkiSpoEu46tfEPD7vA4N8J/6zw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR06MB5001 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 'discard_submit' sysfs node controls whether discard threads are allowed to submit discard commands. And writing a non-zero value to this node will force the discard thread to wake up immediately. Some scenarios where this node can be used: 1. A large number of unsubmitted discards have accumulated, and the thread still runs at the max_discard_issue_time interval, and the thread needs to be woken up. 2. A large number of discards have been accumulated, which will affect the submission of other commands of the device when submitting. 3. In some specific scenarios, it is necessary to observe the regularity and distribution of the discard command to optimize the discard merging algorithm or other. Signed-off-by: Yangtao Li --- Documentation/ABI/testing/sysfs-fs-f2fs | 10 ++++++++++ fs/f2fs/f2fs.h | 1 + fs/f2fs/segment.c | 8 ++++++++ fs/f2fs/sysfs.c | 11 +++++++++++ 4 files changed, 30 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/te= sting/sysfs-fs-f2fs index 24e7cb77f265..2f42ce42ab9e 100644 --- a/Documentation/ABI/testing/sysfs-fs-f2fs +++ b/Documentation/ABI/testing/sysfs-fs-f2fs @@ -646,3 +646,13 @@ Date: October 2022 Contact: "Yangtao Li" Description: Show the current gc_mode as a string. This is a read-only entry. + +What: /sys/fs/f2fs//discard_submit +Date: November 2022 +Contact: "Yangtao Li" +Description: Controls whether discard threads are allowed to submit discar= d commands. + When set to 0, the discard thread running time will be changed to max_di= scard_issue_time, + and the discard command will not be sent to the device. Otherwise, writi= ng other + values to this node will force the discard thread to wake up immediately= , and + the discard command will be allowed to be sent to the device. + Default: 1 diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index f0833638f59e..81e5816e4b34 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -420,6 +420,7 @@ struct discard_cmd_control { atomic_t discard_cmd_cnt; /* # of cached cmd count */ struct rb_root_cached root; /* root of discard rb-tree */ bool rbtree_check; /* config for consistence check */ + bool discard_submit; /* allow submit discard cmd or not */ }; =20 /* for the list of fsync inodes, used only during recovery */ diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 8b0b76550578..5b0a67ccdac3 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -1115,6 +1115,9 @@ static int __submit_discard_cmd(struct f2fs_sb_info *= sbi, if (is_sbi_flag_set(sbi, SBI_NEED_FSCK)) return 0; =20 + if (!dcc->discard_submit) + return 0; + trace_f2fs_issue_discard(bdev, dc->start, dc->len); =20 lstart =3D dc->lstart; @@ -1717,6 +1720,10 @@ static int issue_discard_thread(void *data) wait_ms =3D dpolicy.max_interval; continue; } + if (!dcc->discard_submit) { + wait_ms =3D dpolicy.max_interval; + continue; + } if (!atomic_read(&dcc->discard_cmd_cnt)) continue; =20 @@ -2085,6 +2092,7 @@ static int create_discard_cmd_control(struct f2fs_sb_= info *sbi) dcc->min_discard_issue_time =3D DEF_MIN_DISCARD_ISSUE_TIME; dcc->mid_discard_issue_time =3D DEF_MID_DISCARD_ISSUE_TIME; dcc->max_discard_issue_time =3D DEF_MAX_DISCARD_ISSUE_TIME; + dcc->discard_submit =3D true; dcc->undiscard_blks =3D 0; dcc->next_pos =3D 0; dcc->root =3D RB_ROOT_CACHED; diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c index 33ec467b3772..b6f017b4d565 100644 --- a/fs/f2fs/sysfs.c +++ b/fs/f2fs/sysfs.c @@ -661,6 +661,15 @@ static ssize_t __sbi_store(struct f2fs_attr *a, return count; } =20 + if (!strcmp(a->attr.name, "discard_submit")) { + struct discard_cmd_control *dcc =3D SM_I(sbi)->dcc_info; + + dcc->discard_submit =3D !!t; + if (dcc->discard_submit) + wake_up_discard_thread(sbi, true); + return count; + } + *ui =3D (unsigned int)t; =20 return count; @@ -800,6 +809,7 @@ F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_discard= _request, max_discard_req F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, min_discard_issue_time, min_di= scard_issue_time); F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, mid_discard_issue_time, mid_di= scard_issue_time); F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_discard_issue_time, max_di= scard_issue_time); +F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, discard_submit, discard_submit= ); F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, discard_granularity, discard_g= ranularity); F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_ordered_discard, max_order= ed_discard); F2FS_RW_ATTR(RESERVED_BLOCKS, f2fs_sb_info, reserved_blocks, reserved_bloc= ks); @@ -930,6 +940,7 @@ static struct attribute *f2fs_attrs[] =3D { ATTR_LIST(min_discard_issue_time), ATTR_LIST(mid_discard_issue_time), ATTR_LIST(max_discard_issue_time), + ATTR_LIST(discard_submit), ATTR_LIST(discard_granularity), ATTR_LIST(max_ordered_discard), ATTR_LIST(pending_discard), --=20 2.25.1