Commit c2fbd812 authored by Filipe Manana's avatar Filipe Manana Committed by David Sterba

btrfs: pass the extent map tree's inode to remove_extent_mapping()

Extent maps are always associated to an inode's extent map tree, so
there's no need to pass the extent map tree explicitly to
remove_extent_mapping().

In order to facilitate an upcoming change that adds a shrinker for extent
maps, change remove_extent_mapping() to receive the inode instead of its
extent map tree.
Reviewed-by: default avatarQu Wenruo <wqu@suse.com>
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 002f3a2c
...@@ -2457,7 +2457,7 @@ int try_release_extent_mapping(struct page *page, gfp_t mask) ...@@ -2457,7 +2457,7 @@ int try_release_extent_mapping(struct page *page, gfp_t mask)
* hurts the fsync performance for workloads with a data * hurts the fsync performance for workloads with a data
* size that exceeds or is close to the system's memory). * size that exceeds or is close to the system's memory).
*/ */
remove_extent_mapping(map, em); remove_extent_mapping(btrfs_inode, em);
/* once for the rb tree */ /* once for the rb tree */
free_extent_map(em); free_extent_map(em);
next: next:
......
...@@ -449,16 +449,18 @@ struct extent_map *search_extent_mapping(struct extent_map_tree *tree, ...@@ -449,16 +449,18 @@ struct extent_map *search_extent_mapping(struct extent_map_tree *tree,
} }
/* /*
* Remove an extent_map from the extent tree. * Remove an extent_map from its inode's extent tree.
* *
* @tree: extent tree to remove from * @inode: the inode the extent map belongs to
* @em: extent map being removed * @em: extent map being removed
* *
* Remove @em from @tree. No reference counts are dropped, and no checks * Remove @em from the extent tree of @inode. No reference counts are dropped,
* are done to see if the range is in use. * and no checks are done to see if the range is in use.
*/ */
void remove_extent_mapping(struct extent_map_tree *tree, struct extent_map *em) void remove_extent_mapping(struct btrfs_inode *inode, struct extent_map *em)
{ {
struct extent_map_tree *tree = &inode->extent_tree;
lockdep_assert_held_write(&tree->lock); lockdep_assert_held_write(&tree->lock);
WARN_ON(em->flags & EXTENT_FLAG_PINNED); WARN_ON(em->flags & EXTENT_FLAG_PINNED);
...@@ -633,8 +635,10 @@ int btrfs_add_extent_mapping(struct btrfs_inode *inode, ...@@ -633,8 +635,10 @@ int btrfs_add_extent_mapping(struct btrfs_inode *inode,
* if needed. This avoids searching the tree, from the root down to the first * if needed. This avoids searching the tree, from the root down to the first
* extent map, before each deletion. * extent map, before each deletion.
*/ */
static void drop_all_extent_maps_fast(struct extent_map_tree *tree) static void drop_all_extent_maps_fast(struct btrfs_inode *inode)
{ {
struct extent_map_tree *tree = &inode->extent_tree;
write_lock(&tree->lock); write_lock(&tree->lock);
while (!RB_EMPTY_ROOT(&tree->map.rb_root)) { while (!RB_EMPTY_ROOT(&tree->map.rb_root)) {
struct extent_map *em; struct extent_map *em;
...@@ -643,7 +647,7 @@ static void drop_all_extent_maps_fast(struct extent_map_tree *tree) ...@@ -643,7 +647,7 @@ static void drop_all_extent_maps_fast(struct extent_map_tree *tree)
node = rb_first_cached(&tree->map); node = rb_first_cached(&tree->map);
em = rb_entry(node, struct extent_map, rb_node); em = rb_entry(node, struct extent_map, rb_node);
em->flags &= ~(EXTENT_FLAG_PINNED | EXTENT_FLAG_LOGGING); em->flags &= ~(EXTENT_FLAG_PINNED | EXTENT_FLAG_LOGGING);
remove_extent_mapping(tree, em); remove_extent_mapping(inode, em);
free_extent_map(em); free_extent_map(em);
cond_resched_rwlock_write(&tree->lock); cond_resched_rwlock_write(&tree->lock);
} }
...@@ -676,7 +680,7 @@ void btrfs_drop_extent_map_range(struct btrfs_inode *inode, u64 start, u64 end, ...@@ -676,7 +680,7 @@ void btrfs_drop_extent_map_range(struct btrfs_inode *inode, u64 start, u64 end,
WARN_ON(end < start); WARN_ON(end < start);
if (end == (u64)-1) { if (end == (u64)-1) {
if (start == 0 && !skip_pinned) { if (start == 0 && !skip_pinned) {
drop_all_extent_maps_fast(em_tree); drop_all_extent_maps_fast(inode);
return; return;
} }
len = (u64)-1; len = (u64)-1;
...@@ -854,7 +858,7 @@ void btrfs_drop_extent_map_range(struct btrfs_inode *inode, u64 start, u64 end, ...@@ -854,7 +858,7 @@ void btrfs_drop_extent_map_range(struct btrfs_inode *inode, u64 start, u64 end,
ASSERT(!split); ASSERT(!split);
btrfs_set_inode_full_sync(inode); btrfs_set_inode_full_sync(inode);
} }
remove_extent_mapping(em_tree, em); remove_extent_mapping(inode, em);
} }
/* /*
......
...@@ -120,7 +120,7 @@ static inline u64 extent_map_end(const struct extent_map *em) ...@@ -120,7 +120,7 @@ static inline u64 extent_map_end(const struct extent_map *em)
void extent_map_tree_init(struct extent_map_tree *tree); void extent_map_tree_init(struct extent_map_tree *tree);
struct extent_map *lookup_extent_mapping(struct extent_map_tree *tree, struct extent_map *lookup_extent_mapping(struct extent_map_tree *tree,
u64 start, u64 len); u64 start, u64 len);
void remove_extent_mapping(struct extent_map_tree *tree, struct extent_map *em); void remove_extent_mapping(struct btrfs_inode *inode, struct extent_map *em);
int split_extent_map(struct btrfs_inode *inode, u64 start, u64 len, u64 pre, int split_extent_map(struct btrfs_inode *inode, u64 start, u64 len, u64 pre,
u64 new_logical); u64 new_logical);
......
...@@ -11,8 +11,9 @@ ...@@ -11,8 +11,9 @@
#include "../disk-io.h" #include "../disk-io.h"
#include "../block-group.h" #include "../block-group.h"
static int free_extent_map_tree(struct extent_map_tree *em_tree) static int free_extent_map_tree(struct btrfs_inode *inode)
{ {
struct extent_map_tree *em_tree = &inode->extent_tree;
struct extent_map *em; struct extent_map *em;
struct rb_node *node; struct rb_node *node;
int ret = 0; int ret = 0;
...@@ -21,7 +22,7 @@ static int free_extent_map_tree(struct extent_map_tree *em_tree) ...@@ -21,7 +22,7 @@ static int free_extent_map_tree(struct extent_map_tree *em_tree)
while (!RB_EMPTY_ROOT(&em_tree->map.rb_root)) { while (!RB_EMPTY_ROOT(&em_tree->map.rb_root)) {
node = rb_first_cached(&em_tree->map); node = rb_first_cached(&em_tree->map);
em = rb_entry(node, struct extent_map, rb_node); em = rb_entry(node, struct extent_map, rb_node);
remove_extent_mapping(em_tree, em); remove_extent_mapping(inode, em);
#ifdef CONFIG_BTRFS_DEBUG #ifdef CONFIG_BTRFS_DEBUG
if (refcount_read(&em->refs) != 1) { if (refcount_read(&em->refs) != 1) {
...@@ -142,7 +143,7 @@ static int test_case_1(struct btrfs_fs_info *fs_info, struct btrfs_inode *inode) ...@@ -142,7 +143,7 @@ static int test_case_1(struct btrfs_fs_info *fs_info, struct btrfs_inode *inode)
} }
free_extent_map(em); free_extent_map(em);
out: out:
ret2 = free_extent_map_tree(em_tree); ret2 = free_extent_map_tree(inode);
if (ret == 0) if (ret == 0)
ret = ret2; ret = ret2;
...@@ -237,7 +238,7 @@ static int test_case_2(struct btrfs_fs_info *fs_info, struct btrfs_inode *inode) ...@@ -237,7 +238,7 @@ static int test_case_2(struct btrfs_fs_info *fs_info, struct btrfs_inode *inode)
} }
free_extent_map(em); free_extent_map(em);
out: out:
ret2 = free_extent_map_tree(em_tree); ret2 = free_extent_map_tree(inode);
if (ret == 0) if (ret == 0)
ret = ret2; ret = ret2;
...@@ -313,7 +314,7 @@ static int __test_case_3(struct btrfs_fs_info *fs_info, ...@@ -313,7 +314,7 @@ static int __test_case_3(struct btrfs_fs_info *fs_info,
} }
free_extent_map(em); free_extent_map(em);
out: out:
ret2 = free_extent_map_tree(em_tree); ret2 = free_extent_map_tree(inode);
if (ret == 0) if (ret == 0)
ret = ret2; ret = ret2;
...@@ -435,7 +436,7 @@ static int __test_case_4(struct btrfs_fs_info *fs_info, ...@@ -435,7 +436,7 @@ static int __test_case_4(struct btrfs_fs_info *fs_info,
} }
free_extent_map(em); free_extent_map(em);
out: out:
ret2 = free_extent_map_tree(em_tree); ret2 = free_extent_map_tree(inode);
if (ret == 0) if (ret == 0)
ret = ret2; ret = ret2;
...@@ -679,7 +680,7 @@ static int test_case_5(struct btrfs_fs_info *fs_info, struct btrfs_inode *inode) ...@@ -679,7 +680,7 @@ static int test_case_5(struct btrfs_fs_info *fs_info, struct btrfs_inode *inode)
if (ret) if (ret)
goto out; goto out;
out: out:
ret2 = free_extent_map_tree(&inode->extent_tree); ret2 = free_extent_map_tree(inode);
if (ret == 0) if (ret == 0)
ret = ret2; ret = ret2;
...@@ -738,7 +739,7 @@ static int test_case_6(struct btrfs_fs_info *fs_info, struct btrfs_inode *inode) ...@@ -738,7 +739,7 @@ static int test_case_6(struct btrfs_fs_info *fs_info, struct btrfs_inode *inode)
ret = 0; ret = 0;
out: out:
free_extent_map(em); free_extent_map(em);
ret2 = free_extent_map_tree(em_tree); ret2 = free_extent_map_tree(inode);
if (ret == 0) if (ret == 0)
ret = ret2; ret = ret2;
...@@ -876,7 +877,7 @@ static int test_case_7(struct btrfs_fs_info *fs_info, struct btrfs_inode *inode) ...@@ -876,7 +877,7 @@ static int test_case_7(struct btrfs_fs_info *fs_info, struct btrfs_inode *inode)
ret2 = unpin_extent_cache(inode, 0, SZ_16K, 0); ret2 = unpin_extent_cache(inode, 0, SZ_16K, 0);
if (ret == 0) if (ret == 0)
ret = ret2; ret = ret2;
ret2 = free_extent_map_tree(em_tree); ret2 = free_extent_map_tree(inode);
if (ret == 0) if (ret == 0)
ret = ret2; ret = ret2;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment