@@ -163,10 +163,10 @@ int btrfs_can_overcommit(struct btrfs_fs_info *fs_info,
struct btrfs_space_info *space_info, u64 bytes,
enum btrfs_reserve_flush_enum flush)
{
+ enum btrfs_raid_types index;
u64 profile;
u64 avail;
u64 used;
- int factor;
/* Don't overcommit when in mixed mode. */
if (space_info->flags & BTRFS_BLOCK_GROUP_DATA)
@@ -178,16 +178,13 @@ int btrfs_can_overcommit(struct btrfs_fs_info *fs_info,
profile = btrfs_metadata_alloc_profile(fs_info);
used = btrfs_space_info_used(space_info, true);
- avail = atomic64_read(&fs_info->free_chunk_space);
/*
- * If we have dup, raid1 or raid10 then only half of the free
- * space is actually usable. For raid56, the space info used
- * doesn't include the parity drive, so we don't have to
- * change the math
+ * Grab avail space from per-profile array which should be as accurate
+ * as chunk allocator.
*/
- factor = btrfs_bg_type_to_factor(profile);
- avail = div_u64(avail, factor);
+ index = btrfs_bg_flags_to_raid_index(profile);
+ avail = atomic64_read(&fs_info->fs_devices->per_profile_avail[index]);
/*
* If we aren't flushing all things, let us overcommit up to