diff mbox series

[1/5] btrfs: add and use helper to remove extent map from its inode's tree

Message ID fb07004bfcdfb702307b484a4910d8d1d4962fc3.1727174151.git.fdmanana@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs: make extent map shrinker more efficient and re-enable it | expand

Commit Message

Filipe Manana Sept. 24, 2024, 10:45 a.m. UTC
From: Filipe Manana <fdmanana@suse.com>

Move the common code to remove an extent map from its inode's tree into a
helper function and use it, reducing duplicated code.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 fs/btrfs/extent_map.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

Comments

Qu Wenruo Sept. 25, 2024, 10 p.m. UTC | #1
在 2024/9/24 20:15, fdmanana@kernel.org 写道:
> From: Filipe Manana <fdmanana@suse.com>
>
> Move the common code to remove an extent map from its inode's tree into a
> helper function and use it, reducing duplicated code.
>
> Signed-off-by: Filipe Manana <fdmanana@suse.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu
> ---
>   fs/btrfs/extent_map.c | 18 +++++++-----------
>   1 file changed, 7 insertions(+), 11 deletions(-)
>
> diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c
> index 25d191f1ac10..cb2a6f5dce2b 100644
> --- a/fs/btrfs/extent_map.c
> +++ b/fs/btrfs/extent_map.c
> @@ -77,10 +77,13 @@ static u64 range_end(u64 start, u64 len)
>   	return start + len;
>   }
>
> -static void dec_evictable_extent_maps(struct btrfs_inode *inode)
> +static void remove_em(struct btrfs_inode *inode, struct extent_map *em)
>   {
>   	struct btrfs_fs_info *fs_info = inode->root->fs_info;
>
> +	rb_erase(&em->rb_node, &inode->extent_tree.root);
> +	RB_CLEAR_NODE(&em->rb_node);
> +
>   	if (!btrfs_is_testing(fs_info) && is_fstree(btrfs_root_id(inode->root)))
>   		percpu_counter_dec(&fs_info->evictable_extent_maps);
>   }
> @@ -333,7 +336,6 @@ static void validate_extent_map(struct btrfs_fs_info *fs_info, struct extent_map
>   static void try_merge_map(struct btrfs_inode *inode, struct extent_map *em)
>   {
>   	struct btrfs_fs_info *fs_info = inode->root->fs_info;
> -	struct extent_map_tree *tree = &inode->extent_tree;
>   	struct extent_map *merge = NULL;
>   	struct rb_node *rb;
>
> @@ -365,10 +367,8 @@ static void try_merge_map(struct btrfs_inode *inode, struct extent_map *em)
>   			em->flags |= EXTENT_FLAG_MERGED;
>
>   			validate_extent_map(fs_info, em);
> -			rb_erase(&merge->rb_node, &tree->root);
> -			RB_CLEAR_NODE(&merge->rb_node);
> +			remove_em(inode, merge);
>   			free_extent_map(merge);
> -			dec_evictable_extent_maps(inode);
>   		}
>   	}
>
> @@ -380,12 +380,10 @@ static void try_merge_map(struct btrfs_inode *inode, struct extent_map *em)
>   		if (em->disk_bytenr < EXTENT_MAP_LAST_BYTE)
>   			merge_ondisk_extents(em, merge);
>   		validate_extent_map(fs_info, em);
> -		rb_erase(&merge->rb_node, &tree->root);
> -		RB_CLEAR_NODE(&merge->rb_node);
>   		em->generation = max(em->generation, merge->generation);
>   		em->flags |= EXTENT_FLAG_MERGED;
> +		remove_em(inode, merge);
>   		free_extent_map(merge);
> -		dec_evictable_extent_maps(inode);
>   	}
>   }
>
> @@ -582,12 +580,10 @@ void remove_extent_mapping(struct btrfs_inode *inode, struct extent_map *em)
>   	lockdep_assert_held_write(&tree->lock);
>
>   	WARN_ON(em->flags & EXTENT_FLAG_PINNED);
> -	rb_erase(&em->rb_node, &tree->root);
>   	if (!(em->flags & EXTENT_FLAG_LOGGING))
>   		list_del_init(&em->list);
> -	RB_CLEAR_NODE(&em->rb_node);
>
> -	dec_evictable_extent_maps(inode);
> +	remove_em(inode, em);
>   }
>
>   static void replace_extent_mapping(struct btrfs_inode *inode,
diff mbox series

Patch

diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c
index 25d191f1ac10..cb2a6f5dce2b 100644
--- a/fs/btrfs/extent_map.c
+++ b/fs/btrfs/extent_map.c
@@ -77,10 +77,13 @@  static u64 range_end(u64 start, u64 len)
 	return start + len;
 }
 
-static void dec_evictable_extent_maps(struct btrfs_inode *inode)
+static void remove_em(struct btrfs_inode *inode, struct extent_map *em)
 {
 	struct btrfs_fs_info *fs_info = inode->root->fs_info;
 
+	rb_erase(&em->rb_node, &inode->extent_tree.root);
+	RB_CLEAR_NODE(&em->rb_node);
+
 	if (!btrfs_is_testing(fs_info) && is_fstree(btrfs_root_id(inode->root)))
 		percpu_counter_dec(&fs_info->evictable_extent_maps);
 }
@@ -333,7 +336,6 @@  static void validate_extent_map(struct btrfs_fs_info *fs_info, struct extent_map
 static void try_merge_map(struct btrfs_inode *inode, struct extent_map *em)
 {
 	struct btrfs_fs_info *fs_info = inode->root->fs_info;
-	struct extent_map_tree *tree = &inode->extent_tree;
 	struct extent_map *merge = NULL;
 	struct rb_node *rb;
 
@@ -365,10 +367,8 @@  static void try_merge_map(struct btrfs_inode *inode, struct extent_map *em)
 			em->flags |= EXTENT_FLAG_MERGED;
 
 			validate_extent_map(fs_info, em);
-			rb_erase(&merge->rb_node, &tree->root);
-			RB_CLEAR_NODE(&merge->rb_node);
+			remove_em(inode, merge);
 			free_extent_map(merge);
-			dec_evictable_extent_maps(inode);
 		}
 	}
 
@@ -380,12 +380,10 @@  static void try_merge_map(struct btrfs_inode *inode, struct extent_map *em)
 		if (em->disk_bytenr < EXTENT_MAP_LAST_BYTE)
 			merge_ondisk_extents(em, merge);
 		validate_extent_map(fs_info, em);
-		rb_erase(&merge->rb_node, &tree->root);
-		RB_CLEAR_NODE(&merge->rb_node);
 		em->generation = max(em->generation, merge->generation);
 		em->flags |= EXTENT_FLAG_MERGED;
+		remove_em(inode, merge);
 		free_extent_map(merge);
-		dec_evictable_extent_maps(inode);
 	}
 }
 
@@ -582,12 +580,10 @@  void remove_extent_mapping(struct btrfs_inode *inode, struct extent_map *em)
 	lockdep_assert_held_write(&tree->lock);
 
 	WARN_ON(em->flags & EXTENT_FLAG_PINNED);
-	rb_erase(&em->rb_node, &tree->root);
 	if (!(em->flags & EXTENT_FLAG_LOGGING))
 		list_del_init(&em->list);
-	RB_CLEAR_NODE(&em->rb_node);
 
-	dec_evictable_extent_maps(inode);
+	remove_em(inode, em);
 }
 
 static void replace_extent_mapping(struct btrfs_inode *inode,