btrfs: some trivial cleanups related to io trees
cover btrfs: some trivial cleanups related to io trees
From: Filipe Manana <[email protected]>
Some simple cleanups related to io trees that are very trivial and were initally part of a larger patchset. Details in the change logs.
Filipe Manana (3):
btrfs: use clear_extent_bit() at try_release_extent_state()
btrfs: use clear_extent_bits() at chunk_map_device_clear_bits()
btrfs: simplify last record detection at test_range_bit_exists()
fs/btrfs/extent-io-tree.c | 8 +++----- fs/btrfs/extent_io.c | 2 +- fs/btrfs/volumes.c | 7 +++---- 3 files changed, 7 insertions(+), 10 deletions(-)
Signature · 1 line
2.45.2
PATCH 1/3 btrfs: use clear_extent_bit() at try_release_extent_state()
From: Filipe Manana <[email protected]>
Instead of using __clear_extent_bit() we can use clear_extent_bit() since we pass a NULL value for the changeset argument.
--- fs/btrfs/extent_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/extent_io.c +1 -1
@@ -2651,7 +2651,7 @@ static bool try_release_extent_state(struct extent_io_tree *tree,* nodatasum, delalloc new and finishing ordered bits. The delalloc new * bit will be cleared by ordered extent completion. */ - ret2 =__clear_extent_bit (tree, start, end, clear_bits, &cached_state,NULL ); + ret2 =clear_extent_bit (tree, start, end, clear_bits, &cached_state);/* * If clear_extent_bit failed for enomem reasons, we can't allow the * release to continue.
Signature · 1 line
2.45.2
PATCH 2/3 btrfs: use clear_extent_bits() at chunk_map_device_clear_bits()
In reply to [email protected]From: Filipe Manana <[email protected]>
Instead of using __clear_extent_bit() we can use clear_extent_bits() since we pass a NULL value for the cached and changeset arguments.
--- fs/btrfs/volumes.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
fs/btrfs/volumes.c +3 -4
@@ -5508,10 +5508,9 @@ static void chunk_map_device_clear_bits(struct btrfs_chunk_map *map, unsigned instruct btrfs_io_stripe *stripe = &map->stripes[i];struct btrfs_device *device = stripe->dev; -__clear_extent_bit (&device->alloc_state, stripe->physical, - stripe->physical + map->stripe_size -1 , - bits |EXTENT_NOWAIT , -NULL ,NULL ); +clear_extent_bits (&device->alloc_state, stripe->physical, + stripe->physical + map->stripe_size -1 , + bits |EXTENT_NOWAIT ); } }
Signature · 1 line
2.45.2
PATCH 3/3 btrfs: simplify last record detection at test_range_bit_exists()
In reply to [email protected]From: Filipe Manana <[email protected]>
Instead of keeping track of the minimum start offset of the next record and detecting overflow everytime we update that offset to be the sum of current record's end offset plus one, we can simply exit when the current record ends at or beyond our end offset and forget about about updating the start offset on every iteration and testing for it at the top of the loop. This makes both the source code and assembly code simpler, more efficient and shorter (reducing the object text size).
Also remove the pointless initializion to NULL of the state variable, as we don't use it before the first assignment to it. This may help avoid some warnings with clang tools such as the one reported/fixed by commit 966de47ff0c9 ("btrfs: remove redundant initialization of variables in log_new_ancestors").
--- fs/btrfs/extent-io-tree.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
fs/btrfs/extent-io-tree.c +3 -5
@@ -1726,14 +1726,14 @@ u64 count_range_bits(struct extent_io_tree *tree,*/ bool test_range_bit_exists (struct extent_io_tree *tree,u64 start,u64 end,u32 bit) { -struct extent_state *state =NULL ; +struct extent_state *state;bool bitset = false;ASSERT (is_power_of_2 (bit));spin_lock (&tree->lock); state =tree_search (tree, start); -while (state && start <= end) { +while (state) {if (state->start > end)break ;
@@ -1742,9 +1742,7 @@ bool test_range_bit_exists(struct extent_io_tree *tree, u64 start, u64 end, u32break ; } -/* If state->end is (u64)-1, start will overflow to 0 */ - start = state->end +1 ; -if (start > end || start ==0 ) +if (state->end >= end)break ; state =next_state (state); }
Signature · 1 line
2.45.2
v2 cover btrfs: some trivial cleanups related to io trees
In reply to [email protected]From: Filipe Manana <[email protected]>
Some simple cleanups related to io trees that are very trivial and were initally part of a larger patchset. Details in the change logs.
V2: Added patch 3/4.
Filipe Manana (4):
btrfs: use clear_extent_bit() at try_release_extent_state()
btrfs: use clear_extent_bits() at chunk_map_device_clear_bits()
btrfs: use clear_extent_bits() instead of clear_extent_bit() where possible
btrfs: simplify last record detection at test_range_bit_exists()
fs/btrfs/extent-io-tree.c | 8 +++----- fs/btrfs/extent_io.c | 2 +- fs/btrfs/inode.c | 3 +-- fs/btrfs/reflink.c | 5 ++--- fs/btrfs/tests/inode-tests.c | 24 ++++++++++++------------ fs/btrfs/volumes.c | 7 +++---- 6 files changed, 22 insertions(+), 27 deletions(-)
Signature · 1 line
2.45.2
PATCH v2 1/4 btrfs: use clear_extent_bit() at try_release_extent_state()
From: Filipe Manana <[email protected]>
Instead of using __clear_extent_bit() we can use clear_extent_bit() since we pass a NULL value for the changeset argument.
--- fs/btrfs/extent_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/extent_io.c +1 -1
@@ -2651,7 +2651,7 @@ static bool try_release_extent_state(struct extent_io_tree *tree,* nodatasum, delalloc new and finishing ordered bits. The delalloc new * bit will be cleared by ordered extent completion. */ - ret2 =__clear_extent_bit (tree, start, end, clear_bits, &cached_state,NULL ); + ret2 =clear_extent_bit (tree, start, end, clear_bits, &cached_state);/* * If clear_extent_bit failed for enomem reasons, we can't allow the * release to continue.
Signature · 1 line
2.45.2
PATCH v2 2/4 btrfs: use clear_extent_bits() at chunk_map_device_clear_bits()
In reply to [email protected]From: Filipe Manana <[email protected]>
Instead of using __clear_extent_bit() we can use clear_extent_bits() since we pass a NULL value for the cached and changeset arguments.
--- fs/btrfs/volumes.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
fs/btrfs/volumes.c +3 -4
@@ -5508,10 +5508,9 @@ static void chunk_map_device_clear_bits(struct btrfs_chunk_map *map, unsigned instruct btrfs_io_stripe *stripe = &map->stripes[i];struct btrfs_device *device = stripe->dev; -__clear_extent_bit (&device->alloc_state, stripe->physical, - stripe->physical + map->stripe_size -1 , - bits |EXTENT_NOWAIT , -NULL ,NULL ); +clear_extent_bits (&device->alloc_state, stripe->physical, + stripe->physical + map->stripe_size -1 , + bits |EXTENT_NOWAIT ); } }
Signature · 1 line
2.45.2
PATCH v2 3/4 btrfs: use clear_extent_bits() instead of clear_extent_bit() where possible
In reply to [email protected]From: Filipe Manana <[email protected]>
Several places are using clear_extent_bit() and passing a NULL value for the 'cached' argument, which is pointless as they can use instead clear_extent_bits().
--- fs/btrfs/inode.c | 3 +-- fs/btrfs/reflink.c | 5 ++--- fs/btrfs/tests/inode-tests.c | 24 ++++++++++++------------ 3 files changed, 15 insertions(+), 17 deletions(-)
fs/btrfs/inode.c +1 -2
@@ -1753,8 +1753,7 @@ static int fallback_to_cow(struct btrfs_inode *inode,spin_unlock (&sinfo->lock);if (count >0 ) -clear_extent_bit (io_tree, start, end,EXTENT_NORESERVE , -NULL ); +clear_extent_bits (io_tree, start, end,EXTENT_NORESERVE ); }unlock_extent (io_tree, start, end, &cached_state);
fs/btrfs/reflink.c +2 -3
@@ -95,9 +95,8 @@ static int copy_inline_to_page(struct btrfs_inode *inode,if (ret <0 ) goto out_unlock; -clear_extent_bit (&inode->io_tree, file_offset, range_end, -EXTENT_DELALLOC |EXTENT_DO_ACCOUNTING |EXTENT_DEFRAG , -NULL ); +clear_extent_bits (&inode->io_tree, file_offset, range_end, +EXTENT_DELALLOC |EXTENT_DO_ACCOUNTING |EXTENT_DEFRAG ); ret =btrfs_set_extent_delalloc (inode, file_offset, range_end,0 ,NULL );if (ret) goto out_unlock;
fs/btrfs/tests/inode-tests.c +12 -12
@@ -949,10 +949,10 @@ static int test_extent_accounting(u32 sectorsize, u32 nodesize) }/* [BTRFS_MAX_EXTENT_SIZE/2][sectorsize HOLE][the rest] */ - ret =clear_extent_bit (&BTRFS_I (inode)->io_tree, -BTRFS_MAX_EXTENT_SIZE >>1 , - (BTRFS_MAX_EXTENT_SIZE >>1 ) + sectorsize -1 , -EXTENT_DELALLOC |EXTENT_DELALLOC_NEW ,NULL ); + ret =clear_extent_bits (&BTRFS_I (inode)->io_tree, +BTRFS_MAX_EXTENT_SIZE >>1 , + (BTRFS_MAX_EXTENT_SIZE >>1 ) + sectorsize -1 , +EXTENT_DELALLOC |EXTENT_DELALLOC_NEW );if (ret) {test_err ("clear_extent_bit returned %d" , ret); goto out;
@@ -1016,10 +1016,10 @@ static int test_extent_accounting(u32 sectorsize, u32 nodesize) }/* [BTRFS_MAX_EXTENT_SIZE+4k][4K HOLE][BTRFS_MAX_EXTENT_SIZE+4k] */ - ret =clear_extent_bit (&BTRFS_I (inode)->io_tree, -BTRFS_MAX_EXTENT_SIZE + sectorsize, -BTRFS_MAX_EXTENT_SIZE +2 * sectorsize -1 , -EXTENT_DELALLOC |EXTENT_DELALLOC_NEW ,NULL ); + ret =clear_extent_bits (&BTRFS_I (inode)->io_tree, +BTRFS_MAX_EXTENT_SIZE + sectorsize, +BTRFS_MAX_EXTENT_SIZE +2 * sectorsize -1 , +EXTENT_DELALLOC |EXTENT_DELALLOC_NEW );if (ret) {test_err ("clear_extent_bit returned %d" , ret); goto out;
@@ -1050,8 +1050,8 @@ static int test_extent_accounting(u32 sectorsize, u32 nodesize) }/* Empty */ - ret =clear_extent_bit (&BTRFS_I (inode)->io_tree,0 , (u64)-1 , -EXTENT_DELALLOC |EXTENT_DELALLOC_NEW ,NULL ); + ret =clear_extent_bits (&BTRFS_I (inode)->io_tree,0 , (u64)-1 , +EXTENT_DELALLOC |EXTENT_DELALLOC_NEW );if (ret) {test_err ("clear_extent_bit returned %d" , ret); goto out;
@@ -1065,8 +1065,8 @@ static int test_extent_accounting(u32 sectorsize, u32 nodesize) ret =0 ; out:if (ret) -clear_extent_bit (&BTRFS_I (inode)->io_tree,0 , (u64)-1 , -EXTENT_DELALLOC |EXTENT_DELALLOC_NEW ,NULL ); +clear_extent_bits (&BTRFS_I (inode)->io_tree,0 , (u64)-1 , +EXTENT_DELALLOC |EXTENT_DELALLOC_NEW );iput (inode);btrfs_free_dummy_root (root);btrfs_free_dummy_fs_info (fs_info);
Signature · 1 line
2.45.2
PATCH v2 4/4 btrfs: simplify last record detection at test_range_bit_exists()
In reply to [email protected]From: Filipe Manana <[email protected]>
Instead of keeping track of the minimum start offset of the next record and detecting overflow everytime we update that offset to be the sum of current record's end offset plus one, we can simply exit when the current record ends at or beyond our end offset and forget about updating the start offset on every iteration and testing for it at the top of the loop. This makes both the source code and assembly code simpler, more efficient and shorter (reducing the object text size).
Also remove the pointless initializion to NULL of the state variable, as we don't use it before the first assignment to it. This may help avoid some warnings with clang tools such as the one reported/fixed by commit 966de47ff0c9 ("btrfs: remove redundant initialization of variables in log_new_ancestors").
--- fs/btrfs/extent-io-tree.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
fs/btrfs/extent-io-tree.c +3 -5
@@ -1726,14 +1726,14 @@ u64 count_range_bits(struct extent_io_tree *tree,*/ bool test_range_bit_exists (struct extent_io_tree *tree,u64 start,u64 end,u32 bit) { -struct extent_state *state =NULL ; +struct extent_state *state;bool bitset = false;ASSERT (is_power_of_2 (bit));spin_lock (&tree->lock); state =tree_search (tree, start); -while (state && start <= end) { +while (state) {if (state->start > end)break ;
@@ -1742,9 +1742,7 @@ bool test_range_bit_exists(struct extent_io_tree *tree, u64 start, u64 end, u32break ; } -/* If state->end is (u64)-1, start will overflow to 0 */ - start = state->end +1 ; -if (start > end || start ==0 ) +if (state->end >= end)break ; state =next_state (state); }
Signature · 1 line
2.45.2
Quoted 4 lines · On Tue, Apr 01, 2025 at 04:29:50PM +0100, [email protected] wrote:
From: Filipe Manana <[email protected]>
Some simple cleanups related to io trees that are very trivial and were initally part of a larger patchset. Details in the change logs.
Quoted 20 lines
V2: Added patch 3/4.
Filipe Manana (4):
btrfs: useclear_extent_bit()attry_release_extent_state()
btrfs: useclear_extent_bits()atchunk_map_device_clear_bits()
btrfs: useclear_extent_bits()instead ofclear_extent_bit()where possible
btrfs: simplify last record detection attest_range_bit_exists()fs/btrfs/extent-io-tree.c | 8 +++----- fs/btrfs/extent_io.c | 2 +- fs/btrfs/inode.c | 3 +-- fs/btrfs/reflink.c | 5 ++--- fs/btrfs/tests/inode-tests.c | 24 ++++++++++++------------ fs/btrfs/volumes.c | 7 +++---- 6 files changed, 22 insertions(+), 27 deletions(-)Signature · 1 line
2.45.2
Quoted 4 lines · 在 2025/4/2 01:59, [email protected] 写道:
From: Filipe Manana <[email protected]>
Some simple cleanups related to io trees that are very trivial and were initally part of a larger patchset. Details in the change logs.
My bad, didn't notice the v2 series.
Still looks good.
Thanks,
Qu>
Quoted 16 lines
V2: Added patch 3/4.
Filipe Manana (4):
btrfs: useclear_extent_bit()attry_release_extent_state()
btrfs: useclear_extent_bits()atchunk_map_device_clear_bits()
btrfs: useclear_extent_bits()instead ofclear_extent_bit()where possible
btrfs: simplify last record detection attest_range_bit_exists()fs/btrfs/extent-io-tree.c | 8 +++----- fs/btrfs/extent_io.c | 2 +- fs/btrfs/inode.c | 3 +-- fs/btrfs/reflink.c | 5 ++--- fs/btrfs/tests/inode-tests.c | 24 ++++++++++++------------ fs/btrfs/volumes.c | 7 +++---- 6 files changed, 22 insertions(+), 27 deletions(-)
Quoted 4 lines · 在 2025/4/1 22:35, [email protected] 写道:
From: Filipe Manana <[email protected]>
Some simple cleanups related to io trees that are very trivial and were initally part of a larger patchset. Details in the change logs.
Thanks,
Qu
Quoted 11 lines
Filipe Manana (3):
btrfs: useclear_extent_bit()attry_release_extent_state()
btrfs: useclear_extent_bits()atchunk_map_device_clear_bits()
btrfs: simplify last record detection attest_range_bit_exists()fs/btrfs/extent-io-tree.c | 8 +++----- fs/btrfs/extent_io.c | 2 +- fs/btrfs/volumes.c | 7 +++---- 3 files changed, 7 insertions(+), 10 deletions(-)