Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp270807rdb; Thu, 30 Nov 2023 04:36:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IF6yrmWEychSxr8b4zfdjEltpRL1lcpMQXqhocV555TrA1TygTWR4j6efLOQ8rfyqdJfw+c X-Received: by 2002:aa7:98dd:0:b0:6cd:e189:c0f4 with SMTP id e29-20020aa798dd000000b006cde189c0f4mr3092793pfm.12.1701347782087; Thu, 30 Nov 2023 04:36:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701347782; cv=none; d=google.com; s=arc-20160816; b=Gxx2V/erjllJKqiZK4/TRMq0KhoFEXSHIOrmhezZW4L9hoCe2CBgwIv4/J1xFQ0WHJ 2k+UQTk7RKjkmOu2nuu/ScmMRjFAAgJhlXaeuThj9pWbDLikb23ZiC9Wz0urr/1wQvit MZ+jlg7OkU4B8LPKlt2+r2c42yB6jaACCHbBWgWRoRWCyrPlwwR6AEVajeQq3ayu3iX3 ZjKu9uK8Ubxcmpu5Yac7QOL9McSBoemjuzoZtVjfN0Mei5qgB4p1F/c2EblNsJRORm1H wah8Fwz1/JDfQXGu8Oe5iw7fa5H4HLdBz6mGxqq2DfGmPaA11S6vprxIfKLrWfHrMyFt K/DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature:dkim-signature; bh=/ljrQk3BqbkodSFG46bYr4eazlX6Cxqb5pUHT95C7r8=; fh=spUwD7dSELrNX/N9BtbRZGJG2TxWRw4hqNQqIakmps0=; b=nT3M46DxB0ZZWJHofa2i1KtAaLitAE2N6Her1bdpxcNJDLQnhW/MZxFSDR4Wlgkv0n dbGrbYGix6eDTaM9iMHhMgTdG24xq5n3WN0f0dsIA5X60bNd3qSLiacKzYkyNbvn2pwK FKQQB/RdABP4Hftem28X2QEeA++lp6e+hiIBTBsCkKcf7IUJeHUYzIKJKDyNiat6bRjq bMEkoRGxn0BvmyNkEBxfxFgCceFvYBgnGLWoDU4Wn69UB4uDfcDk0Ep2iP8TjuRQLXUE K9uUfvktuAnmx0nl7lUlkpxaNygEwyjdsur3h/9FwI0aCYGuiDliQnqBaKerilwkDksW fdsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=1N8lw7rU; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-ext4+bounces-239-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-ext4+bounces-239-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id df9-20020a056a00470900b006be30cdc3d8si1084055pfb.163.2023.11.30.04.36.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 04:36:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-239-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=1N8lw7rU; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-ext4+bounces-239-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-ext4+bounces-239-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 0C3DFB20E0A for ; Thu, 30 Nov 2023 12:36:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EC3BD3C06D; Thu, 30 Nov 2023 12:36:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="1N8lw7rU"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="WcwFG53O" X-Original-To: linux-ext4@vger.kernel.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C12E8D4A; Thu, 30 Nov 2023 04:36:04 -0800 (PST) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 4223A1FB3F; Thu, 30 Nov 2023 12:36:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1701347762; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=/ljrQk3BqbkodSFG46bYr4eazlX6Cxqb5pUHT95C7r8=; b=1N8lw7rU4uUXQy7fe3kxGnnYmL9jqMDEONqJi4/euu9FDvVp5d5BVwGYTs3NGNoPw3QeYQ sEONeEvUeUZglEaIPJt7j2qKxT1W/paPxfGinNzHslBgNLQYl4xjoEsV/7IYUm0rUz4v33 D4Tu57GRj/GmtNCkIvp4+aTtjwUjwts= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1701347762; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=/ljrQk3BqbkodSFG46bYr4eazlX6Cxqb5pUHT95C7r8=; b=WcwFG53OnS6tXTduO1WdTZq2CZ6bNcbIBD//vZLIBdvx9koi3D5zpu/etzAgsfziyUkkNk IaL6OOFyhNZmKoCw== Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 34D9613A5C; Thu, 30 Nov 2023 12:36:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id NeTdDLKBaGV2UwAAn2gu4w (envelope-from ); Thu, 30 Nov 2023 12:36:02 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id AB210A07DB; Thu, 30 Nov 2023 13:36:01 +0100 (CET) Date: Thu, 30 Nov 2023 13:36:01 +0100 From: Jan Kara To: Gou Hao Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, alex@clusterfs.com, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, gouhaojake@163.com Subject: Re: [PATCH] ext4: improving calculation of 'fe_{len|start}' in mb_find_extent() Message-ID: <20231130123601.bdzyhsxqegpe5qbe@quack3> References: <20231113082617.11258-1-gouhao@uniontech.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231113082617.11258-1-gouhao@uniontech.com> Authentication-Results: smtp-out2.suse.de; none X-Spam-Score: 4.50 X-Spamd-Result: default: False [4.50 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; BAYES_SPAM(5.10)[100.00%]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FREEMAIL_ENVRCPT(0.00)[163.com]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; RCPT_COUNT_SEVEN(0.00)[8]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.cz:email,suse.com:email,uniontech.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; MID_RHS_NOT_FQDN(0.50)[]; FREEMAIL_CC(0.00)[mit.edu,dilger.ca,suse.cz,clusterfs.com,vger.kernel.org,163.com]; RCVD_TLS_ALL(0.00)[] On Mon 13-11-23 16:26:17, Gou Hao wrote: > 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 Ah, nice simplification! Feel free to add: Reviewed-by: Jan Kara Honza > --- > 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, struct ext4_buddy *e4b, > static int mb_find_extent(struct ext4_buddy *e4b, int block, > int needed, struct ext4_free_extent *ex) > { > - int next = block; > - int max, order; > + int max, order, next; > void *buddy; > > 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, int block, > > /* find actual order */ > order = mb_find_order_for_block(e4b, block); > - block = block >> order; > > - ex->fe_len = 1 << order; > - ex->fe_start = block << order; > + ex->fe_len = (1 << order) - (block & ((1 << order) - 1)); > + ex->fe_start = block; > ex->fe_group = e4b->bd_group; > > - /* calc difference from given start */ > - next = next - ex->fe_start; > - ex->fe_len -= next; > - ex->fe_start += next; > + block = block >> order; > > while (needed > ex->fe_len && > mb_find_buddy(e4b, order, &max)) { > -- > 2.20.1 > -- Jan Kara SUSE Labs, CR