From patchwork Wed Dec 11 06:55:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: LongPing Wei X-Patchwork-Id: 13903007 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 C474AE7717D for ; Wed, 11 Dec 2024 06:56:23 +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 1tLGdw-0007lZ-9D; Wed, 11 Dec 2024 06:56:20 +0000 Received: from [172.30.29.66] (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 1tLGdv-0007lT-7W for linux-f2fs-devel@lists.sourceforge.net; Wed, 11 Dec 2024 06:56:19 +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=eTzc+BhgztoIRxIGzEGWscEb3wgJRVSlxKB342b/E1A=; b=If2eCHcZE1UlOGOYp4SiQ7RoFh mO7GlOAg84UGQ54i/V4uRp8GWLdkjxoj2cnHAL/AZrg5O/gnrYD40MzsqXo01hnHHagifH97Uf5Vk EU80EYtVTASPE1EbDgK1d1mEkDpd5VgSScon2gGztpQBnY9Hfb+ATKcxH2g95bAP4YOY=; 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=eTzc+BhgztoIRxIGzEGWscEb3wgJRVSlxKB342b/E1A=; b=U hUvh+wrv+In0942ikGiT358hP9xamakn64n4++kG3BrmBTVVB75MA32T3Uhlwk3XARS+/jb8dU7IO Xrp0sWY6XxH6wID1w102I5KQy0uiUfikajX8Xozwyu05Usk22koegNZhqihc4U2HZn4KKADpgVAVT gfAoGvitZwaPj8AQ=; Received: from mail-koreacentralazon11013043.outbound.protection.outlook.com ([40.107.44.43] helo=SEYPR02CU001.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 1tLGdu-0005fl-95 for linux-f2fs-devel@lists.sourceforge.net; Wed, 11 Dec 2024 06:56:19 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=D4zTr55VhTX6ATpvcx+L2PH1DVAvJAjkqNnfVP09jhY9dOmz0VXc7za1irfwEtHSSoLHhmo5xuz4U2qQLkieD2DanZUacSWjO9NUhSVPsElSwNcn7NTmqe4ZH7SIdkXiGN/oo+EqUOysfZgJlPMA2+IYUdjXxoOOFNCwtNw6sGvfPAwgHIiunxIucmtUqpeqC1X4Za8pWzO3hP0FAmLyryixMpRZub9XOnppoL9of/pl4SmrJjq0lO7l0GjyUUtoBrTe+axZ0e67lTWv44DlyRqB5IPJtLKz0+blXI3WTWbdPOWovvohdzazxSEhcNeR1OvDOZ5jLTTwZlgc+cab3w== 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=eTzc+BhgztoIRxIGzEGWscEb3wgJRVSlxKB342b/E1A=; b=s0f1PfhlsCsvvN/eL7ItLgG8Ost2/ud0Qxc5uv8jgNzupKWmIt3mL5Osa33L5hPPsrYbWfzyeBcoOOACU7V5+aEjcf0HOSPKRqCeZGbF5Q7MMajFzltF8O2wuG9THXmPYgmzci+ZiyneXET6OzWG7ktNdn4gebFbsB/jGUniTQ9blbtluJGp33DtKNQCJfcb3YUPC9LK9KBxwJddP3iSV6/VO2jo9gABP/+UpOjoTMDAzKTBsgAsgGj6QVJXJArc/+bXsJAhXspLan9/1MBK8Vbjyh8sYL4/yNns4+W6v1G91M5vm0n4nSSXuL1rmXoohsFhEmo0uSzZQKaVQ/SX0w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oppo.com; dmarc=pass action=none header.from=oppo.com; dkim=pass header.d=oppo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oppo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=eTzc+BhgztoIRxIGzEGWscEb3wgJRVSlxKB342b/E1A=; b=frEArJy7nvvLhKLzaKEluGH9L68bH+dmc/MDN/3zOqjnKmdRdFR6TQUkV5okYV7iEIVIWWJqK6qa0RCvlRd/0AWLPv65uKdJ8pekJT4MLa9GLZLDByZOGyuz4EJeyW+SrwvmSER/b26be/oNrtNPtjSkZs3KaDIAEKPp15DEyBU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oppo.com; Received: from SEZPR02MB7967.apcprd02.prod.outlook.com (2603:1096:101:22a::14) by JH0PR02MB6903.apcprd02.prod.outlook.com (2603:1096:990:43::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.20; Wed, 11 Dec 2024 06:56:03 +0000 Received: from SEZPR02MB7967.apcprd02.prod.outlook.com ([fe80::5723:5b88:ed4c:d49b]) by SEZPR02MB7967.apcprd02.prod.outlook.com ([fe80::5723:5b88:ed4c:d49b%3]) with mapi id 15.20.8230.016; Wed, 11 Dec 2024 06:56:03 +0000 To: jaegeuk@kernel.org, chao@kernel.org Date: Wed, 11 Dec 2024 14:55:45 +0800 Message-Id: <20241211065545.4128914-1-weilongping@oppo.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SI2PR04CA0005.apcprd04.prod.outlook.com (2603:1096:4:197::16) To SEZPR02MB7967.apcprd02.prod.outlook.com (2603:1096:101:22a::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEZPR02MB7967:EE_|JH0PR02MB6903:EE_ X-MS-Office365-Filtering-Correlation-Id: 63f483e2-8ecd-4264-ec6e-08dd19b0e098 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|366016|52116014|376014|38350700014; X-Microsoft-Antispam-Message-Info: 2ASWY+m15Qdrve8o3in9fAA4J77GiPTQkKO80t9xn0kLaqtVz+ic0Cpfc2LwhT1YiYu+dgCZrNnaxEMGhSTutIlqQlRLmteNMV7ne+EL899z/HlSkpTq3oEmZfrvb2u8SozZUix8O3HWb7ob6GAQx9Vq35EuGznQKIRWA5cYyT2ZFXByLtcLEqyRy6Fvybp3gAjCrxWZtEvlbmcQsacoRtjP9oHvfupzngK3jTsdtenispwl5MkvUJHW71yu/VzLIqB/hA8ZnAIYytqfnDobNIDXmgcfKXLlSqyYgGL98gMqxXNvkNvMdmDODfEQw6C0MGvr1ziTKlF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LuCJncWkOQ35NUSrUKlZCSzkA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SEZPR02MB7967.apcprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(366016)(52116014)(376014)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: JD6slEBWjJuAx1AjbA1a9CtiavioSLr7cyoThavUo0sEoiH6eNUKIn2EHikwWBvYWvNrt3kyp5CX9NfcfJ+fANH1a+EzqhKFFt8pxNqEo016h/z2wC2vHPqrzVRucKYIzgWjVyXGCqFhzTNCxrjt0UNgJSA3oI0QnXBEa1ShRdADshAzaP/NKrGj82M9oHhKNFfsbVOB8Ps87Z5fMMz0+BlAGDGkIELVYqPMO2dVkn5lR6LTOaDjZYY//pRW43qkQSj309w81wnNVfet7JB6t4BKAN8LkVkF0Hjl6yDV0BuzadThPT44RrEiacEUGTnC30FLSPpm7PxBhZ1zGxp+aEm6yLwlidWua4SqBbjy+lvMfEdcLCYN/eLBudDXgQMzsd7mx4erwqyDEPPQrwBWHRVtZJrAQ/ZoLHFzIWr7oteiSuc4SnuiYBfn08OrhxHE1SqWOxFheoyWFJnvjoBEUvu2G5CZAp7vOUB7Kx9dWFRFWWsrZyPJr9UnY1piWW6/IC8mrm8YRyIKHm4EOwe1Y9Puovbm0EBITK8/TrUjJRFJDhpdfPje/hSBgVCpveVLecueXrQjy3QQKih7KJAEsX7uaTDmg8dr8EfLhaN2mDmLfQiq0uVKSp0UkbmTIBhV0f+rvkifVQ2o3wMpldZsX07NOvcgwzlTc0VFNmg9O16PwiDC+0MYeuN2az8rdzpjF9aIRFO7gORwRly/5oOwl0TmSbqth07gFlZcjbOj2OXXRBsDWfC7A8lwv+S2nd+lf2nFeqGvy5tMuN0a/Yl0xMyH4afXU/J+RJrN7bXoPh3WXmwoBg8vnkM2PAEiBvNN9NYtugyod8KoZTqcCbB4KVLIvSJeJVp3sQ1rFqorL88+DIKmk/y9mNMiFnDxm5+6dMSxcWeo/tt4lzowGYYxBllcrrU6pCKJ6CmkngI52KCYy9azVOmiKKfjdxytkaZGmDt3WD2pnktgwpUnDDq7NYsrspLW9b+JpXNPEZMLgZKgIdjYxJFufhG5m6ZDRHUS0oeOdZ978Br0TGZXHP+f46GM8TSP5L9vV9a+9w9qQYaFB3PrUB9G189edScPv5MsI9ZS1kK8BZhbQwMW4qsciMvZ0lZ8EzIBwLymEr5FQr74fMyfKxoVg0uVOfwDewsPvorVoUp+L4D4MSJds8GsYmNysAZ+P4Lr20wFNCppIqslW98zojpS5ErZDoGwZANk1q6js8JniNEBuH74YtVK2nFIdHSKaW0dGAoYrl/1ht1Na2fK0E3J//RBHmMH2dIpPZystoQnfCob9NQD9hAHtXhtAa6KRBXUkSVXR7EXf6x9KZpzEDU7pkJkSSTzEpu3XvEdMFB3m8OdzphYDAjRK7tKCfByL7nki/FEAwgCYN5t8EBXDetBGCrrnsjE00SLFSdiGbZQB0KyvPjigEWZybsABD+v3/TPUa6qY+ubJf3A9TPItUuFo+b67wO5VbGfMUb78+lqk9/qiYQd8mCF2dsQaHfCUy0i1WBn1OhL+NFWE49DEZUfLU21ltklJ4uYP1fWov/tIstfzbfiz1SWfMWdYJVZZTgRQIqASmMlL++1iz7MkUybq03FuMlHhwObG8hmWrPt6UPChFimhkHVFg== X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 63f483e2-8ecd-4264-ec6e-08dd19b0e098 X-MS-Exchange-CrossTenant-AuthSource: SEZPR02MB7967.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2024 06:56:03.1827 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f1905eb1-c353-41c5-9516-62b4a54b5ee6 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: HrFDtwGt+05G+9IoncuIPHGthUNQpJhrfIYQgdJ3i++Ca05t4rfsrM4DBYlp4YZGJzw8sQpfI0McW18C/BDT/Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: JH0PR02MB6903 X-Headers-End: 1tLGdu-0005fl-95 Subject: [f2fs-dev] [PATCH] f2fs-tools: avoid meaningless repetition in migrate_block 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: LongPing Wei via Linux-f2fs-devel From: LongPing Wei Reply-To: LongPing Wei Cc: LongPing Wei , linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net 1. Use the same buffer in the same call cycle of f2fs_defragment; 2. Pass se and offset as arguments to the migrate_block; Signed-off-by: LongPing Wei --- fsck/defrag.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/fsck/defrag.c b/fsck/defrag.c index 9889b70..7336f8f 100644 --- a/fsck/defrag.c +++ b/fsck/defrag.c @@ -9,28 +9,21 @@ */ #include "fsck.h" -static int migrate_block(struct f2fs_sb_info *sbi, u64 from, u64 to) +static int migrate_block(struct f2fs_sb_info *sbi, u64 from, u64 to, + void *raw, struct seg_entry *se, u64 offset) { - void *raw = calloc(F2FS_BLKSIZE, 1); - struct seg_entry *se; struct f2fs_summary sum; - u64 offset; int ret, type; - ASSERT(raw != NULL); - /* read from */ ret = dev_read_block(raw, from); ASSERT(ret >= 0); - /* get segment type */ - se = get_seg_entry(sbi, GET_SEGNO(sbi, from)); /* write to */ ret = dev_write_block(raw, to, f2fs_io_type_to_rw_hint(se->type)); ASSERT(ret >= 0); /* update sit bitmap & valid_blocks && se->type */ - offset = OFFSET_IN_SEG(sbi, from); type = se->type; se->valid_blocks--; f2fs_clear_bit(offset, (char *)se->cur_valid_map); @@ -57,7 +50,6 @@ static int migrate_block(struct f2fs_sb_info *sbi, u64 from, u64 to) DBG(1, "Migrate %s block %"PRIx64" -> %"PRIx64"\n", IS_DATASEG(type) ? "data" : "node", from, to); - free(raw); return 0; } @@ -65,6 +57,9 @@ int f2fs_defragment(struct f2fs_sb_info *sbi, u64 from, u64 len, u64 to, int lef { struct seg_entry *se; u64 idx, offset; + void *raw = calloc(F2FS_BLKSIZE, 1); + + ASSERT(raw != NULL); /* flush NAT/SIT journal entries */ flush_journal_entries(sbi); @@ -83,7 +78,7 @@ int f2fs_defragment(struct f2fs_sb_info *sbi, u64 from, u64 len, u64 to, int lef return -1; } - if (migrate_block(sbi, idx, target)) { + if (migrate_block(sbi, idx, target, raw, se, offset)) { ASSERT_MSG("Found inconsistency: please run FSCK"); return -1; } @@ -99,5 +94,6 @@ int f2fs_defragment(struct f2fs_sb_info *sbi, u64 from, u64 len, u64 to, int lef write_checkpoint(sbi); + free(raw); return 0; }