Skip to content

Commit 3593ce3

Browse files
josefbacikkdave
authored andcommitted
btrfs: change the minimum global reserve size
It made sense to have the global reserve set at 16M in the past, but since it is used less nowadays set the minimum size to the number of items we'll need to update the main trees we update during a transaction commit, plus some slop area so we can do unlinks if we need to. In practice this doesn't affect normal file systems, but for xfstests where we do things like fill up a fs and then rm * it can fall over in weird ways. This enables us for more sane behavior at extremely small file system sizes. Signed-off-by: Josef Bacik <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent d05e464 commit 3593ce3

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

fs/btrfs/block-rsv.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ void btrfs_update_global_block_rsv(struct btrfs_fs_info *fs_info)
259259
struct btrfs_block_rsv *block_rsv = &fs_info->global_block_rsv;
260260
struct btrfs_space_info *sinfo = block_rsv->space_info;
261261
u64 num_bytes;
262+
unsigned min_items;
262263

263264
/*
264265
* The global block rsv is based on the size of the extent tree, the
@@ -268,7 +269,26 @@ void btrfs_update_global_block_rsv(struct btrfs_fs_info *fs_info)
268269
num_bytes = btrfs_root_used(&fs_info->extent_root->root_item) +
269270
btrfs_root_used(&fs_info->csum_root->root_item) +
270271
btrfs_root_used(&fs_info->tree_root->root_item);
271-
num_bytes = max_t(u64, num_bytes, SZ_16M);
272+
273+
/*
274+
* We at a minimum are going to modify the csum root, the tree root, and
275+
* the extent root.
276+
*/
277+
min_items = 3;
278+
279+
/*
280+
* But we also want to reserve enough space so we can do the fallback
281+
* global reserve for an unlink, which is an additional 5 items (see the
282+
* comment in __unlink_start_trans for what we're modifying.)
283+
*
284+
* But we also need space for the delayed ref updates from the unlink,
285+
* so its 10, 5 for the actual operation, and 5 for the delayed ref
286+
* updates.
287+
*/
288+
min_items += 10;
289+
290+
num_bytes = max_t(u64, num_bytes,
291+
btrfs_calc_insert_metadata_size(fs_info, min_items));
272292

273293
spin_lock(&sinfo->lock);
274294
spin_lock(&block_rsv->lock);

0 commit comments

Comments
 (0)