From patchwork Thu Jan 9 12:27:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunhai Guo X-Patchwork-Id: 13932469 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A67B0E77199 for ; Thu, 9 Jan 2025 12:25:47 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1tVrbe-0007uy-CU; Thu, 09 Jan 2025 12:25:46 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1tVrbd-0007ul-78 for linux-f2fs-devel@lists.sourceforge.net; Thu, 09 Jan 2025 12:25:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=MIME-Version:Content-Type:Content-Transfer-Encoding :Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=UYFMTGTzX5kZZOqhdxtacwAvw3YZs9KcfkBVYuiJfi4=; b=OJ+Xh1Fl1R+FjWSSZwUjpxE+l1 fD83XacTEnUTVKsykZzHez5Me/wUPkh4jFeLCh8kF9tQaTDOGUyqPGrKmnU68nKvigBa8yg7pcgcB qj8SmrlOt/pHzoYzfTz/f/Qa/+/SnSe7ia5DZMPtbAziwxXFZhYOOERbvb5CPQ8WF2jg=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:Content-ID:Content-Description:Resent-Date :Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=UYFMTGTzX5kZZOqhdxtacwAvw3YZs9KcfkBVYuiJfi4=; b=V GqUFXmK+iRhVkEL4oT7ggW6Bmhp+HFFIYXJfpbpA98T/MOSdw7Je9JVD7a8sg9P6wWgn2ZXzKdvEQ HLfdAMCM7g8BwtLTY0rNziOhYSjjWYY/bY/2BbgtuIKIEvk9vqYIWEiO/iKvnEESWJ/sXZwzcUgut AUlMpmC+kOl3HRss=; Received: from mail-tyzapc01on2076.outbound.protection.outlook.com ([40.107.117.76] helo=APC01-TYZ-obe.outbound.protection.outlook.com) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1tVrbc-0000oA-Cm for linux-f2fs-devel@lists.sourceforge.net; Thu, 09 Jan 2025 12:25:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=eM+sQYX2xPXhLtNy8rNUieBiWUs8W0dtKqgfMCjFW/MqbGJvF+YeTMFpMa8eMYQIlRNwOfq1V1tHKlPfZF64QwKpPmM9YwjhwinQPfehuksyopxYRudg1gNPF1IpCjAdnKxxAM7zyVU667a5kLVnrMjAABCvW1c5lYskkX/tYJ8a//HTHDN1FfueSomz+aHjE6nIr0kIiPD9J89nfFI2OENftsprMVDUcXj7WYChJ9SwTW6Pfdb4ZCo8aVAajR21xDo7El/yTczCHG3K+5hycHPn/usAEaGx23nlc2gI4Y/tJS0tYZ/wj+xLgNtNHv4bREsY6qb4u+NI3XzhELLIHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=UYFMTGTzX5kZZOqhdxtacwAvw3YZs9KcfkBVYuiJfi4=; b=kMkar2bWL/G7ux5x8Uu0lT9EBj6V4O0yJmarWIkKw1jHWn2TdgBbglJ8rnUtW2pSg7M/clpcizBnOP5kBpnnvUkJYeeYHh67toJ9MireQZ0OhgmZXktdAXLRJRl6TAqGYLTz3hAYqDRJBNssYU7mi/Ijm4sz1yjHiSL77Gy0KMhxy3FOH0O840eFctp/+RiNEXVrv8fYkXyhUQQ8l+pV5grSD3+xuL8+7R3tuqBVZJlc/Ahb+sSNTrlmqW8EYwyGTbhpzOMzxDtGlY6GyT7uVJSEERoLlSIoUsDP84Ph0GNzfSzVAJ3HAaN/Exaq/dXxs8IdMSkbuJ+3QNbCjRq+Xg== 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=UYFMTGTzX5kZZOqhdxtacwAvw3YZs9KcfkBVYuiJfi4=; b=b7y6170kaV0b4kdhTnLuevgsy77NbNLShAU3t0VkH85r+TiwTI1ByaDcXAAAFfW/JmsYAI+mL0dvlf4JVcdXguqTDF2hUmv10ntsLsZdg7IbfsHX7ptX0qNzd6GubSC+UYaym6JpnNb2l3IDYzB0rLpMGHvwUw9IpwjVm157eLBLlJAN+XND3VhsnACYyUz+sDy9dCElvATMHDv06vyxg49gChnknAtjlh6zqwZ872hA7U401kJxjreECSv08oXKfIvv+GuhEkWvSnnRB6u6A1UQROdq/XIlH/4e+CtrDpNqewLQ5jpo1Pjs37nm0+CiKLKdcubE7PMY0+7ae7NUyw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from SI6PR06MB7103.apcprd06.prod.outlook.com (2603:1096:4:24e::14) by KL1PR06MB6556.apcprd06.prod.outlook.com (2603:1096:820:f1::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.10; Thu, 9 Jan 2025 12:10:33 +0000 Received: from SI6PR06MB7103.apcprd06.prod.outlook.com ([fe80::b34a:c5ea:54cb:7bf9]) by SI6PR06MB7103.apcprd06.prod.outlook.com ([fe80::b34a:c5ea:54cb:7bf9%4]) with mapi id 15.20.8335.010; Thu, 9 Jan 2025 12:10:33 +0000 To: chao@kernel.org, jaegeuk@kernel.org Date: Thu, 9 Jan 2025 05:27:55 -0700 Message-Id: <20250109122755.177926-1-guochunhai@vivo.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SG2PR02CA0132.apcprd02.prod.outlook.com (2603:1096:4:188::15) To SI6PR06MB7103.apcprd06.prod.outlook.com (2603:1096:4:24e::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SI6PR06MB7103:EE_|KL1PR06MB6556:EE_ X-MS-Office365-Filtering-Correlation-Id: b2892cd0-ed35-4564-744f-08dd30a69e3e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|52116014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: Rg2qul0iCD02pFPpmd0rLfDT+g9NR9JFsY++1PmJg781pEyATkMUc3WnVHjzhHBUNHGSDG212M41mI46oEQ0Dr2sFU/ywJNv2W0THZzm+ZU5egb8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U1IjCEonNZUJEja8j/kUHqmiHUF0LjxUyAPXEtm3iZJLG1XxtNaZDibgaCz74syMsUOJsjrF3sPAa8ruhtWC9Eb6+nu84fA7R+TxVcI98i3/0sKMLD5O2yiNM+7sSQDGZkMB1G0XrjH495uHLqtPlTpIbdtVy6jtQBsY1nnQG9EBxKRBrfmeg9OE/A7gK7Nn1VXx627lYnZcKOOPcwyilDIYFamtqtauBJwinFejGvLD1JfytH4dnQHRq3W8r8HaZgLFdPS/MR8fUMbNzd2dPzC6jgA X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SI6PR06MB7103.apcprd06.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(52116014)(1800799024)(366016)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Xt19dl686S74oPAhHrATe4HYiGHPoRCNbkIWgZnlRfE8B7uy8zRlHkizhkHVRKltqwp6I2zbQRjfIT09MnOWGJsbuRvpvhkdISN5kmL6DQQ8tZ4tR2r6wnBOCLQaKr4lUgpbBpUv7MMSMf3iMaOP9ypvSf85RBSLddjNqYnxlnC4hmEcpRQR/Qb8EaKVRPiwdeDb4wx3bI8Q51QuQ/Gmg2J7xCqwxZ/+CgANRhkW8kOCocW0ume7ezhAgEXqHBmkpLSHV46lItz5KmqbRN61APd7s9tzgiM9c6lx9EY4+oBrNRsI3/s6rNo3awDXQuLVx1VnEMMfMRLAjM7xi/43y4nhJ0GJRsrMCtRDc3Gl4KajQ2XFWnc4gzj+mii5nlgqkbPXN7anas73O0GmL9NZs5zLCa74ZKECJAaAlncZg8d8XAMJqH7La8jjcV9sUgBu5nmlNi4b3fyv3HNqoRyyqjGwzXk3eEa552jdO9ZHQiA3IwcKaiSJGxiCVIzmEISIi8JxIH5rfm9KxequmA6Fw7SLiKf1AWyRxtLoj1nAMfT4Pj6+iKR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message-Id: b2892cd0-ed35-4564-744f-08dd30a69e3e X-MS-Exchange-CrossTenant-AuthSource: SI6PR06MB7103.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jan 2025 12:10:33.5642 (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: 05lb+pMR2Fi697ONev4Ef/Iun+bKQo8GT3ugdliUIuAxOvgjECNivIHlkK7/5OlvM8PfR+MZbaaYrjt0o3kOZA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR06MB6556 X-Headers-End: 1tVrbc-0000oA-Cm Subject: [f2fs-dev] [PATCH v2] f2fs: fix missing discard for active segments X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Chunhai Guo via Linux-f2fs-devel From: Chunhai Guo Reply-To: Chunhai Guo Cc: Chunhai Guo , linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net During a checkpoint, the current active segment X may not be handled properly. This occurs when segment X has 0 valid blocks and a non-zero number of discard blocks, for the following reasons: locate_dirty_segment() does not mark any active segment as a prefree segment. As a result, segment X is not included in dirty_segmap[PRE], and f2fs_clear_prefree_segments() skips it when handling prefree segments. add_discard_addrs() skips any segment with 0 valid blocks, so segment X is also skipped. Consequently, no `struct discard_cmd` is actually created for segment X. However, the ckpt_valid_map and cur_valid_map of segment X are synced by seg_info_to_raw_sit() during the current checkpoint process. As a result, it cannot find the missing discard bits even in subsequent checkpoints. Consequently, the value of sbi->discard_blks remains non-zero. Thus, when f2fs is umounted, CP_TRIMMED_FLAG will not be set due to the non-zero sbi->discard_blks. Relevant code process: f2fs_write_checkpoint() f2fs_flush_sit_entries() list_for_each_entry_safe(ses, tmp, head, set_list) { for_each_set_bit_from(segno, bitmap, end) { ... add_discard_addrs(sbi, cpc, false); // skip segment X due to its 0 valid blocks ... seg_info_to_raw_sit(); // sync ckpt_valid_map with cur_valid_map for segment X ... } } f2fs_clear_prefree_segments(); // segment X is not included in dirty_segmap[PRE] and is skipped Since add_discard_addrs() can handle active segments with non-zero valid blocks, it is reasonable to fix this issue by allowing it to also handle active segments with 0 valid blocks. Fixes: b29555505d81 ("f2fs: add key functions for small discards") Signed-off-by: Chunhai Guo --- v1: https://lore.kernel.org/linux-f2fs-devel/20241203065108.2763436-1-guochunhai@vivo.com/ v1->v2: - Modify the commit message to make it easier to understand. - Add fixes to the commit. --- fs/f2fs/segment.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 86e547f008f9..13ee73a3c481 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -2090,7 +2090,9 @@ static bool add_discard_addrs(struct f2fs_sb_info *sbi, struct cp_control *cpc, return false; if (!force) { - if (!f2fs_realtime_discard_enable(sbi) || !se->valid_blocks || + if (!f2fs_realtime_discard_enable(sbi) || + (!se->valid_blocks && + !IS_CURSEG(sbi, cpc->trim_start)) || SM_I(sbi)->dcc_info->nr_discards >= SM_I(sbi)->dcc_info->max_discards) return false;