From patchwork Mon Jun 26 10:07:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lu Hongfei X-Patchwork-Id: 13292596 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5BAF3EB64D7 for ; Mon, 26 Jun 2023 10:07:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229879AbjFZKHd (ORCPT ); Mon, 26 Jun 2023 06:07:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229501AbjFZKHa (ORCPT ); Mon, 26 Jun 2023 06:07:30 -0400 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2090.outbound.protection.outlook.com [40.107.117.90]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED04811C; Mon, 26 Jun 2023 03:07:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j15m1ALPUOeTzIw3KSRTGYge6X6jwEOvspvpAXvweOBfpm86TLpm2mbmGP959BfP7mUMEuKXdi7m3Ene/XXB1B92PU6xjopmTEQQiZxuI1D8Vjkg3GBGyiv/MRs0Wo1Gas7GY2PxPksX7M9B/We5W+B1zsHv2Xg2JqmfdX3vavdX0pk6Fno9wT4cLngUvRbdP4HgVWTlPSRWSzswNfJcEyByWoud7LAbgR/mYC14IwcOuo27/wF4sVZUsE+abML+xvP2PBRXJLlwGEvwqI55el418XgXupF9PjNa6c8NGPHk5bAA2DQj3tSouwO+5ty32b+DI6wQarnfmJCtTBZI+Q== 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=lqmnioJ3vzotlIxAdjHlpXNRzAHZFf9ikm1RY9ddu+c=; b=Md2IUVA0dgzYz3YVsOH9idxkFvKBwpOqMZXB9rVjSzjrDfRBBNcWiM8kzPn636/biCp7QwU6pdQqHv5BmYYe9ru4Z1jVU29gPIeOdcwmZYIyNcvry2GTdzyAhs9EFyap5EJjeROrWHvDNHmKsMztCimxOQE/OJIzn22dPve0bF3oYH5KOAjk4rcaX/JhrhWhshK83KrjUawWs0weX0zFLxPU+uk3+KWf3fmcrGZD9wJ3dRs8VN8uI3njGZB8ArwDVBNMuMjjFp+NBFUWO16GYvQHXXK4607nIaQSno/QCIxVRsAwbWYXk+SBlhmJ1Z7lvRFPkv1gId7VoNasH3m5sw== 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=lqmnioJ3vzotlIxAdjHlpXNRzAHZFf9ikm1RY9ddu+c=; b=HEFZO+7KFAnraZ+30va0siIX/dgedMOhkUUuwmCc/wwiLJfBaBArZd2ptLGwsm87liucMH5A+6mF5wBtDRYky5a3JecB8A61Xwrv7MsCed6hx1OFGcDUn4jTpQ7Gax3E9fV4bnmSWYEOyJe2hCMZWsAUo9vmzAIu3ArjNVqUbCC2FjmcLncZA2OwbiRjHLGAIE9Bg16+LpKgdMt4Alyfw9Uv5lm39OePozV7x5ri4m681Rt2VP4QZfprLxkhcGh36ci9CbfPQnlEg1glS3/KiscmIOZGyBNvjGLkcjqOSAC39qbmZXRBwG8dwI0/e08IjbxMt6/paRkHXtka/14kNQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from TYZPR06MB6697.apcprd06.prod.outlook.com (2603:1096:400:451::6) by TY0PR06MB5755.apcprd06.prod.outlook.com (2603:1096:400:27d::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.23; Mon, 26 Jun 2023 10:07:26 +0000 Received: from TYZPR06MB6697.apcprd06.prod.outlook.com ([fe80::f652:a96b:482:409e]) by TYZPR06MB6697.apcprd06.prod.outlook.com ([fe80::f652:a96b:482:409e%6]) with mapi id 15.20.6521.023; Mon, 26 Jun 2023 10:07:26 +0000 From: Lu Hongfei To: Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: opensource.kernel@vivo.com, luhongfei@vivo.com Subject: [PATCH] fs: btrfs: Optimize code execution process to save time Date: Mon, 26 Jun 2023 18:07:16 +0800 Message-Id: <20230626100716.18935-1-luhongfei@vivo.com> X-Mailer: git-send-email 2.39.0 X-ClientProxiedBy: TYCP286CA0046.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:2b5::6) To TYZPR06MB6697.apcprd06.prod.outlook.com (2603:1096:400:451::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYZPR06MB6697:EE_|TY0PR06MB5755:EE_ X-MS-Office365-Filtering-Correlation-Id: 1624f149-b1c4-4d59-204b-08db762d2454 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Jhq01hPmk4Wim8qPwv5JTzaNnjybcGP7ttH7EiJUkqmE/D5DXOmV/klCAnxDfyXZh/V4QrYVSpaKTV/UvW0ZY3Xm5wzPjaQgrPlxIK8aD1jrcZWz5K+MN/Y8kkGM+cALnIIZ/L8jaDXaOwCPq83b6Wv6f4O2ijWm8S7Kpn4dpcTDXSrBO9y69dscFLiwUPP2NiAkWxUhnEsee5XhW28UZnmkjykzeLoeOtMFaSXMd1Y0aKeHgjhdJGSBtPKtduD48AOyQJf/n73GnujG5MvSSqOtgEKEavQNFdcdHPgHPdszCbHT+tkyc75JcVsI/MHRErZVHozMgEo9JGZeMsFX+g6GREvB36Wdax3Djv04UtGNYhNF3StqX2zPqF5hBPEOUEWi2TGIDQaUh9OenNNQeuVgNhDYyy/hlPh1l2MJItJxvgi4qT0TqDPYSzxBk9BUDuyq6SdoQYZD9bIHfb/CHKeNfpH3T5h23c1ed30aPIX233PfsJGO+4hdCsz9jR8aOU4ut4qDJoqdHI03z66L+IVfKfhIztfWFecAGWS4JqJMgF7M5GAqGnH3waAwiafaXc6Am811UAWUAlz+gxHphFcdWLHdhnyT9yOvsRrrMrQICBVJJ/2FscCpgSM3jbWj X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:TYZPR06MB6697.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(136003)(366004)(39860400002)(346002)(396003)(376002)(451199021)(6506007)(6512007)(66556008)(2616005)(66476007)(8676002)(1076003)(8936002)(186003)(5660300002)(26005)(107886003)(4744005)(2906002)(38350700002)(4326008)(41300700001)(6666004)(83380400001)(66946007)(36756003)(38100700002)(110136005)(478600001)(52116002)(316002)(6486002)(86362001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Cdb+iNZNV/3GXx/DCchui25yVXuDi50qVyQulEO2kysAg+zSyIzAMapoCTrzhWVNyp4ETy+JChUxI7/t476rHVlteEDWFHK2HjHpO0+Zr0U+LWNchB94shQFe5dJwOQOJvoVbS/zwNE9Al20wvDWAQEnQ7NUIRiFUDHokwMuOQGThFODH4WNTu3SODwOBdXgKDpytS1ELcZsn2Wf/781vAU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bVv6ApYXVWrfhW2qmN3oEctKD9YnlbDDNjDxuoUmftgqPO0LTipNdLSt0mUxus7KaTBS3uuXWrCydz+QFAqZwkEVxl9wJ0gFe5D1+IaTowWP+vHr2cX5hZb3bP3egZH9kWoqquKFUs+kpyJPHhGw1Z7LvuV5VMdE+s7KURpjGcjzTadDBkNXIfvP+frwEFRwOL4ESlCXsPYv518jWae/mklPMksjuVEbRyL+00/Jk6YaSZYl9kk5UrrfVXw8tzIssFCBvfdmTMqMo2LxodmVR3AIy1kGcdl2+3BOSFJP0HmqqNtLwRqXvR+q X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1624f149-b1c4-4d59-204b-08db762d2454 X-MS-Exchange-CrossTenant-AuthSource: TYZPR06MB6697.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jun 2023 10:07:25.9905 (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: beSyTg8sTd9dhFv/tMZCDIo4dkxtp8i43foGwSpkgb0dhrSCMVYsPv3tLezt/CvZfSbwwL/d6ajmGx8CwoqCNQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY0PR06MB5755 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Originally, the btrfs_check_data_free_space used round_down twice when aligning the range, which to some extent increased the execution time of the code. After optimization, round_down only needs to be executed once, which can improve code efficiency and increase code readability. Signed-off-by: Lu Hongfei --- fs/btrfs/delalloc-space.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/btrfs/delalloc-space.c b/fs/btrfs/delalloc-space.c index 427abaf608b8..fd33b1cf1954 100644 --- a/fs/btrfs/delalloc-space.c +++ b/fs/btrfs/delalloc-space.c @@ -137,9 +137,8 @@ int btrfs_check_data_free_space(struct btrfs_inode *inode, int ret; /* align the range */ - len = round_up(start + len, fs_info->sectorsize) - - round_down(start, fs_info->sectorsize); start = round_down(start, fs_info->sectorsize); + len = round_up(start + len, fs_info->sectorsize) - start; if (noflush) flush = BTRFS_RESERVE_NO_FLUSH;