Commit d7601566 authored by Naohiro Aota's avatar Naohiro Aota Committed by David Sterba

btrfs: use fs_info->max_extent_size in get_extent_max_capacity()

Use fs_info->max_extent_size also in get_extent_max_capacity() for the
completeness. This is only used for defrag and not really necessary to fix
the metadata reservation size. But, it still suppresses unnecessary defrag
operations.
Signed-off-by: default avatarNaohiro Aota <naohiro.aota@wdc.com>
Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 7d7672bc
...@@ -1230,16 +1230,18 @@ static struct extent_map *defrag_lookup_extent(struct inode *inode, u64 start, ...@@ -1230,16 +1230,18 @@ static struct extent_map *defrag_lookup_extent(struct inode *inode, u64 start,
return em; return em;
} }
static u32 get_extent_max_capacity(const struct extent_map *em) static u32 get_extent_max_capacity(const struct btrfs_fs_info *fs_info,
const struct extent_map *em)
{ {
if (test_bit(EXTENT_FLAG_COMPRESSED, &em->flags)) if (test_bit(EXTENT_FLAG_COMPRESSED, &em->flags))
return BTRFS_MAX_COMPRESSED; return BTRFS_MAX_COMPRESSED;
return BTRFS_MAX_EXTENT_SIZE; return fs_info->max_extent_size;
} }
static bool defrag_check_next_extent(struct inode *inode, struct extent_map *em, static bool defrag_check_next_extent(struct inode *inode, struct extent_map *em,
u32 extent_thresh, u64 newer_than, bool locked) u32 extent_thresh, u64 newer_than, bool locked)
{ {
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
struct extent_map *next; struct extent_map *next;
bool ret = false; bool ret = false;
...@@ -1263,7 +1265,7 @@ static bool defrag_check_next_extent(struct inode *inode, struct extent_map *em, ...@@ -1263,7 +1265,7 @@ static bool defrag_check_next_extent(struct inode *inode, struct extent_map *em,
* If the next extent is at its max capacity, defragging current extent * If the next extent is at its max capacity, defragging current extent
* makes no sense, as the total number of extents won't change. * makes no sense, as the total number of extents won't change.
*/ */
if (next->len >= get_extent_max_capacity(em)) if (next->len >= get_extent_max_capacity(fs_info, em))
goto out; goto out;
/* Skip older extent */ /* Skip older extent */
if (next->generation < newer_than) if (next->generation < newer_than)
...@@ -1400,6 +1402,7 @@ static int defrag_collect_targets(struct btrfs_inode *inode, ...@@ -1400,6 +1402,7 @@ static int defrag_collect_targets(struct btrfs_inode *inode,
bool locked, struct list_head *target_list, bool locked, struct list_head *target_list,
u64 *last_scanned_ret) u64 *last_scanned_ret)
{ {
struct btrfs_fs_info *fs_info = inode->root->fs_info;
bool last_is_target = false; bool last_is_target = false;
u64 cur = start; u64 cur = start;
int ret = 0; int ret = 0;
...@@ -1484,7 +1487,7 @@ static int defrag_collect_targets(struct btrfs_inode *inode, ...@@ -1484,7 +1487,7 @@ static int defrag_collect_targets(struct btrfs_inode *inode,
* Skip extents already at its max capacity, this is mostly for * Skip extents already at its max capacity, this is mostly for
* compressed extents, which max cap is only 128K. * compressed extents, which max cap is only 128K.
*/ */
if (em->len >= get_extent_max_capacity(em)) if (em->len >= get_extent_max_capacity(fs_info, em))
goto next; goto next;
/* /*
......
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