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: =?utf-8?b?5p2O5oms6Z+s?= X-Patchwork-Id: 83044 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1185923vqo; Thu, 13 Apr 2023 10:04:15 -0700 (PDT) X-Google-Smtp-Source: AKy350bZPhHSklNUnpYXEZLPxdDyG3p3jOpvDlTtfUnkC/DoEr8iuctcopQc04OB7d2pBVeTg7pM X-Received: by 2002:a5e:a716:0:b0:75c:f4d8:95a4 with SMTP id b22-20020a5ea716000000b0075cf4d895a4mr1925783iod.7.1681405455338; Thu, 13 Apr 2023 10:04:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1681405455; cv=pass; d=google.com; s=arc-20160816; b=WfBRYna0MxzV7dMYK2RdsYcZfcYGm/MRPr3vRZ+nxAL7OUTLtntqdgs8yWnn8Br+lN WkbpFVYt/nDMmdC0yIyx3plx+UcFJlqTtOwWVQkFCxtuazB3tAK9YcOWn3Ij+xqKJFdN UNQ9W3erf0H/o4vkM7A4UHcKLsLO9ozzu4QrEIcZZ85Udjte6ZXOPGdyFX1Yxu1zMVL2 QCrqssVTX4n7N5wTZJ+7k5E0wlwPTAoCnYBYWEwWvnfmboKi3KVit/wv1kQGuwGtVzww VmG8cTuFDwt4K+cGWmkzX5yWmdZZfz0M8hTJUXm20MFk0sG4wai8f3Z8Z59cfnph150L pgXQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=KIy2/Ql2VbmGn5JLo7/7JEGdi3FIBsu/zp0wLdA/Alc=; b=Yu1xLEwShI5kJz55ztrbvtBjWK+6TEQHNC7Yoenuy5bWHeu6qCYjvSPg3ByVME1IHb IdQsX0P82A5cLl+gz5O2WKxvD1oJRPQl7TA8HpEEdZX6Zm3+ZhPOSw3KRhoKmQDvR7oN 5GyvEyUoJqj7rkZOo1xwKPbpnPux1hnOoMZkUzJyVEbbo0CGEJ9VnD8lHGVsAgebzAby Ov3BTdSOBOyhCJCYRT3KsGEM0xluEnhWzDYMzz6krFLcCXA06y6F8WNkJuyxsJSEzesc O+TqTF4RHERn1niBZ/Mz1KAWNnZe/PePjikixXrCSr6wbl9+4FO/CGm0KcTgXeQEvnDA KMjg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=V74WlcxP; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f6-20020a6b6206000000b00760a6ea764esi2113059iog.106.2023.04.13.10.04.00; Thu, 13 Apr 2023 10:04:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=V74WlcxP; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229932AbjDMRAZ (ORCPT + 99 others); Thu, 13 Apr 2023 13:00:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229728AbjDMRAW (ORCPT ); Thu, 13 Apr 2023 13:00:22 -0400 Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2096.outbound.protection.outlook.com [40.107.255.96]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58E8DAD1B for ; Thu, 13 Apr 2023 10:00:05 -0700 (PDT) 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 From: Yangtao Li To: Jaegeuk Kim , Chao Yu Cc: Yangtao Li , linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH] f2fs: add has_enough_free_secs() 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/JPsuLomFJX6K5SdJFPKv9HTqrcTJ2dcFu8QIQ9NoJ7sErZNZdq71zRT7jQpo7aoNbIso0X9XB/5bqytKk3CZO2yY6oYZjXdI2F3dJZ4S6jJE3OPDxj+VUvP8ntpNSzIrRFyF2QwdgZXZk5fNQDVw7z3RpwIuBewiLKBSyF/t0OH6HtqzdRG9BCZhDc/4VlRoXLTFAYizqk+1mhaZO8tSdncOYrP4oC5JLWHAGwR29J61ayYENsPANOHp1p2CP/Yx38KMQy2b5C4tqzry9i+qPzblCkcHjMEbtBYrFIvjUxgMb5n1v/6NCvJGD9K9Rb0i9XKJk3QqRj/W5oTgr6axRmWah1Q9D5+TrUJqV0G64RYvFsPS3ID58pQjel6pXUHl73uq0P2w5gwRcXvvBkPLxD3RhZwcR6SFVACIWX98mxooJfeOElW6Wk+hDLOlrokY8VRWAou70gqdUfepxT28WQPbxIhoUBU3/H18Xk76m/WDSl7UWT7PAOW6RZqKkUdFQHT5qPrUJiWFhbkYP3K9mBaFmnNkCtAYIkOq3VMIxYiC6CDdhac2aulec+KLqv4EzduwMv4ByDSZSwVqEGhH52zSco4i1dKxKlHwemO6d5p5lb9qY08DjlHOqgXeOb0I72OZewSzVYNNM2tYqIexM3+zT6b2FBO7noh3svdqbJQmJqkMp+YA6Qzid7xxuQTfcXYWGERvFKW5law5Z/gGf0XhKe28CaUjJgpeQZ+9Ta3IIXoOdLZCliSQTIoLt9/efZMEWxwiagVBSg5Hel+9AY8A1qcVzfw79cLZsVB2b0fMIZAlV1qdK2FuygaKDkVg+zVkjjawcMrMxmN/NQxvk6Vd4KHzCrUxufjQCuOJM/ycSZj4MAwdpO08k+zbWiEC/oEvsYhsuUtCfedAngKtzre6U2tX1XuuhVx/kOQE5bUyaeVuvr9dJk4G5RFjpcopL5meUb0amr9A7oxutCXPNpy+/0a36aiiHnHLmsu9usLpMQuXS41cK02z1cbU2baUduCMagctgdfJA6g7Capn8SLaKwkR7L0TlWxeY1ylt/ysbawEELDH8wOYMsjIY2+V4tTiSlvV/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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763081406374041256?= X-GMAIL-MSGID: =?utf-8?q?1763081406374041256?= 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; }