[PATCH] fs: btrfs: Optimize code execution process to save time

From: Lu Hongfei
Date: Mon Jun 26 2023 - 06:07:35 EST


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 <luhongfei@xxxxxxxx>
---
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;
--
2.39.0