Commit 98d20f67 authored by Chris Mason's avatar Chris Mason

Add a min size parameter to btrfs_alloc_extent

On huge machines, delayed allocation may try to allocate massive extents.
This change allows btrfs_alloc_extent to return something smaller than
the caller asked for, and the data allocation routines will loop over
the allocations until it fills the whole delayed alloc.
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent 73f61b2a
...@@ -1286,7 +1286,8 @@ int btrfs_insert_extent_backref(struct btrfs_trans_handle *trans, ...@@ -1286,7 +1286,8 @@ int btrfs_insert_extent_backref(struct btrfs_trans_handle *trans,
u64 owner, u64 owner_offset); u64 owner, u64 owner_offset);
int btrfs_alloc_extent(struct btrfs_trans_handle *trans, int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct btrfs_root *root,
u64 num_bytes, u64 root_objectid, u64 ref_generation, u64 num_bytes, u64 min_bytes,
u64 root_objectid, u64 ref_generation,
u64 owner, u64 owner_offset, u64 owner, u64 owner_offset,
u64 empty_size, u64 hint_byte, u64 empty_size, u64 hint_byte,
u64 search_end, struct btrfs_key *ins, int data); u64 search_end, struct btrfs_key *ins, int data);
......
...@@ -1694,7 +1694,8 @@ static int noinline find_free_extent(struct btrfs_trans_handle *trans, ...@@ -1694,7 +1694,8 @@ static int noinline find_free_extent(struct btrfs_trans_handle *trans,
*/ */
int btrfs_alloc_extent(struct btrfs_trans_handle *trans, int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct btrfs_root *root,
u64 num_bytes, u64 root_objectid, u64 ref_generation, u64 num_bytes, u64 min_alloc_size,
u64 root_objectid, u64 ref_generation,
u64 owner, u64 owner_offset, u64 owner, u64 owner_offset,
u64 empty_size, u64 hint_byte, u64 empty_size, u64 hint_byte,
u64 search_end, struct btrfs_key *ins, int data) u64 search_end, struct btrfs_key *ins, int data)
...@@ -1727,7 +1728,7 @@ int btrfs_alloc_extent(struct btrfs_trans_handle *trans, ...@@ -1727,7 +1728,7 @@ int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
info->metadata_alloc_profile; info->metadata_alloc_profile;
data = BTRFS_BLOCK_GROUP_METADATA | alloc_profile; data = BTRFS_BLOCK_GROUP_METADATA | alloc_profile;
} }
again:
if (root->ref_cows) { if (root->ref_cows) {
if (!(data & BTRFS_BLOCK_GROUP_METADATA)) { if (!(data & BTRFS_BLOCK_GROUP_METADATA)) {
ret = do_chunk_alloc(trans, root->fs_info->extent_root, ret = do_chunk_alloc(trans, root->fs_info->extent_root,
...@@ -1751,6 +1752,11 @@ int btrfs_alloc_extent(struct btrfs_trans_handle *trans, ...@@ -1751,6 +1752,11 @@ int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
search_start, search_end, hint_byte, ins, search_start, search_end, hint_byte, ins,
trans->alloc_exclude_start, trans->alloc_exclude_start,
trans->alloc_exclude_nr, data); trans->alloc_exclude_nr, data);
if (ret == -ENOSPC && num_bytes > min_alloc_size) {
num_bytes = num_bytes >> 1;
num_bytes = max(num_bytes, min_alloc_size);
goto again;
}
BUG_ON(ret); BUG_ON(ret);
if (ret) if (ret)
return ret; return ret;
...@@ -1869,7 +1875,7 @@ struct extent_buffer *__btrfs_alloc_free_block(struct btrfs_trans_handle *trans, ...@@ -1869,7 +1875,7 @@ struct extent_buffer *__btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
int ret; int ret;
struct extent_buffer *buf; struct extent_buffer *buf;
ret = btrfs_alloc_extent(trans, root, blocksize, ret = btrfs_alloc_extent(trans, root, blocksize, blocksize,
root_objectid, ref_generation, root_objectid, ref_generation,
level, first_objectid, empty_size, hint, level, first_objectid, empty_size, hint,
(u64)-1, &ins, 0); (u64)-1, &ins, 0);
......
...@@ -125,6 +125,7 @@ static int cow_file_range(struct inode *inode, u64 start, u64 end) ...@@ -125,6 +125,7 @@ static int cow_file_range(struct inode *inode, u64 start, u64 end)
while(num_bytes > 0) { while(num_bytes > 0) {
cur_alloc_size = min(num_bytes, root->fs_info->max_extent); cur_alloc_size = min(num_bytes, root->fs_info->max_extent);
ret = btrfs_alloc_extent(trans, root, cur_alloc_size, ret = btrfs_alloc_extent(trans, root, cur_alloc_size,
root->sectorsize,
root->root_key.objectid, root->root_key.objectid,
trans->transid, trans->transid,
inode->i_ino, start, 0, inode->i_ino, start, 0,
...@@ -133,6 +134,7 @@ static int cow_file_range(struct inode *inode, u64 start, u64 end) ...@@ -133,6 +134,7 @@ static int cow_file_range(struct inode *inode, u64 start, u64 end)
WARN_ON(1); WARN_ON(1);
goto out; goto out;
} }
cur_alloc_size = ins.offset;
ret = btrfs_insert_file_extent(trans, root, inode->i_ino, ret = btrfs_insert_file_extent(trans, root, inode->i_ino,
start, ins.objectid, ins.offset, start, ins.objectid, ins.offset,
ins.offset); ins.offset);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment