diff options
author | Josef Bacik <jbacik@fb.com> | 2015-09-23 17:11:16 -0400 |
---|---|---|
committer | Chris Mason <clm@fb.com> | 2015-10-21 21:51:44 -0400 |
commit | 0b670dc44c91bd1e5fac15b5ac4c98c8bd255ca2 (patch) | |
tree | e0215055573cac5f67c6f6c5a515efdceb60bb07 | |
parent | d0bd456074dca089579818312da7cbe726ad2ff9 (diff) |
Btrfs: fix prealloc under heavy fragmentation conditions
If we are heavily fragmented we will continually try to prealloc the largest
extent size we can every time we call btrfs_reserve_extent. This can be very
expensive when we are heavily fragmented, burning lots of CPU cycles and loops
through the allocator. So instead notice when we get a smaller chunk from the
allocator than what we specified and use this as the new maximum size we try to
allocate. Thanks,
Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: Chris Mason <clm@fb.com>
-rw-r--r-- | fs/btrfs/inode.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 5ce55f6eefce..a3e078365de5 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -9687,6 +9687,7 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode, | |||
9687 | u64 cur_offset = start; | 9687 | u64 cur_offset = start; |
9688 | u64 i_size; | 9688 | u64 i_size; |
9689 | u64 cur_bytes; | 9689 | u64 cur_bytes; |
9690 | u64 last_alloc = (u64)-1; | ||
9690 | int ret = 0; | 9691 | int ret = 0; |
9691 | bool own_trans = true; | 9692 | bool own_trans = true; |
9692 | 9693 | ||
@@ -9703,6 +9704,13 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode, | |||
9703 | 9704 | ||
9704 | cur_bytes = min(num_bytes, 256ULL * 1024 * 1024); | 9705 | cur_bytes = min(num_bytes, 256ULL * 1024 * 1024); |
9705 | cur_bytes = max(cur_bytes, min_size); | 9706 | cur_bytes = max(cur_bytes, min_size); |
9707 | /* | ||
9708 | * If we are severely fragmented we could end up with really | ||
9709 | * small allocations, so if the allocator is returning small | ||
9710 | * chunks lets make its job easier by only searching for those | ||
9711 | * sized chunks. | ||
9712 | */ | ||
9713 | cur_bytes = min(cur_bytes, last_alloc); | ||
9706 | ret = btrfs_reserve_extent(root, cur_bytes, min_size, 0, | 9714 | ret = btrfs_reserve_extent(root, cur_bytes, min_size, 0, |
9707 | *alloc_hint, &ins, 1, 0); | 9715 | *alloc_hint, &ins, 1, 0); |
9708 | if (ret) { | 9716 | if (ret) { |
@@ -9711,6 +9719,7 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode, | |||
9711 | break; | 9719 | break; |
9712 | } | 9720 | } |
9713 | 9721 | ||
9722 | last_alloc = ins.offset; | ||
9714 | ret = insert_reserved_file_extent(trans, inode, | 9723 | ret = insert_reserved_file_extent(trans, inode, |
9715 | cur_offset, ins.objectid, | 9724 | cur_offset, ins.objectid, |
9716 | ins.offset, ins.offset, | 9725 | ins.offset, ins.offset, |