Skip to content

Commit d21356f

Browse files
josefbacikgregkh
authored andcommitted
btrfs: force chunk allocation if our global rsv is larger than metadata
commit 9c34378 upstream. Nikolay noticed a bunch of test failures with my global rsv steal patches. At first he thought they were introduced by them, but they've been failing for a while with 64k nodes. The problem is with 64k nodes we have a global reserve that calculates out to 13MiB on a freshly made file system, which only has 8MiB of metadata space. Because of changes I previously made we no longer account for the global reserve in the overcommit logic, which means we correctly allow overcommit to happen even though we are already overcommitted. However in some corner cases, for example btrfs/170, we will allocate the entire file system up with data chunks before we have enough space pressure to allocate a metadata chunk. Then once the fs is full we ENOSPC out because we cannot overcommit and the global reserve is taking up all of the available space. The most ideal way to deal with this is to change our space reservation stuff to take into account the height of the tree's that we're modifying, so that our global reserve calculation does not end up so obscenely large. However that is a huge undertaking. Instead fix this by forcing a chunk allocation if the global reserve is larger than the total metadata space. This gives us essentially the same behavior that happened before, we get a chunk allocated and these tests can pass. This is meant to be a stop-gap measure until we can tackle the "tree height only" project. Fixes: 0096420 ("btrfs: do not account global reserve in can_overcommit") CC: [email protected] # 5.4+ Reviewed-by: Nikolay Borisov <[email protected]> Tested-by: Nikolay Borisov <[email protected]> Signed-off-by: Josef Bacik <[email protected]> Signed-off-by: David Sterba <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent fe70c3a commit d21356f

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

fs/btrfs/block-rsv.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "block-rsv.h"
66
#include "space-info.h"
77
#include "transaction.h"
8+
#include "block-group.h"
89

910
/*
1011
* HOW DO BLOCK RESERVES WORK
@@ -405,6 +406,8 @@ void btrfs_update_global_block_rsv(struct btrfs_fs_info *fs_info)
405406
else
406407
block_rsv->full = 0;
407408

409+
if (block_rsv->size >= sinfo->total_bytes)
410+
sinfo->force_alloc = CHUNK_ALLOC_FORCE;
408411
spin_unlock(&block_rsv->lock);
409412
spin_unlock(&sinfo->lock);
410413
}

fs/btrfs/transaction.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "dev-replace.h"
2222
#include "qgroup.h"
2323
#include "block-group.h"
24+
#include "space-info.h"
2425

2526
#define BTRFS_ROOT_TRANS_TAG 0
2627

@@ -523,6 +524,7 @@ start_transaction(struct btrfs_root *root, unsigned int num_items,
523524
u64 num_bytes = 0;
524525
u64 qgroup_reserved = 0;
525526
bool reloc_reserved = false;
527+
bool do_chunk_alloc = false;
526528
int ret;
527529

528530
/* Send isn't supposed to start transactions. */
@@ -585,6 +587,9 @@ start_transaction(struct btrfs_root *root, unsigned int num_items,
585587
delayed_refs_bytes);
586588
num_bytes -= delayed_refs_bytes;
587589
}
590+
591+
if (rsv->space_info->force_alloc)
592+
do_chunk_alloc = true;
588593
} else if (num_items == 0 && flush == BTRFS_RESERVE_FLUSH_ALL &&
589594
!delayed_refs_rsv->full) {
590595
/*
@@ -666,6 +671,19 @@ start_transaction(struct btrfs_root *root, unsigned int num_items,
666671
if (!current->journal_info)
667672
current->journal_info = h;
668673

674+
/*
675+
* If the space_info is marked ALLOC_FORCE then we'll get upgraded to
676+
* ALLOC_FORCE the first run through, and then we won't allocate for
677+
* anybody else who races in later. We don't care about the return
678+
* value here.
679+
*/
680+
if (do_chunk_alloc && num_bytes) {
681+
u64 flags = h->block_rsv->space_info->flags;
682+
683+
btrfs_chunk_alloc(h, btrfs_get_alloc_profile(fs_info, flags),
684+
CHUNK_ALLOC_NO_FORCE);
685+
}
686+
669687
/*
670688
* btrfs_record_root_in_trans() needs to alloc new extents, and may
671689
* call btrfs_join_transaction() while we're also starting a

0 commit comments

Comments
 (0)