aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/inode.c
diff options
context:
space:
mode:
authorAnand Jain <anand.jain@oracle.com>2016-12-19 06:09:06 -0500
committerDavid Sterba <dsterba@suse.com>2017-02-14 09:50:50 -0500
commit26d30f85290723613a32e8f1d02504352502a224 (patch)
tree03332ddb6e3a130be5a1441ea4a266d04ee529d4 /fs/btrfs/inode.c
parent8c3e6b1f0cd1765d6aeeaa9cdb69b39cea0b6804 (diff)
btrfs: consolidate auto defrag kick off policies
As of now writes smaller than 64k for non compressed extents and 16k for compressed extents inside eof are considered as candidate for auto defrag, put them together at a place. Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r--fs/btrfs/inode.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index c2fc5357166a..c0e982c36ec5 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -388,6 +388,15 @@ static inline int inode_need_compress(struct inode *inode)
388 return 0; 388 return 0;
389} 389}
390 390
391static inline void inode_should_defrag(struct inode *inode,
392 u64 start, u64 end, u64 num_bytes, u64 small_write)
393{
394 /* If this is a small write inside eof, kick off a defrag */
395 if (num_bytes < small_write &&
396 (start > 0 || end + 1 < BTRFS_I(inode)->disk_i_size))
397 btrfs_add_inode_defrag(NULL, inode);
398}
399
391/* 400/*
392 * we create compressed extents in two phases. The first 401 * we create compressed extents in two phases. The first
393 * phase compresses a range of pages that have already been 402 * phase compresses a range of pages that have already been
@@ -430,10 +439,7 @@ static noinline void compress_file_range(struct inode *inode,
430 int compress_type = fs_info->compress_type; 439 int compress_type = fs_info->compress_type;
431 int redirty = 0; 440 int redirty = 0;
432 441
433 /* if this is a small write inside eof, kick off a defrag */ 442 inode_should_defrag(inode, start, end, end - start + 1, SZ_16K);
434 if ((end - start + 1) < SZ_16K &&
435 (start > 0 || end + 1 < BTRFS_I(inode)->disk_i_size))
436 btrfs_add_inode_defrag(NULL, inode);
437 443
438 actual_end = min_t(u64, isize, end + 1); 444 actual_end = min_t(u64, isize, end + 1);
439again: 445again:
@@ -965,10 +971,7 @@ static noinline int cow_file_range(struct inode *inode,
965 num_bytes = max(blocksize, num_bytes); 971 num_bytes = max(blocksize, num_bytes);
966 disk_num_bytes = num_bytes; 972 disk_num_bytes = num_bytes;
967 973
968 /* if this is a small write inside eof, kick off defrag */ 974 inode_should_defrag(inode, start, end, num_bytes, SZ_64K);
969 if (num_bytes < SZ_64K &&
970 (start > 0 || end + 1 < BTRFS_I(inode)->disk_i_size))
971 btrfs_add_inode_defrag(NULL, inode);
972 975
973 if (start == 0) { 976 if (start == 0) {
974 /* lets try to make an inline extent */ 977 /* lets try to make an inline extent */