From nobody Wed Dec 31 00:37:10 2025 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 D70E6C4332F for ; Mon, 13 Nov 2023 08:28:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233117AbjKMI2c (ORCPT ); Mon, 13 Nov 2023 03:28:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229817AbjKMI2b (ORCPT ); Mon, 13 Nov 2023 03:28:31 -0500 Received: from smtpbgau1.qq.com (smtpbgau1.qq.com [54.206.16.166]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1404610EB; Mon, 13 Nov 2023 00:28:26 -0800 (PST) X-QQ-mid: bizesmtp85t1699863979tcxakaxm Received: from localhost.localdomain ( [125.76.217.162]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 13 Nov 2023 16:26:17 +0800 (CST) X-QQ-SSF: 01400000000000E0H000000A0000000 X-QQ-FEAT: qcKkmz/zJhxqbYcU5R90Rxyhm/T3t0XRpYz8RuWcrc7q8ZXXUvih9I2J7w3Zm TgGSA5p2t51eTivSBiFpYr6c6s5BMgl50zMLjblpN1qjb5G6ojofsyLTk8GUnkshxHyCwRE NIhLMCB9ZMgTmyRXRAHoNqbLbXqsbN1a5AsQXTE124zpH6KEtTyvPr4TzO9/a9TsGzm2nUU 6ddfTxEDSZwJliX1o38SXMK5Unb2jIfwwcDlgCKVN4RJZUobgRu3pnbz/1yPUeT723tjGUm K3HCyqVt0GWvkDBvbuCUwZ4v2vhWaWCC4GT0DiAN/au/x6Uz+/kVCqmfjnSitfuJdJ0RApK n3BZe2Ia8vVww5lWrp4poRknTBQM33BoMlt5TL8EeHbg2y7Nbe6BR5zxsMF2QiPufA5qFJc rMMWK/vKBYY= X-QQ-GoodBg: 1 X-BIZMAIL-ID: 2065864653820567975 From: Gou Hao To: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, alex@clusterfs.com, linux-ext4@vger.kernel.org Cc: linux-kernel@vger.kernel.org, gouhaojake@163.com Subject: [PATCH] ext4: improving calculation of 'fe_{len|start}' in mb_find_extent() Date: Mon, 13 Nov 2023 16:26:17 +0800 Message-Id: <20231113082617.11258-1-gouhao@uniontech.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:uniontech.com:qybglogicsvrgz:qybglogicsvrgz7a-0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" After first execution of mb_find_order_for_block(): 'fe_start' is the value of 'block' passed in mb_find_extent(). 'fe_len' is the difference between the length of order-chunk and remainder of the block divided by order-chunk. And 'next' does not require initialization after above modifications. Signed-off-by: Gou Hao Reviewed-by: Jan Kara --- fs/ext4/mballoc.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 454d5612641e..d3f985f7cab8 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -1958,8 +1958,7 @@ static void mb_free_blocks(struct inode *inode, struc= t ext4_buddy *e4b, static int mb_find_extent(struct ext4_buddy *e4b, int block, int needed, struct ext4_free_extent *ex) { - int next =3D block; - int max, order; + int max, order, next; void *buddy; =20 assert_spin_locked(ext4_group_lock_ptr(e4b->bd_sb, e4b->bd_group)); @@ -1977,16 +1976,12 @@ static int mb_find_extent(struct ext4_buddy *e4b, i= nt block, =20 /* find actual order */ order =3D mb_find_order_for_block(e4b, block); - block =3D block >> order; =20 - ex->fe_len =3D 1 << order; - ex->fe_start =3D block << order; + ex->fe_len =3D (1 << order) - (block & ((1 << order) - 1)); + ex->fe_start =3D block; ex->fe_group =3D e4b->bd_group; =20 - /* calc difference from given start */ - next =3D next - ex->fe_start; - ex->fe_len -=3D next; - ex->fe_start +=3D next; + block =3D block >> order; =20 while (needed > ex->fe_len && mb_find_buddy(e4b, order, &max)) { --=20 2.20.1