From patchwork Thu Jan 2 10:13:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunhai Guo X-Patchwork-Id: 13924378 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 B9D51E77188 for ; Thu, 2 Jan 2025 10:28:51 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1tTIRe-0004Pe-9Y; Thu, 02 Jan 2025 10:28:51 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1tTIRc-0004PV-R4 for linux-f2fs-devel@lists.sourceforge.net; Thu, 02 Jan 2025 10:28:49 +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 :References:In-Reply-To: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:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=T1aMG3GVzwYX0HJCTcQ9ArjF5DoPr2yQtdqerUg8mC0=; b=Z6pI1x2QS72Kd4tqpuQKckVgV8 UxjDz32JxOUPzGXurHi+brILJaNNSOe6XFuAWrb6BZRG+laKpWB9vhT/hDuyueHH1n1aJ/AE5i+HN A8wdXvNBr0Uod6RL0OFJJ9aN0+LG3DdI0zEQfphBtl+/TqgxBHYx1BbplL5m98rdwZRQ=; 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:References: In-Reply-To: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:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=T1aMG3GVzwYX0HJCTcQ9ArjF5DoPr2yQtdqerUg8mC0=; b=RhwZCfHc95QP5nu+ikoyOoGw1M Yko22l+8Oq9+wCc/dmJc6G+IMEvYCfsw544zvy/HqUnsL+/+TeKLuV+pVFjq1AW57urQjoaNRURIF kQQmhFlZhk2wxn1EzEt9TdYMFeQZykD0CZ5jkIBe3HCiSh3qukUthlmp1uS5oKi6V864=; Received: from mail-eastasiaazon11011018.outbound.protection.outlook.com ([52.101.129.18] helo=HK3PR03CU002.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 1tTIRc-0000rJ-SS for linux-f2fs-devel@lists.sourceforge.net; Thu, 02 Jan 2025 10:28:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HRnwIIRUoMVIdEIgsa7np7TCJ1Tw7ZqXWAEEAiHnphEmEjxxKgKdPHwxECKMveO9YDc4jG/CiUb841UOHm1S+ypl4HB27OOtjGNYc+dGRJ6cV5YYri/YzpRCe7s6Of4AjjFxfNcLT4qCnHECXSy44X+sVaMt4EMIfEdNV+3r19mxif+k0OwiEHI+IiX3DuLFmV4aU7Uc/5IFttneL6ME2Wkdcc/+kQ54Gj3sZdH9L0trhqdzWP/BXOCe3eSRW426nMiE75O5QH2F0dCAZboPzlj0UY6TaT361Oti2HaF/Kw0itwQL71HeSv+eHIws/a4O1uk/vPrIck+hWlWL47Udg== 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=T1aMG3GVzwYX0HJCTcQ9ArjF5DoPr2yQtdqerUg8mC0=; b=QQFtpOsm80FTKe3XM4rf1DfIZunP8zveWTGQobzlHRgFWFiSLMdBXs4aCXipKOltU2vkFzTotnkUpWeHx488FErZERcUwwx1HUEZwhC3YWBf5UE4qdBIm0OSix9eLh88u2FVrV2Yl0Qn1JeC7wY9empoQC5pgUo6sXbSUGAdb3d3RUt/eH+etnxQk4EiKfWc4Ltgyooe08SY/vDyqPnXQwlkpog/NU1jGamjpP1FYEPAZRD/pGIMt0+bOALXwMuTQ7XWcmtFuGsuBbxh2pKeVYn3blwuFTvffMgRH3m9K+2vFTDOaRZPDh5UxHqeN3G8RkuwbJfJv97Gf5WTtUDsXw== 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=T1aMG3GVzwYX0HJCTcQ9ArjF5DoPr2yQtdqerUg8mC0=; b=KitFuBENhRbu4d2h1JaDkH7Izyx7tDof6ee1t0SCQ+UzOCU+klSyR7p9mlcGAPpIjEX7WWOGPrt8TpxzRxdI+bLMw2izY5q+UuuqW82Bp/Ygzb3NBPLyQ1C35/VBpgiL1Su0eOuC0hB1n2KwTt/k6eWtSy14GxoB7YyHfdulXmpeSO9MUwUhPJKnUGWGk+niDWtojS1u+YsYKMC2SrMmYyhcBAHXKQPKI3Nyt8K7q9t7mU67CjEbiVlcXR4zM75Mm0JKX6Zcak8r3ErpIvw2kesKuH4BZSi3g0U41xkK+5R0wtLG16KiBw2kdNDBzQ/ljzZTLrjF3cepu4/LR+Tb6A== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from TYZPR06MB7096.apcprd06.prod.outlook.com (2603:1096:405:b5::13) by KL1PR0601MB5726.apcprd06.prod.outlook.com (2603:1096:820:bc::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.9; Thu, 2 Jan 2025 09:55:57 +0000 Received: from TYZPR06MB7096.apcprd06.prod.outlook.com ([fe80::6c3a:9f76:c4a5:c2b]) by TYZPR06MB7096.apcprd06.prod.outlook.com ([fe80::6c3a:9f76:c4a5:c2b%4]) with mapi id 15.20.8314.001; Thu, 2 Jan 2025 09:55:57 +0000 To: chao@kernel.org, jaegeuk@kernel.org Date: Thu, 2 Jan 2025 03:13:09 -0700 Message-Id: <20250102101310.580277-2-guochunhai@vivo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250102101310.580277-1-guochunhai@vivo.com> References: <20250102101310.580277-1-guochunhai@vivo.com> X-ClientProxiedBy: SGAP274CA0010.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b6::22) To TYZPR06MB7096.apcprd06.prod.outlook.com (2603:1096:405:b5::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYZPR06MB7096:EE_|KL1PR0601MB5726:EE_ X-MS-Office365-Filtering-Correlation-Id: 702d3094-53d7-43ae-c25b-08dd2b13a796 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: kYO9XkNKfRvoagVFSlty0Yik75qrAk/cFiX9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MB1dCE/mLulrEkamTZ8nsVSTstO91uwbhNaeeNg+iI2wm+xeh4B37kwTAeYCGa2eSK2V7GuZw54DcrHSuTBhcisl8SQaYikMkyI3cb1aHO2iVRNEiUVKqRGOLIqbVGteVjW6mYRNNxlDiMpL1/GiIp4fEEix0JCW+QophSd6Fh3Q04XD006s2K0kp36tbKd2HQApyuR3vKvewFAnktPmPKKauHCoJLiXNRmD/nuCwca7k79v14mBFB+s6quLVHKDOjnaAsKEcFu2nGuOkl0e4ZbxU2mEtRYAJwATMDlHHgIg25SZNrgVVj7GsjaZSm9BFrlUjtMz03LXRJYAzUtfQiHC58ulTEmiG7t2HEQ X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:TYZPR06MB7096.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: i3x3x8SUPaaAfPinpUW+3UO5m+FzSuuOnpBxkI06iEIjTC8AxryZ8ZG4+fd0GSEwbBknu918HMIk9O0XEVV13uZp8GXMmcAD7gPj6FdIi5d7hAFJQMIoKd0mkAf/2jZDc/xU0O3YptKBpABlTjYb6QtjX9dTzuha+4VjyzybwDc1j3wFgijxkHhMJQsktEpugJjq6XWgJEr5U+qxKH0w+hy0DBpIq2NVbA+YpHMSQ735gMZJ39p8kdFixyLzoKyM4ejPmQHfgJYIb39Sks1l1/kce4GH0kZAiyqtwBgdQLjM8dMJtXwuDQd+mBI1I61oNDEz+obIwCB9Ngn/eKrDnoKcfMUN/uzNkazcnM+C7TU0uQYI6um6IoMAm44FpLd/d13lbn7dnYT0+KwyCoZDz6GhtkrGeZFAju8cP1VhNy09ARTQxSFf0F2B2QsFbtEN/I8/TXlaxl0mTwEqtcmVeNON52FrfCjGJ5IEQWte9mcwlj9zkM49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ipr6TstJdNsf4 X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 702d3094-53d7-43ae-c25b-08dd2b13a796 X-MS-Exchange-CrossTenant-AuthSource: TYZPR06MB7096.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jan 2025 09:55:57.3838 (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: kkr328L6kNVa3DQX6ua41YRUztjaXVerdl8x4TV3GgbtMFKkBfIM0AB2MduO8pd/90tSWKdoKIZdkwUranQJRg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR0601MB5726 X-Headers-End: 1tTIRc-0000rJ-SS Subject: [f2fs-dev] [PATCH 2/2] f2fs: fix missing small discard in fstrim 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 If userspace issues an fstrim with a range that does not include all segments with small discards, these segments will be reused without being discarded. This patch fixes this issue. This patch is somewhat similar to commit 650d3c4e56e1 ("f2fs: fix a missing discard prefree segments"). Fixes: d7bc2484b8d4 ("f2fs: fix small discards not to issue redundantly") Signed-off-by: Chunhai Guo --- fs/f2fs/segment.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 8fe9f794b581..af9a62591c49 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -4552,6 +4552,8 @@ void f2fs_flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc) struct list_head *head = &SM_I(sbi)->sit_entry_set; bool to_journal = !is_sbi_flag_set(sbi, SBI_IS_RESIZEFS); struct seg_entry *se; + bool force = (cpc->reason & CP_DISCARD); + __u64 trim_start = cpc->trim_start; down_write(&sit_i->sentry_lock); @@ -4609,7 +4611,9 @@ void f2fs_flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc) #endif /* add discard candidates */ - if (!(cpc->reason & CP_DISCARD)) { + if (!force || (force && + (segno < trim_start || + segno > cpc->trim_end))) { cpc->trim_start = segno; add_discard_addrs(sbi, cpc, false, false); } @@ -4649,8 +4653,8 @@ void f2fs_flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc) f2fs_bug_on(sbi, !list_empty(head)); f2fs_bug_on(sbi, sit_i->dirty_sentries); out: - if (cpc->reason & CP_DISCARD) { - __u64 trim_start = cpc->trim_start; + if (force) { + cpc->trim_start = trim_start; for (; cpc->trim_start <= cpc->trim_end; cpc->trim_start++) add_discard_addrs(sbi, cpc, true, false);