From patchwork Thu Apr 13 16:59:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangtao Li X-Patchwork-Id: 13210471 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 1750AC77B6E for ; Thu, 13 Apr 2023 17:00:15 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1pn0Iu-0001CF-JM; Thu, 13 Apr 2023 17:00:13 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pn0It-0001C8-B8 for linux-f2fs-devel@lists.sourceforge.net; Thu, 13 Apr 2023 17:00:12 +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=KIy2/Ql2VbmGn5JLo7/7JEGdi3FIBsu/zp0wLdA/Alc=; b=JFRqdhovkiUWt3VJLcv7LJ4DeT usSRHitNZf5CC1olyHYrpDMS4hg4BRLS0Ybeek2H//2IUGb5DQrQmy3VtNnpk6AssU8zcJEARZI9J yhJgi0pOHVsyNylbuePT49pW+zWp3o/zPfA44G2QEz4ajQtPUKzYKrPzACST24CLi4lQ=; 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=KIy2/Ql2VbmGn5JLo7/7JEGdi3FIBsu/zp0wLdA/Alc=; b=P SjKZfTQrmtCL6A6s5/pFw0FsXR3J9UZ3RwLHyGCwOQ8YDApCreZAzsarphLCPhoIPXApYw6IG7ohD AJwFJ8UNoBTh2kTJ/TIdjLn/whP6FSC4W+hYiLK24QXiDq8msC5Teh4wBnC1dTdvgagNYlkZ3HK+q VkxjnigeEUAaODe0=; Received: from mail-psaapc01on2123.outbound.protection.outlook.com ([40.107.255.123] helo=APC01-PSA-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 1pn0Ir-0000Cg-Um for linux-f2fs-devel@lists.sourceforge.net; Thu, 13 Apr 2023 17:00:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Nt73Ordig8I2fmxH8O0icn2ikuw2rGJsUpKYk+ZWZEGoY2fuNH6p82Wo4oj3OZbbeWPA6WOYPEdJZhKO9Ia7D/z2l/UCCtmeWxpbA44cIAVNbM7oq5NlYv3syT+BF/RN/WGThXFOZpXp+L9WsvAHUpdiiLoLNzXSxUWzpezpeSFNtKGheX0SwK0ciSskf1STD94s9v+GbFsgcjTPc93VT5810gRI3h8nlaybVvPidVFrsb0skRPn7ewJk3taAHSi6yj58k93QjJEskYMdv/et3MkyegF93G9xPM888eaa4p7f/l4VdNJqw9HEgN+R6jhXBhNGVRDfQ8j620CxyjMQA== 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=KIy2/Ql2VbmGn5JLo7/7JEGdi3FIBsu/zp0wLdA/Alc=; b=a61M/7NkfWweWNlvK5XJznJ9qfA1LaaShkyU+89y1EZakuh/FN+3WXEP12VnEIiSQAnxzyQR8vdfi5kQlqXV1xPnlL8k9e2U4CR9Wf9F9Jr6M1YctiPhe9PdoA6g2l8j76A35UUNpLE8ns/5ob2U0/kd2s0OIux0HcgovhJcarVREeQc3UlPhA7f2mtA1H5H+57+mL4M4tZaOJBsqQlxeypvlkiAzxX9QvKEtBunAnPXP8bn1mJ2l3wokzbmWybCuFPbJiV1obCU7Bizuyn3h9PU8i3VqmCRGSPvXH//f9c3zHt0ob3pacLptUOzOi6GCxJIbLRRVnZD97ZcYRPR/A== 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=KIy2/Ql2VbmGn5JLo7/7JEGdi3FIBsu/zp0wLdA/Alc=; b=V74WlcxP36vDBl+aUvk356vZuVMP/GX7PO7kBDsXz3VEf/C6veqMeARJwXn881HKDgqyDpjM1ZX4YIPgZxpNdxNf+VCAzEFlWAE86khbgWhrt3QRn4SEQoRtXxI3prdwUGWSW7+Sezyqlf1FKQ9uaWLad19u0MVyETFoV+AR5ASvMqA/Gq1qd8rqNaYek/zwNqMDwPjkDLG1rwrLeKmTWc9fM1LXaopSD3thf/1llVZ1s6BM6ak5V5Oqby7tY5QavMG9yCiLa4V70h2WN37qIfrsJ0Qicdrf6D4nSjiIimD4Mu5VoKyhKdUdvOMHoXzJnHq4hvnH6MHLdriDu9aA+Q== 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 SG2PR06MB5359.apcprd06.prod.outlook.com (2603:1096:4:1d7::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.34; Thu, 13 Apr 2023 17:00:01 +0000 Received: from SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::a3a1:af8e:be1e:437c]) by SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::a3a1:af8e:be1e:437c%6]) with mapi id 15.20.6277.038; Thu, 13 Apr 2023 17:00:01 +0000 To: Jaegeuk Kim , Chao Yu Date: Fri, 14 Apr 2023 00:59:51 +0800 Message-Id: <20230413165951.54051-1-frank.li@vivo.com> X-Mailer: git-send-email 2.35.1 X-ClientProxiedBy: SG2PR04CA0202.apcprd04.prod.outlook.com (2603:1096:4:187::20) To SEZPR06MB5269.apcprd06.prod.outlook.com (2603:1096:101:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEZPR06MB5269:EE_|SG2PR06MB5359:EE_ X-MS-Office365-Filtering-Correlation-Id: a6e58605-5212-4402-d8d1-08db3c408554 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Byv/3yeKOQ/GasG3lFGKB4f2G/0zMClEJWfnw5rmZGF9FxWrq8yypDGeoUdtd3duvuGGXXtBWHniKGzpUKyeDYtZo8mKU5hCjZRe0Zx8ApLqYSUqHghh59UEcvC6W0AnDeG/ojLruM3W/Q2Mj7qB9tBRep+1e3cKQPGW6zJ4HJDPG7rufIGGl//an7zs/22Qbr8jZVbmHBSGilqJ5fOQFImM5+Rlfd3qFkOazPhG7KnNHkgqoGsXUnbD3D6oWZlL7FhuEhs5QnZLXL1Y3bJXH84y10c0oiV9gBs1WRdfiqxCWgb/HkGPNx71lPabskmHpop9gPvTBrubJB4p5m3yGyL5vHS0nwA8g2zck32frd2eNYZuFIxapDqSgTkR1bGC7Ih/Kai9IhLdP/ihgX+s7RcE+b1qAFhu4EHW/LoYrpzRhieri45rf9tqJ3xlvljOLOh65zpfegZE7xq1rmyVH7PX9VNwJJxXEEopbf6flABAkQCBjjDGDN3F9rQRN0BusPenEGDTgGjmzP4RhwjA17MP1IxPOMbDsg6n+8CUTYYVu6VTDRO6eQEhqGLzaZkq347qH2pjpswq/M56Rud/hb5Ci1a4nYLLq+Hm2giX+CagiUv2COP3bebYD4n93ks8 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:(13230028)(4636009)(366004)(346002)(39860400002)(136003)(376002)(396003)(451199021)(316002)(6506007)(1076003)(86362001)(186003)(6512007)(83380400001)(2616005)(36756003)(26005)(110136005)(6486002)(478600001)(52116002)(6666004)(4326008)(66476007)(2906002)(8676002)(41300700001)(8936002)(66946007)(66556008)(5660300002)(38100700002)(38350700002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: dPjYlz1nNKdq2nv0gPIs74X3554UGJlopip/m/QRgv6irXLufzZG7yyWxTaXPNktS0D2SksRVRu/pHGVCnJF88JA8xoldJZcatm39e2hT4jWKvAyWS/X01an9/qV3UylV8Xda2v7uErwqlYfB2CXbnx10WeoF2ejfp5w//Mmwsa027VJc1Gsyew5E2u94T9uNQeZxCH3+xthlvR+iOc/ZTm+aUvPsXFxTpk8hyrtjN9/JP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4tTiSlvV/5yUuUbvyjDjeKPOcA36fekgGlG3dzwnWzLEVvAxR8ou1ImK6+7zbyZz+vR00p3khxE8001vLfhHBS2/wB0g8LDhNWz0IFvojBcxSkVM56hNWNK+GRPbjJhlpeM7F9hOJcit4hvVZlbxbMjWIov/B1JCtcKChm5LkTCONLsqOTsmo90kF3GGWCz6/Vc9t/TUiavqQarfEPmBpm+DN6OJTKkiDKS31ZSl+GKBS8E0FUa0VrdNZa4CxgK8gbx6JOp5FiYviHqKCN9U X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: a6e58605-5212-4402-d8d1-08db3c408554 X-MS-Exchange-CrossTenant-AuthSource: SEZPR06MB5269.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Apr 2023 17:00:01.7397 (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: pBhJzwYXQDCp1etCwiEsWd+Ql14HhuzQDCYue94MdLbf4HuSPQp9FsKy+qqqgaoCciZX/P+tWnwel+4XKHI/wQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SG2PR06MB5359 X-Headers-End: 1pn0Ir-0000Cg-Um Subject: [f2fs-dev] [PATCH] f2fs: add has_enough_free_secs() 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: Yangtao Li via Linux-f2fs-devel From: Yangtao Li Reply-To: Yangtao Li Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Yangtao Li Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net Replace !has_not_enough_free_secs w/ has_enough_free_secs. BTW avoid nested 'if' statements in f2fs_balance_fs(). Signed-off-by: Yangtao Li --- fs/f2fs/gc.c | 2 +- fs/f2fs/segment.c | 43 ++++++++++++++++++++++--------------------- fs/f2fs/segment.h | 8 +++++++- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index c748cdfb0501..79a7b4e31672 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -1872,7 +1872,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control) sbi->cur_victim_sec = NULL_SEGNO; if (gc_control->init_gc_type == FG_GC || - !has_not_enough_free_secs(sbi, + has_enough_free_secs(sbi, (gc_type == FG_GC) ? sec_freed : 0, 0)) { if (gc_type == FG_GC && sec_freed < gc_control->nr_free_secs) goto go_gc_more; diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 82430f80c5da..c35476b3c075 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -412,27 +412,28 @@ void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need) * We should do GC or end up with checkpoint, if there are so many dirty * dir/node pages without enough free segments. */ - if (has_not_enough_free_secs(sbi, 0, 0)) { - if (test_opt(sbi, GC_MERGE) && sbi->gc_thread && - sbi->gc_thread->f2fs_gc_task) { - DEFINE_WAIT(wait); - - prepare_to_wait(&sbi->gc_thread->fggc_wq, &wait, - TASK_UNINTERRUPTIBLE); - wake_up(&sbi->gc_thread->gc_wait_queue_head); - io_schedule(); - finish_wait(&sbi->gc_thread->fggc_wq, &wait); - } else { - struct f2fs_gc_control gc_control = { - .victim_segno = NULL_SEGNO, - .init_gc_type = BG_GC, - .no_bg_gc = true, - .should_migrate_blocks = false, - .err_gc_skipped = false, - .nr_free_secs = 1 }; - f2fs_down_write(&sbi->gc_lock); - f2fs_gc(sbi, &gc_control); - } + if (has_enough_free_secs(sbi, 0, 0)) + return; + + if (test_opt(sbi, GC_MERGE) && sbi->gc_thread && + sbi->gc_thread->f2fs_gc_task) { + DEFINE_WAIT(wait); + + prepare_to_wait(&sbi->gc_thread->fggc_wq, &wait, + TASK_UNINTERRUPTIBLE); + wake_up(&sbi->gc_thread->gc_wait_queue_head); + io_schedule(); + finish_wait(&sbi->gc_thread->fggc_wq, &wait); + } else { + struct f2fs_gc_control gc_control = { + .victim_segno = NULL_SEGNO, + .init_gc_type = BG_GC, + .no_bg_gc = true, + .should_migrate_blocks = false, + .err_gc_skipped = false, + .nr_free_secs = 1 }; + f2fs_down_write(&sbi->gc_lock); + f2fs_gc(sbi, &gc_control); } } diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h index ac2e35170f2d..2ca8fb5d0dc4 100644 --- a/fs/f2fs/segment.h +++ b/fs/f2fs/segment.h @@ -643,11 +643,17 @@ static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi, return !curseg_space; } +static inline bool has_enough_free_secs(struct f2fs_sb_info *sbi, + int freed, int needed) +{ + return !has_not_enough_free_secs(sbi, freed, needed); +} + static inline bool f2fs_is_checkpoint_ready(struct f2fs_sb_info *sbi) { if (likely(!is_sbi_flag_set(sbi, SBI_CP_DISABLED))) return true; - if (likely(!has_not_enough_free_secs(sbi, 0, 0))) + if (likely(has_enough_free_secs(sbi, 0, 0))) return true; return false; }