[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230629153331.GN16168@twin.jikos.cz>
Date: Thu, 29 Jun 2023 17:33:31 +0200
From: David Sterba <dsterba@...e.cz>
To: Lu Hongfei <luhongfei@...o.com>
Cc: Chris Mason <clm@...com>, Josef Bacik <josef@...icpanda.com>,
David Sterba <dsterba@...e.com>, linux-btrfs@...r.kernel.org,
linux-kernel@...r.kernel.org, opensource.kernel@...o.com
Subject: Re: [PATCH] fs: btrfs: Optimize code execution process to save time
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 <luhongfei@...o.com>
> ---
> 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.
Powered by blists - more mailing lists