Btrfs: use async helpers for DIO write checksumming

The async helper threads offload crc work onto all the
CPUs, and make streaming writes much faster.  This
changes the O_DIRECT write code to use them.  The only
small complication was that we need to pass in the
logical offset in the file for each bio, because we can't
find it in the bio's pages.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
This commit is contained in:
Chris Mason 2010-05-25 09:48:28 -04:00
parent ed3b3d314c
commit eaf25d933e
5 changed files with 52 additions and 17 deletions

View File

@ -74,6 +74,11 @@ struct async_submit_bio {
int rw; int rw;
int mirror_num; int mirror_num;
unsigned long bio_flags; unsigned long bio_flags;
/*
* bio_offset is optional, can be used if the pages in the bio
* can't tell us where in the file the bio should go
*/
u64 bio_offset;
struct btrfs_work work; struct btrfs_work work;
}; };
@ -534,7 +539,8 @@ static void run_one_async_start(struct btrfs_work *work)
async = container_of(work, struct async_submit_bio, work); async = container_of(work, struct async_submit_bio, work);
fs_info = BTRFS_I(async->inode)->root->fs_info; fs_info = BTRFS_I(async->inode)->root->fs_info;
async->submit_bio_start(async->inode, async->rw, async->bio, async->submit_bio_start(async->inode, async->rw, async->bio,
async->mirror_num, async->bio_flags); async->mirror_num, async->bio_flags,
async->bio_offset);
} }
static void run_one_async_done(struct btrfs_work *work) static void run_one_async_done(struct btrfs_work *work)
@ -556,7 +562,8 @@ static void run_one_async_done(struct btrfs_work *work)
wake_up(&fs_info->async_submit_wait); wake_up(&fs_info->async_submit_wait);
async->submit_bio_done(async->inode, async->rw, async->bio, async->submit_bio_done(async->inode, async->rw, async->bio,
async->mirror_num, async->bio_flags); async->mirror_num, async->bio_flags,
async->bio_offset);
} }
static void run_one_async_free(struct btrfs_work *work) static void run_one_async_free(struct btrfs_work *work)
@ -570,6 +577,7 @@ static void run_one_async_free(struct btrfs_work *work)
int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct inode *inode, int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct inode *inode,
int rw, struct bio *bio, int mirror_num, int rw, struct bio *bio, int mirror_num,
unsigned long bio_flags, unsigned long bio_flags,
u64 bio_offset,
extent_submit_bio_hook_t *submit_bio_start, extent_submit_bio_hook_t *submit_bio_start,
extent_submit_bio_hook_t *submit_bio_done) extent_submit_bio_hook_t *submit_bio_done)
{ {
@ -592,6 +600,7 @@ int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct inode *inode,
async->work.flags = 0; async->work.flags = 0;
async->bio_flags = bio_flags; async->bio_flags = bio_flags;
async->bio_offset = bio_offset;
atomic_inc(&fs_info->nr_async_submits); atomic_inc(&fs_info->nr_async_submits);
@ -627,7 +636,8 @@ static int btree_csum_one_bio(struct bio *bio)
static int __btree_submit_bio_start(struct inode *inode, int rw, static int __btree_submit_bio_start(struct inode *inode, int rw,
struct bio *bio, int mirror_num, struct bio *bio, int mirror_num,
unsigned long bio_flags) unsigned long bio_flags,
u64 bio_offset)
{ {
/* /*
* when we're called for a write, we're already in the async * when we're called for a write, we're already in the async
@ -638,7 +648,8 @@ static int __btree_submit_bio_start(struct inode *inode, int rw,
} }
static int __btree_submit_bio_done(struct inode *inode, int rw, struct bio *bio, static int __btree_submit_bio_done(struct inode *inode, int rw, struct bio *bio,
int mirror_num, unsigned long bio_flags) int mirror_num, unsigned long bio_flags,
u64 bio_offset)
{ {
/* /*
* when we're called for a write, we're already in the async * when we're called for a write, we're already in the async
@ -648,7 +659,8 @@ static int __btree_submit_bio_done(struct inode *inode, int rw, struct bio *bio,
} }
static int btree_submit_bio_hook(struct inode *inode, int rw, struct bio *bio, static int btree_submit_bio_hook(struct inode *inode, int rw, struct bio *bio,
int mirror_num, unsigned long bio_flags) int mirror_num, unsigned long bio_flags,
u64 bio_offset)
{ {
int ret; int ret;
@ -671,6 +683,7 @@ static int btree_submit_bio_hook(struct inode *inode, int rw, struct bio *bio,
*/ */
return btrfs_wq_submit_bio(BTRFS_I(inode)->root->fs_info, return btrfs_wq_submit_bio(BTRFS_I(inode)->root->fs_info,
inode, rw, bio, mirror_num, 0, inode, rw, bio, mirror_num, 0,
bio_offset,
__btree_submit_bio_start, __btree_submit_bio_start,
__btree_submit_bio_done); __btree_submit_bio_done);
} }

View File

@ -87,7 +87,7 @@ int btrfs_bio_wq_end_io(struct btrfs_fs_info *info, struct bio *bio,
int metadata); int metadata);
int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct inode *inode, int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct inode *inode,
int rw, struct bio *bio, int mirror_num, int rw, struct bio *bio, int mirror_num,
unsigned long bio_flags, unsigned long bio_flags, u64 bio_offset,
extent_submit_bio_hook_t *submit_bio_start, extent_submit_bio_hook_t *submit_bio_start,
extent_submit_bio_hook_t *submit_bio_done); extent_submit_bio_hook_t *submit_bio_done);

