From patchwork Fri Sep 15 09:04:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wu Bo X-Patchwork-Id: 13386611 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 5D8B7EE644B for ; Fri, 15 Sep 2023 08:57:13 +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 1qh4dW-0000fc-0W; Fri, 15 Sep 2023 08:57:12 +0000 Received: from [172.30.20.202] (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 1qh4dU-0000fV-FX for linux-f2fs-devel@lists.sourceforge.net; Fri, 15 Sep 2023 08:57:11 +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=55obZ+kvwCHjLjYM2qB+/d5MrTQT4QQR23koeSEhJPE=; b=CBXAvPOxnl0NvZEbixk3r4lATc k2ddAR5jvcMm7MwmCI56CHxuy5zfbYV5xi9RXFfdB8VwxxCOOhZvrxN5PVnoSQ5KHn4zekgV4GXcy Vj0Dat2tVvTa5ylOaSOMGIpLSGAvm9UHBWkCQEI8HxrMlp82woEHy7km5XTVef6+6SMo=; 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=55obZ+kvwCHjLjYM2qB+/d5MrTQT4QQR23koeSEhJPE=; b=BKxaJBGnZhc3m2+NbuwxLmnfst k9w6mKSXIrLNrekUmKJM/HIqOuv9bIVeAbvuVh6X8OA04kKcDStblVtzW0fFYkJJDe1fYQvCBAXIR 4F5T60SgmfstOF3y6UAtJHomKOG1HeqORoxLsDZ60aHSoirINQLscwehvIJ3s5D7EA6Q=; Received: from mail-tyzapc01on2109.outbound.protection.outlook.com ([40.107.117.109] helo=APC01-TYZ-obe.outbound.protection.outlook.com) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1qh4dS-0076BY-OJ for linux-f2fs-devel@lists.sourceforge.net; Fri, 15 Sep 2023 08:57:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DaZ20t4mQzqSW6P8auerXgofjVbgufBVaQvsYuQQM4nX4oFXjuuL/VT2WlL1pQSXDH2xVPbpzYelJYs2+pUeQbAQq3Ocxh2bvPsZpe2/G5Wf2HjVstjbm6Pz847Uz4vTFjt45gpeoaNJ2RFuyFFRRvYSgsU5pdV4HpEwqEdsSMMg4zjJnEt5t5Zvr8OlEn8w86Z0zXcAQ3Fnc5m5+tXi4+IE8496USZ4G5kBHpHaw8vW6UUlkp9HhhcBhPOUpd6tLoFTy4OSgikK9Z9HXV1pqgmi6yMtJJ4nu+6ypZqKXCGafzx7S4oN3unrPJETM8GpVqBUdGwZxvAL9Tg285FiTw== 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=55obZ+kvwCHjLjYM2qB+/d5MrTQT4QQR23koeSEhJPE=; b=mjVfdtL49zJJ+qcaKXbApJ+yieQs4n3ozuA4EDMmOfvCi6s9rW0Bg67cV/f6vgw4eIrUXv6GSFWJjfTHooXbRadqEDPa74Idr37TNF2+IyrbRBBCMAmdHOcELsVZEC6++nr0OUfEGC/nVRdOo7vvikDZD6zXNN70Vhtd1gP0OnOBqnRs7uKGCbPQF2mOr3cB+tFhX9qgkKj4fP1llwHtSL4nkPPRG26CqXS3oy8FM8qZsPHcJKUi5xaxnEnPxK2tEgUoAAYA9MZUHSLI5MFDCQyyOGvZihd+lzDrwj1YOV2fbztTm/nhqlyyLEUneecxEcgBEr3CCH8PQqSByD2lGQ== 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=55obZ+kvwCHjLjYM2qB+/d5MrTQT4QQR23koeSEhJPE=; b=CukVebCn+y2op6HzC8iP1nqME/tUvdjnCxwyBGyhpbH4gz6DxgIyyMygNLUxzGzlUgh8xOc8wUCrdXsoKmPJnAgZgto3vyqfg5p4ulJ9ayJYL2m22kknPRDtx8hQU0L8A3ZrZmiw6hUvK5vFosHJg7mvo3HvXfkEBbE53N3ylfUAkqHHwSrr4xA7dkGv0TV8BOn4/D68d071g7cCzK+Yj7hggOQLkA2VD3AUh1QO3CBB4iWVwuXPseVB6fDxAeZf8Eb7ta5AQLWwuYMnUzRvcaXHeEqj/o/apZjtq7TaMb9JDhAZwDh4HqoFEvOw3tYCwp4NL7GdrubIM8JwQI6OAw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from SL2PR06MB3017.apcprd06.prod.outlook.com (2603:1096:100:3a::16) by TYSPR06MB6693.apcprd06.prod.outlook.com (2603:1096:400:478::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.20; Fri, 15 Sep 2023 08:57:05 +0000 Received: from SL2PR06MB3017.apcprd06.prod.outlook.com ([fe80::deb4:b884:ed42:e52e]) by SL2PR06MB3017.apcprd06.prod.outlook.com ([fe80::deb4:b884:ed42:e52e%4]) with mapi id 15.20.6792.020; Fri, 15 Sep 2023 08:57:05 +0000 To: Jaegeuk Kim , Chao Yu Date: Fri, 15 Sep 2023 03:04:45 -0600 Message-Id: <3d8d905f27aafb2a8f376eda423b406720cea310.1694768423.git.bo.wu@vivo.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: X-ClientProxiedBy: SG2P153CA0037.APCP153.PROD.OUTLOOK.COM (2603:1096:4:c6::6) To SL2PR06MB3017.apcprd06.prod.outlook.com (2603:1096:100:3a::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SL2PR06MB3017:EE_|TYSPR06MB6693:EE_ X-MS-Office365-Filtering-Correlation-Id: 8b1321f8-1b5b-4f8e-d113-08dbb5c9bbdc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5Kc6B+aFtH1mvHp+Jmoft1V3T7Kk4vFFpkVmKEQseKiNJ+at3qr8UncZfWNOpo+ljjYhV1ESO7Tj8RYykcw9DMNHCh8j5f+UnVfKLj0co7jYXAAlQGA+FCFJQiIKR9peofisynNnevdyiKj0gOiRLPU36ITR3TNLN5/6yIDGgefxt6C9aTVmJjk5N1u3HmzT51p2p2watu92WOfcgUEGWPe5ZFYis8ZyNT6LnwhYMNp8AKN8gQ22fUyF77OTGnJ8t0dlwrNhUMmkrWyN6q0GX0QdGpM+quouZwhxKC4yUbhlRWYrmwS8JCub2IkLMGagy57A4U3gbS0DXtC1ZOnRAyWHDIuXvNmfAO5kpGpLYzKXL7NncPM9Xgv/7h4yCnq+RnheiESdfR6jXKe5ENvZ5tl0WIDHpyxsyV/HTSo5GXCGIhzzXfn2uJq+q7hi9s3hs2qe5d70IrJiksoZ3v/vgDFRvQXh3ylj9xvDgq9RPh6LCj0UGURBO8XaMoXHGiXk1nlkRS/LEpLznnPG53I5Vk/klLvvuAzBfnzTNWmySpBeGVhSB/+Qc8Q9SH8LsR1yIWcW4m5/5fI3Ri7Tppu6l0q+8cXCZi530sEPU3fkplqzG6m1SjIkkAgROSmDi0vA X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SL2PR06MB3017.apcprd06.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(366004)(396003)(346002)(376002)(136003)(39860400002)(451199024)(1800799009)(186009)(86362001)(83380400001)(6512007)(2906002)(2616005)(26005)(107886003)(6666004)(6506007)(6486002)(52116002)(478600001)(38350700002)(54906003)(66556008)(66476007)(66946007)(316002)(36756003)(38100700002)(5660300002)(41300700001)(110136005)(8936002)(4326008)(8676002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: WKJch64WlVynJWy1EKOwMnYxu+OYdDrI/npGBSosqEC5wH88Kg8j9xId4Q+GRlJC8Rl+16x6aXQR0Eakiwe4XZmDjbasuCRVMitsclHQwjTIXtJ9jGxbjI2rzzqICTHQ1mIR5qBciYz/RPfyqT82ma8j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JedvlL1IeTs7eaKgAwTnLEJlVyALjGzUbm+wVcy1Zp2GtjJrQ6U0rnkt1XeIScRxg77Uon5j5GRnTOr7dbGSwmncxE8Dhj9fnyfiIJtCA48A0Cme1zeyiH5w8JukDFkdTBWolMEW+L+VWWSLSddN9Zc5PjbaWBv2XOLA6UJAHL8zqHIKzzYQYmhM0ySMFHJKICHrFUojhQ3tXKIRuM1kxG/sAzso5eR71lqR/JUmC/dtG32Zx5q4iUUodBtwW2uomPBcIfshFMhDIn/F0X72Z91NyiCdj4u94v4fryZ786xnxsGrdKVc03qIiSIGniKWQ49jUUs3L2GOlIe6oV3likZ+c3WH320JDCvtGkHP1vVhlYv/3Fql X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8b1321f8-1b5b-4f8e-d113-08dbb5c9bbdc X-MS-Exchange-CrossTenant-AuthSource: SL2PR06MB3017.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2023 08:57:05.0032 (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: Q13QSXcG8dsQffS1qOUGgVc1skds0lLihUAcowqTaVdVMYZjwoKtBJar/PrHZDeld9PBSeCbqYzEiCq8MAkVEA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYSPR06MB6693 X-Headers-End: 1qh4dS-0076BY-OJ Subject: [f2fs-dev] [PATCH 3/3] f2fs-tools: cache free segments count to improve perfmance 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: Wu Bo via Linux-f2fs-devel From: Wu Bo Reply-To: Wu Bo Cc: Wu Bo , Wu Bo , linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net 'get_free_segments()' is implemented by traversing all segments to calculate the total free segments. It cosume much time. Every time when call 'find_next_free_block()' this calculation will do it again. So if we cache the free segments count, it will greatly improve performance of dfrag & resize & sload. --- fsck/f2fs.h | 1 + fsck/mount.c | 9 +++++++-- fsck/segment.c | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/fsck/f2fs.h b/fsck/f2fs.h index e65644e..a7cdc4c 100644 --- a/fsck/f2fs.h +++ b/fsck/f2fs.h @@ -197,6 +197,7 @@ struct f2fs_sm_info { unsigned int main_segments; unsigned int reserved_segments; unsigned int ovp_segments; + unsigned int free_segments; }; struct f2fs_dentry_ptr { diff --git a/fsck/mount.c b/fsck/mount.c index dccaae2..b965c5d 100644 --- a/fsck/mount.c +++ b/fsck/mount.c @@ -123,7 +123,7 @@ void update_free_segments(struct f2fs_sb_info *sbi) if (c.dbg_lv) return; - MSG(0, "\r [ %c ] Free segments: 0x%x", progress[i % 5], get_free_segments(sbi)); + MSG(0, "\r [ %c ] Free segments: 0x%x", progress[i % 5], SM_I(sbi)->free_segments); fflush(stdout); i++; } @@ -2430,6 +2430,10 @@ static int build_sit_entries(struct f2fs_sb_info *sbi) check_block_count(sbi, segno, &sit); seg_info_from_raw_sit(sbi, se, &sit); + if (se->valid_blocks == 0x0 && + is_usable_seg(sbi, segno) && + !IS_CUR_SEGNO(sbi, segno)) + SM_I(sbi)->free_segments++; } start_blk += readed; } while (start_blk < sit_blk_cnt); @@ -2485,6 +2489,7 @@ static int early_build_segment_manager(struct f2fs_sb_info *sbi) sm_info->ovp_segments = get_cp(overprov_segment_count); sm_info->main_segments = get_sb(segment_count_main); sm_info->ssa_blkaddr = get_sb(ssa_blkaddr); + sm_info->free_segments = 0; if (build_sit_info(sbi) || build_curseg(sbi)) { free(sm_info); @@ -2805,7 +2810,7 @@ int find_next_free_block(struct f2fs_sb_info *sbi, u64 *to, int left, if (*to > 0) *to -= left; - if (get_free_segments(sbi) <= SM_I(sbi)->reserved_segments + 1) + if (SM_I(sbi)->free_segments <= SM_I(sbi)->reserved_segments + 1) not_enough = 1; while (*to >= SM_I(sbi)->main_blkaddr && *to < end_blkaddr) { diff --git a/fsck/segment.c b/fsck/segment.c index 0307bdd..1cb7d02 100644 --- a/fsck/segment.c +++ b/fsck/segment.c @@ -77,6 +77,8 @@ int reserve_new_block(struct f2fs_sb_info *sbi, block_t *to, se = get_seg_entry(sbi, GET_SEGNO(sbi, blkaddr)); offset = OFFSET_IN_SEG(sbi, blkaddr); se->type = type; + if (se->valid_blocks == 0) + SM_I(sbi)->free_segments--; se->valid_blocks++; f2fs_set_bit(offset, (char *)se->cur_valid_map); if (need_fsync_data_record(sbi)) {