Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp20946304rwd; Thu, 29 Jun 2023 08:58:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6YZ9EnDmmCMI/pWDWClfyGvMNNvoqr693Wquz8y58gXplZMqCAbze+UlgI9hGOdPCkbvtv X-Received: by 2002:a05:6e02:148:b0:345:a757:a4a9 with SMTP id j8-20020a056e02014800b00345a757a4a9mr10364057ilr.22.1688054325486; Thu, 29 Jun 2023 08:58:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688054325; cv=none; d=google.com; s=arc-20160816; b=n/DzeLavvQ6mi2HHsRndsOwpvj3r/5yX6WXQU42kviGmRupc4zxiVpJelDBk/8qri7 DPyeI8qqsLmuhg2A/1YOUHVi88Q3w4aeUVZOeZds6BKkS+jVw6eUqksSncvl2unjOPz3 FnEvSK828HxHbbH7hSfsAVQTPa0wzE+vL1XiNNiaEPhG9sERuR3NACNjfZhWysODqtW6 JfXcjKfRkTpA5n0x10tnxLJi+zfME672+S/eL93DCafjfB25pG0QJO3GzaM9j/Kdn+8z FNzUr7TUdlkn9eiB/DxpB8XlA1wujZYziZWW708E/h0uxtnKSVlvPurVdjSQk8FCjISw obtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:reply-to:message-id:subject:cc:to:from:date :dkim-signature:dkim-signature; bh=qPVwQYynVMCstbm0/qwNXOwQ5cL0DyzRmvEnUJWYqbg=; fh=5imKGwEgPugA1XHC8VjAIhdyT5s4U+NIHYBRG1cA1wE=; b=SIeNSiWuE7V12GQHGA42t5mZDvASsY1JL9nA9EIc5HMwghU1tx6NT4bjSO5cboE3g4 eYdWMlL2bey2czITHoGyZnGU3l8LVXNSQJkY0WefUDh64jkXoYTehv5JQrNAjTuTrfii W1+4M/a10qBuC8g5jlK2Sw3kbGgQZwNktAtmQyttYYK98igzO+gciYGrE6ex3vE6nAOq Ro5I9TgVCauit7CDv3XsMNhmzfSpybaqNdUFA2jSeE2y7Qz4+1YrMt4U315YBcG478qv PSvsux95FqHv6wbDx5vAgTYeArquevftLIg3N5gu58oUNF3eqc48OsiGAbWGvFaGtN9U OEBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=XLdegP4U; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w9-20020a631609000000b005537c94dbefsi10706701pgl.455.2023.06.29.08.58.30; Thu, 29 Jun 2023 08:58:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=XLdegP4U; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232371AbjF2PkF (ORCPT + 99 others); Thu, 29 Jun 2023 11:40:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229575AbjF2PkC (ORCPT ); Thu, 29 Jun 2023 11:40:02 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51DE8210B; Thu, 29 Jun 2023 08:40:01 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id ECE1621853; Thu, 29 Jun 2023 15:39:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1688053199; h=from:from:reply-to: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=qPVwQYynVMCstbm0/qwNXOwQ5cL0DyzRmvEnUJWYqbg=; b=XLdegP4U3l6QvhLOo0Q6yOkTe6OgG/KhMQZvIr54JKQGWJRIu3qz6DnByuQikXGc6SFCTQ 4Ou9Yx1deghPKHw/PusntFjbPKup4l9JqEQJkKPD/4gxVkt09Po7hM1nBP5RIKe3UiKKz0 cWJE+nb6ISZHkYxf6eTBK8XefgHM5Ik= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1688053199; h=from:from:reply-to: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=qPVwQYynVMCstbm0/qwNXOwQ5cL0DyzRmvEnUJWYqbg=; b=HYMOsqSj1cCooCXY6IAZ325dxEdvIDBFpwNUa4ZKii+rCN1xC8LrnrYPeSmxRLz2i0n56j Wa63jAR3uU3GB3Dw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id B986913905; Thu, 29 Jun 2023 15:39:59 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id VYYGLM+lnWT+OwAAMHmgww (envelope-from ); Thu, 29 Jun 2023 15:39:59 +0000 Date: Thu, 29 Jun 2023 17:33:31 +0200 From: David Sterba To: Lu Hongfei Cc: Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, opensource.kernel@vivo.com Subject: Re: [PATCH] fs: btrfs: Optimize code execution process to save time Message-ID: <20230629153331.GN16168@twin.jikos.cz> Reply-To: dsterba@suse.cz References: <20230626100716.18935-1-luhongfei@vivo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230626100716.18935-1-luhongfei@vivo.com> User-Agent: Mutt/1.5.23.1-rc1 (2014-03-12) X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 26, 2023 at 06:07:16PM +0800, Lu Hongfei wrote: > 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. But the code is not equivalent, because there is dependency on the value of start that changes when the line is moved. > 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 is used unchanged, start + len > start = round_down(start, fs_info->sectorsize); > + len = round_up(start + len, fs_info->sectorsize) - start; New code uses the rounded down start for round_up, then for "- start" it's the same (that part is ok). The changelog should explain why the code is still doing the same, not just that it's reducing the number of round_down() calls.