Btrfs: do io in the task context when fsyncing small files
RFC PATCH 1/1 Btrfs: do io in the task context when fsyncing small files
This is a work in progress, and requires that you have include/linux/xlist.h, you can find it here
http://oss.oracle.com/~mason/xlist.h
This is a rough proof of concept, I am very open to any other suggestions.
One of the things that introduces latency when fsyncing small files is passing off the io to different threads to be submitted and completed. When you are only doing a few pages of IO this switching back and forth starts to hurt. This patch will set a flag when we fsync the file so we know we're fsyncing, then if it's a small amount to fsync we submit in the tasks context and setup completions on the task. Then when the io completes the task will run the endio functions itself. This gets us a 5-10% boost in performance. Thanks,
--- fs/btrfs/btrfs_inode.h | 7 ++++++ fs/btrfs/ctree.h | 10 ++++++++ fs/btrfs/extent_io.c | 2 + fs/btrfs/file.c | 16 ++++++++++--- fs/btrfs/inode.c | 54 +++++++++++++++++++++++++++++++++++++++++++++- fs/btrfs/ordered-data.c | 47 +++++++++++++++++++++++++++++++++++++++- 6 files changed, 128 insertions(+), 8 deletions(-)
fs/btrfs/btrfs_inode.h +7 -0
@@ -71,6 +71,10 @@ struct btrfs_inode {/* the space_info for where this inode's data allocations are done */ struct btrfs_space_info *space_info; +atomic_t outstanding_completions; +struct xlist_head completions; +wait_queue_head_t wait; +/* full 64 bit generation number, struct vfs_inode doesn't have a big * enough field for this. */
@@ -158,6 +162,9 @@ struct btrfs_inode {*/ unsigned force_compress:4; +/* This inode is in the middle of a synchronous operation */ + unsigned sync:1; +struct inode vfs_inode; };
fs/btrfs/ctree.h +10 -0
@@ -28,6 +28,7 @@#include <linux/wait.h> #include <linux/slab.h> #include <linux/kobject.h> +#include <linux/xlist.h> #include <trace/events/btrfs.h> #include <asm/kmap_types.h> #include "extent_io.h"
@@ -817,6 +818,15 @@ struct btrfs_caching_control {atomic_t count; }; +struct btrfs_end_io_tsk { +struct bio *bio; +bio_end_io_t *end_io; +void *private; +struct inode *inode; +int error; +struct xlist_head list; +}; +struct btrfs_block_group_cache {struct btrfs_key key;struct btrfs_block_group_item item;
fs/btrfs/extent_io.c +2 -0
@@ -2236,6 +2236,8 @@ static int __extent_writepage(struct page *page, struct writeback_control *wbc,if (nr_delalloc ==0 ) { delalloc_start = delalloc_end +1 ;continue ; + }else if (nr_delalloc >1024 ) { +BTRFS_I (inode)->sync =0 ; } tree->ops->fill_delalloc(inode, page, delalloc_start, delalloc_end, &page_started,
fs/btrfs/file.c +12 -4
@@ -1203,15 +1203,19 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)struct btrfs_trans_handle *trans;trace_btrfs_sync_file (file, datasync); +mutex_lock (&inode->i_mutex); - ret =filemap_write_and_wait_range (inode->i_mapping, start, end); -if (ret) +BTRFS_I (inode)->sync =1 ; + ret =filemap_fdatawrite_range (inode->i_mapping, start, end); +if (ret) { +BTRFS_I (inode)->sync =0 ; +mutex_unlock (&inode->i_mutex);return ret; -mutex_lock (&inode->i_mutex); + }/* we wait first, since the writeback may change the inode */ root->log_batch++; -btrfs_wait_ordered_range (inode,0 , (u64)-1 ); +btrfs_wait_ordered_range (inode, start, end); root->log_batch++;/*
@@ -1219,6 +1223,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)* and see if its already been committed */ if (!BTRFS_I (inode)->last_trans) { +BTRFS_I (inode)->sync =0 ;mutex_unlock (&inode->i_mutex); goto out; }
@@ -1232,6 +1237,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)if (BTRFS_I (inode)->last_trans <= root->fs_info->last_trans_committed) {BTRFS_I (inode)->last_trans =0 ; +BTRFS_I (inode)->sync =0 ;mutex_unlock (&inode->i_mutex); goto out; }
@@ -1245,12 +1251,14 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) trans =btrfs_start_transaction (root,0 );if (IS_ERR (trans)) { ret =PTR_ERR (trans); +BTRFS_I (inode)->sync =0 ;mutex_unlock (&inode->i_mutex); goto out; } ret =btrfs_log_dentry_safe (trans, root, dentry);if (ret <0 ) { +BTRFS_I (inode)->sync =0 ;mutex_unlock (&inode->i_mutex); goto out; }
fs/btrfs/inode.c +52 -2
104 lines not on this page · raw message
fs/btrfs/ordered-data.c +45 -2
68 lines not on this page · raw message
Signature · 1 line
1.7.2.3