From patchwork Thu Sep 28 09:20:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wu Bo X-Patchwork-Id: 13402355 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 9CE8ACE7B0F for ; Thu, 28 Sep 2023 09:13:31 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1qln5Q-0006Cs-LF; Thu, 28 Sep 2023 09:13:31 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1qln5P-0006Cl-EW for linux-f2fs-devel@lists.sourceforge.net; Thu, 28 Sep 2023 09:13:30 +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=p3qYDJ0CPf3IYOOvsJ+LMmfAce2ZiCcVF2trmbUYWYo=; b=G/KLhXsqytFhAYrb46eOC/aLsV 9rPWkZazGlDXrcmFMvuWIv8QusOqXy1JOL/kNE50PDiGZS0NM7RZ+lOdCkL1UJoZ9AWFEa7IO3nCn IozKRFKOsjCt0It5XC0ldCSSSegHhAqFLUNtsIBfwArn+ShtZHZS+z0Mo8vKseKqXkWg=; 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=p3qYDJ0CPf3IYOOvsJ+LMmfAce2ZiCcVF2trmbUYWYo=; b=OTY+xnz6EoXPeiWI1sNAOcZEHQ n6nAxk0vlDMMFex6uTZtMY/499hJhKr4BfFLpJCpEVsMgmjeXC4HdB4pg6nYOFD5apYJ9yc9Mp1US ItbRQtCHvSHvO8j1dxi7qA+Lak7GFQsQvocF+6vhNor7cl3xyYteNReGUoXI/BdodCHg=; Received: from mail-psaapc01on2099.outbound.protection.outlook.com ([40.107.255.99] 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 1qln5M-00050A-K9 for linux-f2fs-devel@lists.sourceforge.net; Thu, 28 Sep 2023 09:13:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DQtH6iCzXYRKO0nEuahrjw76Czw8U1cfO3/eNMQ3zwUflGjcY2ufuDl0qZC9zY8KvsjlPWc+pqIoYaoS2L+dDRtkEiRrGt1Ars9mbxbbWpFMoC5qYmH5wne6fTMsnHu7KVbKbHSfKtpj1ttxVmTaOyKE5OM3tCAsvuT+LvtprSBBJ/7/iYDU7B1jqw4fi5cTbjyY9qVZkv8UFS0OL19Es1YyD/8GoyZz6IFazoYxbyl+ldJlyQpND4bpQ94Ddlsh//VcLgWrS1MCTNVDbW14Haz/Sx1cTKZ3/Vy8+1e2AoMNBNWdrRC204RTRFODJsvzus0MwFRut7+kxpM/r7DqPA== 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=p3qYDJ0CPf3IYOOvsJ+LMmfAce2ZiCcVF2trmbUYWYo=; b=l5GbEVGXGL5M9jbTUld0T0MHvSYJprUYX9bmS8n0jbP+B0a6mXmcUgVs5nSRThPrYxebgL4CSgg9xR+S/c1C9k960bwV1Uu83V3jC8shMQDY0zesvgEGes8ifCMia1DE1qa8j0GAJCgxDMsXG9Ncu+RPmV1gZQ57zMSafqwNZbc31duUngzhX06IrsMXhcT4KM5DCHsOmmbxwhNOk5aEbSAKTsv82lYr+7PxBq2dnZPHJnhWoAJkBCZhTyExBzUFU/CNdYod9QOlJ7T/4ZdSg3d9Ji3JrSUrUKMjYitcszkK9WLYSD7cAuHXVnFmYHV1AMAQVRBxsRjFypMMto1W5w== 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=p3qYDJ0CPf3IYOOvsJ+LMmfAce2ZiCcVF2trmbUYWYo=; b=nY0TCQqKwfdJj5nQOvtVMgOoA3CNvPxVjwmhcBTyvK5dT8uvrn6h7tC91SytYnq7gMT7hixi7t+ohB4YGJfZYCF4kUmyXgt7YZkcxgK8zOStIvOx5ZZV9psuERoNkwFBSFTcun8t0wBwxZdT+fkVT9/uu/uV+0vaneLyJq5zPVQyy9Q08k65r4iO1ZuYV1Gtgpp82dqs7t/+/ukENBqT4fXVg1/fLgqJ+hY6SYhxP75Xj4B6QAd22jffWOiTv3INCM5SIwiBeXuZEbEZynfMjNNqRtXxmoJANu69tnsMKpARDqv3kthssOrP0fGu7+i42jSZoiLC7ZAGnC3+I5nJ3w== 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 SEYPR06MB5867.apcprd06.prod.outlook.com (2603:1096:101:d0::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.28; Thu, 28 Sep 2023 09:13:19 +0000 Received: from SL2PR06MB3017.apcprd06.prod.outlook.com ([fe80::e1e6:c2aa:6b5b:bc1c]) by SL2PR06MB3017.apcprd06.prod.outlook.com ([fe80::e1e6:c2aa:6b5b:bc1c%6]) with mapi id 15.20.6813.027; Thu, 28 Sep 2023 09:13:19 +0000 To: Jaegeuk Kim , Chao Yu Date: Thu, 28 Sep 2023 03:20:51 -0600 Message-Id: <188b05d1764d1ba48f9c704ff28df853f3094f67.1695890686.git.bo.wu@vivo.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: X-ClientProxiedBy: SG3P274CA0020.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:be::32) To SL2PR06MB3017.apcprd06.prod.outlook.com (2603:1096:100:3a::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SL2PR06MB3017:EE_|SEYPR06MB5867:EE_ X-MS-Office365-Filtering-Correlation-Id: ef1e40fa-4ed1-4d8c-516d-08dbc0032853 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IjpqzL790SUgxGnobOdklGbcM5FvItWPbPCbYzqoKzgX09/Ng0F8ws4356NrtSSUBJDIR6ugM0Cd+agFukcXHHGkZF5Zhk7q08UBjL3/y1aeECROd4Q1dtd6OhTFsgyot9YCCXkTpjoC5fjBWFfGwyT9orEI+4xeDAiiZP0wrQgho/Gv9fxUxBo5IIj/zbIkIIphhN3B2458TuqV81Dtkotbtddspu0gIQLF4mYPvVpX6cwGlS9v4/y5EblaC+NZSxPJax9cRe4MmmBRghPj4JSQsK+9rIGXYWZzULm2we8KkXrAU5i1Y1Qw5CbZHpm9lse0oM7RU10YcgF64e78Levwt/G1J1A0fRy0y0ALGZ8M1Dm+vixKxfNt9OQofvLRpFQfQMfxEsl3dJBlOQKTzk+Yua4SS2usPdDBnoidHzJVUR4Vdh0Q44eeyHbHn1jCwtqta5SVmeTi9WSGFOdbPYZs7svokmejbPZdlbYZbNVYk75iSKEsu7GqaHzgX/wcWuYaQeVwlRODzYDGV3vw8gQKOjkxGrxPigPGlgixu6SKpc5/8lCCYaDDtI0H1nPKOYAvBKHhadKGXgVrTnasOKZkcMAKeKopxaRAHIyzvRyCVW9EP1mefzd9P7MS9zqn 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)(396003)(136003)(39860400002)(346002)(366004)(376002)(230922051799003)(64100799003)(1800799009)(186009)(451199024)(2616005)(2906002)(6506007)(52116002)(38350700002)(38100700002)(86362001)(6486002)(110136005)(6512007)(54906003)(83380400001)(26005)(478600001)(316002)(4326008)(107886003)(5660300002)(66556008)(66476007)(36756003)(8676002)(8936002)(41300700001)(6666004)(66946007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hWCnAU7NzJfIng46OdW4vVju+1batKJ0lvlWQulsZVNCiuc23w/hKuKa+R1AI6UgjOwk438KprF0V1sevrIMTKrcgjygRxtuShcXByYkmnN2k7XSy9tuwT4mE5xm6xV9zih+4z6SYzR6Xi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2WyCzv9p+tdQajEIVoqZkMEnYAzytcr/f7VQXhdMh1JhXaTOw+IoFhs9GEd90wlkYNg75Sc/fccY656QpaxTx7DmJVo61/unC5oYASIOiMPEC4VIAAvtNamWQAWZLqMe0wl6pbuC5PE4CoQJ9a4t+fatOvk6m1RZ1LhzsMkI0/0GQHXyfAtD3DsQvTT+PNA+Uv/JIclp0ivZwoL31MtPODzojG0Doo5Kxjebeu05A115b1yJ885lYU1advDnHxqSzWSyAY3gr2PXP72mjWgwl4qU73315RgQjcgXH25AXWlhIlNvVGTqIUT0fCdgw2eTxXHFzaJrYbqc9A9nxidQHFLASJLQ6c8lTiwcEcCsbf/iaaMTZveZv X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: ef1e40fa-4ed1-4d8c-516d-08dbc0032853 X-MS-Exchange-CrossTenant-AuthSource: SL2PR06MB3017.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Sep 2023 09:13:19.8543 (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: y6ZhYeVakilDcM58w4JyeEp8GLFss7k2XI1fIwqYQ9kEwkhy+alS4WFnTRWpMMcOcmzTGluY4ut21ECO6CUfEg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEYPR06MB5867 X-Headers-End: 1qln5M-00050A-K9 Subject: [f2fs-dev] [PATCH v2 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 098e73d..0a37bc4 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); @@ -2806,7 +2811,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)) {