From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: Marc Lehmann <schmorp@schmorp.de>, Josef Bacik <josef@toxicpanda.com>
Subject: [PATCH v7 2/5] btrfs: space-info: Use per-profile available space in can_overcommit()
Date: Tue, 11 Feb 2020 13:11:50 +0800 [thread overview]
Message-ID: <20200211051153.19466-3-wqu@suse.com> (raw)
In-Reply-To: <20200211051153.19466-1-wqu@suse.com>
For the following disk layout, can_overcommit() can cause false
confidence in available space:
devid 1 unallocated: 1T
devid 2 unallocated: 10T
metadata type: RAID1
As can_overcommit() simply uses unallocated space with factor to
calculate the allocatable metadata chunk size.
can_overcommit() believes we still have 5.5T for metadata chunks, while
the truth is, we only have 1T available for metadata chunks.
This can lead to ENOSPC at run_delalloc_range() and cause transaction
abort.
Since factor based calculation can't distinguish RAID1/RAID10 and DUP at
all, we need proper chunk-allocator level awareness to do such estimation.
Thankfully, we have per-profile available space already calculated, just
use that facility to avoid such false confidence.
Reported-by: Marc Lehmann <schmorp@schmorp.de>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
---
fs/btrfs/space-info.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
index 01297c5b2666..2fdc19a39e07 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
@@ -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,15 @@ 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);
+ spin_lock(&fs_info->fs_devices->per_profile_lock);
+ avail = fs_info->fs_devices->per_profile_avail[index];
+ spin_unlock(&fs_info->fs_devices->per_profile_lock);
/*
* If we aren't flushing all things, let us overcommit up to
--
2.25.0
next prev parent reply other threads:[~2020-02-11 5:12 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-11 5:11 [PATCH v7 0/5] Introduce per-profile available space array to avoid over-confident can_overcommit() Qu Wenruo
2020-02-11 5:11 ` [PATCH v7 1/5] btrfs: Introduce per-profile available space facility Qu Wenruo
2020-02-13 17:12 ` kbuild test robot
2020-02-20 12:49 ` Nikolay Borisov
2020-02-20 12:59 ` Qu Wenruo
2020-02-20 13:19 ` Nikolay Borisov
2020-02-21 5:16 ` Qu Wenruo
2020-02-11 5:11 ` Qu Wenruo [this message]
2020-02-11 5:11 ` [PATCH v7 3/5] btrfs: statfs: Use pre-calculated per-profile available space Qu Wenruo
2020-02-11 5:11 ` [PATCH v7 4/5] btrfs: Reset device size when btrfs_update_device() failed in btrfs_grow_device() Qu Wenruo
2020-02-11 5:11 ` [PATCH v7 5/5] btrfs: volumes: Revert device used bytes when calc_per_profile_avail() failed Qu Wenruo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200211051153.19466-3-wqu@suse.com \
--to=wqu@suse.com \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=schmorp@schmorp.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).