View File

@ -1913,7 +1913,7 @@ static int submit_one_bio(int rw, struct bio *bio, int mirror_num,
if (tree->ops && tree->ops->submit_bio_hook) if (tree->ops && tree->ops->submit_bio_hook)
tree->ops->submit_bio_hook(page->mapping->host, rw, bio, tree->ops->submit_bio_hook(page->mapping->host, rw, bio,
mirror_num, bio_flags); mirror_num, bio_flags, start);
else else
submit_bio(rw, bio); submit_bio(rw, bio);
if (bio_flagged(bio, BIO_EOPNOTSUPP)) if (bio_flagged(bio, BIO_EOPNOTSUPP))

View File

@ -49,7 +49,7 @@ struct extent_state;
typedef int (extent_submit_bio_hook_t)(struct inode *inode, int rw, typedef int (extent_submit_bio_hook_t)(struct inode *inode, int rw,
struct bio *bio, int mirror_num, struct bio *bio, int mirror_num,
unsigned long bio_flags); unsigned long bio_flags, u64 bio_offset);
struct extent_io_ops { struct extent_io_ops {
int (*fill_delalloc)(struct inode *inode, struct page *locked_page, int (*fill_delalloc)(struct inode *inode, struct page *locked_page,
u64 start, u64 end, int *page_started, u64 start, u64 end, int *page_started,

View File

@ -1385,7 +1385,8 @@ int btrfs_merge_bio_hook(struct page *page, unsigned long offset,
*/ */
static int __btrfs_submit_bio_start(struct inode *inode, int rw, static int __btrfs_submit_bio_start(struct inode *inode, int rw,
struct bio *bio, int mirror_num, struct bio *bio, int mirror_num,
unsigned long bio_flags) unsigned long bio_flags,
u64 bio_offset)
{ {
struct btrfs_root *root = BTRFS_I(inode)->root; struct btrfs_root *root = BTRFS_I(inode)->root;
int ret = 0; int ret = 0;
@ -1404,7 +1405,8 @@ static int __btrfs_submit_bio_start(struct inode *inode, int rw,
* are inserted into the btree * are inserted into the btree
*/ */
static int __btrfs_submit_bio_done(struct inode *inode, int rw, struct bio *bio, static int __btrfs_submit_bio_done(struct inode *inode, int rw, struct bio *bio,
int mirror_num, unsigned long bio_flags) int mirror_num, unsigned long bio_flags,
u64 bio_offset)
{ {
struct btrfs_root *root = BTRFS_I(inode)->root; struct btrfs_root *root = BTRFS_I(inode)->root;
return btrfs_map_bio(root, rw, bio, mirror_num, 1); return btrfs_map_bio(root, rw, bio, mirror_num, 1);
@ -1415,7 +1417,8 @@ static int __btrfs_submit_bio_done(struct inode *inode, int rw, struct bio *bio,
* on write, or reading the csums from the tree before a read * on write, or reading the csums from the tree before a read
*/ */
static int btrfs_submit_bio_hook(struct inode *inode, int rw, struct bio *bio, static int btrfs_submit_bio_hook(struct inode *inode, int rw, struct bio *bio,
int mirror_num, unsigned long bio_flags) int mirror_num, unsigned long bio_flags,
u64 bio_offset)
{ {
struct btrfs_root *root = BTRFS_I(inode)->root; struct btrfs_root *root = BTRFS_I(inode)->root;
int ret = 0; int ret = 0;
@ -1440,7 +1443,8 @@ static int btrfs_submit_bio_hook(struct inode *inode, int rw, struct bio *bio,
/* we're doing a write, do the async checksumming */ /* we're doing a write, do the async checksumming */
return btrfs_wq_submit_bio(BTRFS_I(inode)->root->fs_info, return btrfs_wq_submit_bio(BTRFS_I(inode)->root->fs_info,
inode, rw, bio, mirror_num, inode, rw, bio, mirror_num,
bio_flags, __btrfs_submit_bio_start, bio_flags, bio_offset,
__btrfs_submit_bio_start,
__btrfs_submit_bio_done); __btrfs_submit_bio_done);
} }
@ -1844,7 +1848,7 @@ static int btrfs_io_failed_hook(struct bio *failed_bio,
BTRFS_I(inode)->io_tree.ops->submit_bio_hook(inode, rw, bio, BTRFS_I(inode)->io_tree.ops->submit_bio_hook(inode, rw, bio,
failrec->last_mirror, failrec->last_mirror,
failrec->bio_flags); failrec->bio_flags, 0);
return 0; return 0;
} }
@ -5484,6 +5488,17 @@ static void btrfs_endio_direct_write(struct bio *bio, int err)
dio_end_io(bio, err); dio_end_io(bio, err);
} }
static int __btrfs_submit_bio_start_direct_io(struct inode *inode, int rw,
struct bio *bio, int mirror_num,
unsigned long bio_flags, u64 offset)
{
int ret;
struct btrfs_root *root = BTRFS_I(inode)->root;
ret = btrfs_csum_one_bio(root, inode, bio, offset, 1);
BUG_ON(ret);
return 0;
}
static void btrfs_submit_direct(int rw, struct bio *bio, struct inode *inode, static void btrfs_submit_direct(int rw, struct bio *bio, struct inode *inode,
loff_t file_offset) loff_t file_offset)
{ {
@ -5535,13 +5550,20 @@ static void btrfs_submit_direct(int rw, struct bio *bio, struct inode *inode,
if (ret) if (ret)
goto out_err; goto out_err;
if (write && !skip_sum) if (write && !skip_sum) {
btrfs_csum_one_bio(root, inode, bio, dip->logical_offset, 1); ret = btrfs_wq_submit_bio(BTRFS_I(inode)->root->fs_info,
else if (!skip_sum) inode, rw, bio, 0, 0,
dip->logical_offset,
__btrfs_submit_bio_start_direct_io,
__btrfs_submit_bio_done);
if (ret)
goto out_err;
return;
} else if (!skip_sum)
btrfs_lookup_bio_sums_dio(root, inode, bio, btrfs_lookup_bio_sums_dio(root, inode, bio,
dip->logical_offset, dip->csums); dip->logical_offset, dip->csums);
ret = btrfs_map_bio(root, rw, bio, 0, 0); ret = btrfs_map_bio(root, rw, bio, 0, 1);
if (ret) if (ret)
goto out_err; goto out_err;
return; return;