mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-24 19:35:58 +00:00
btrfs: add helper to calculate space for delayed references
Instead of duplicating the logic for calculating how much space is required for a given number of delayed references, add an inline helper to encapsulate that logic and use it everywhere we are calculating the space required. Reviewed-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
f4160ee878
commit
0e55a54502
3 changed files with 26 additions and 49 deletions
|
@ -65,20 +65,9 @@ bool btrfs_check_space_for_delayed_refs(struct btrfs_fs_info *fs_info)
|
|||
void btrfs_delayed_refs_rsv_release(struct btrfs_fs_info *fs_info, int nr)
|
||||
{
|
||||
struct btrfs_block_rsv *block_rsv = &fs_info->delayed_refs_rsv;
|
||||
u64 num_bytes = btrfs_calc_insert_metadata_size(fs_info, nr);
|
||||
const u64 num_bytes = btrfs_calc_delayed_ref_bytes(fs_info, nr);
|
||||
u64 released = 0;
|
||||
|
||||
/*
|
||||
* We have to check the mount option here because we could be enabling
|
||||
* the free space tree for the first time and don't have the compat_ro
|
||||
* option set yet.
|
||||
*
|
||||
* We need extra reservations if we have the free space tree because
|
||||
* we'll have to modify that tree as well.
|
||||
*/
|
||||
if (btrfs_test_opt(fs_info, FREE_SPACE_TREE))
|
||||
num_bytes *= 2;
|
||||
|
||||
released = btrfs_block_rsv_release(fs_info, block_rsv, num_bytes, NULL);
|
||||
if (released)
|
||||
trace_btrfs_space_reservation(fs_info, "delayed_refs_rsv",
|
||||
|
@ -100,18 +89,8 @@ void btrfs_update_delayed_refs_rsv(struct btrfs_trans_handle *trans)
|
|||
if (!trans->delayed_ref_updates)
|
||||
return;
|
||||
|
||||
num_bytes = btrfs_calc_insert_metadata_size(fs_info,
|
||||
num_bytes = btrfs_calc_delayed_ref_bytes(fs_info,
|
||||
trans->delayed_ref_updates);
|
||||
/*
|
||||
* We have to check the mount option here because we could be enabling
|
||||
* the free space tree for the first time and don't have the compat_ro
|
||||
* option set yet.
|
||||
*
|
||||
* We need extra reservations if we have the free space tree because
|
||||
* we'll have to modify that tree as well.
|
||||
*/
|
||||
if (btrfs_test_opt(fs_info, FREE_SPACE_TREE))
|
||||
num_bytes *= 2;
|
||||
|
||||
spin_lock(&delayed_rsv->lock);
|
||||
delayed_rsv->size += num_bytes;
|
||||
|
@ -182,21 +161,10 @@ int btrfs_delayed_refs_rsv_refill(struct btrfs_fs_info *fs_info,
|
|||
enum btrfs_reserve_flush_enum flush)
|
||||
{
|
||||
struct btrfs_block_rsv *block_rsv = &fs_info->delayed_refs_rsv;
|
||||
u64 limit = btrfs_calc_insert_metadata_size(fs_info, 1);
|
||||
u64 limit = btrfs_calc_delayed_ref_bytes(fs_info, 1);
|
||||
u64 num_bytes = 0;
|
||||
int ret = -ENOSPC;
|
||||
|
||||
/*
|
||||
* We have to check the mount option here because we could be enabling
|
||||
* the free space tree for the first time and don't have the compat_ro
|
||||
* option set yet.
|
||||
*
|
||||
* We need extra reservations if we have the free space tree because
|
||||
* we'll have to modify that tree as well.
|
||||
*/
|
||||
if (btrfs_test_opt(fs_info, FREE_SPACE_TREE))
|
||||
limit *= 2;
|
||||
|
||||
spin_lock(&block_rsv->lock);
|
||||
if (block_rsv->reserved < block_rsv->size) {
|
||||
num_bytes = block_rsv->size - block_rsv->reserved;
|
||||
|
|
|
@ -253,6 +253,27 @@ extern struct kmem_cache *btrfs_delayed_extent_op_cachep;
|
|||
int __init btrfs_delayed_ref_init(void);
|
||||
void __cold btrfs_delayed_ref_exit(void);
|
||||
|
||||
static inline u64 btrfs_calc_delayed_ref_bytes(const struct btrfs_fs_info *fs_info,
|
||||
int num_delayed_refs)
|
||||
{
|
||||
u64 num_bytes;
|
||||
|
||||
num_bytes = btrfs_calc_insert_metadata_size(fs_info, num_delayed_refs);
|
||||
|
||||
/*
|
||||
* We have to check the mount option here because we could be enabling
|
||||
* the free space tree for the first time and don't have the compat_ro
|
||||
* option set yet.
|
||||
*
|
||||
* We need extra reservations if we have the free space tree because
|
||||
* we'll have to modify that tree as well.
|
||||
*/
|
||||
if (btrfs_test_opt(fs_info, FREE_SPACE_TREE))
|
||||
num_bytes *= 2;
|
||||
|
||||
return num_bytes;
|
||||
}
|
||||
|
||||
static inline void btrfs_init_generic_ref(struct btrfs_ref *generic_ref,
|
||||
int action, u64 bytenr, u64 len, u64 parent)
|
||||
{
|
||||
|
|
|
@ -553,21 +553,9 @@ static inline u64 calc_reclaim_items_nr(const struct btrfs_fs_info *fs_info,
|
|||
static inline u64 calc_delayed_refs_nr(const struct btrfs_fs_info *fs_info,
|
||||
u64 to_reclaim)
|
||||
{
|
||||
u64 bytes;
|
||||
const u64 bytes = btrfs_calc_delayed_ref_bytes(fs_info, 1);
|
||||
u64 nr;
|
||||
|
||||
bytes = btrfs_calc_insert_metadata_size(fs_info, 1);
|
||||
/*
|
||||
* We have to check the mount option here because we could be enabling
|
||||
* the free space tree for the first time and don't have the compat_ro
|
||||
* option set yet.
|
||||
*
|
||||
* We need extra reservations if we have the free space tree because
|
||||
* we'll have to modify that tree as well.
|
||||
*/
|
||||
if (btrfs_test_opt(fs_info, FREE_SPACE_TREE))
|
||||
bytes *= 2;
|
||||
|
||||
nr = div64_u64(to_reclaim, bytes);
|
||||
if (!nr)
|
||||
nr = 1;
|
||||
|
|
Loading…
Reference in a new issue