* [PATCH v2] Btrfs: add readahead for send_write
@ 2014-03-03 9:24 Liu Bo
2014-03-03 14:25 ` David Sterba
0 siblings, 1 reply; 4+ messages in thread
From: Liu Bo @ 2014-03-03 9:24 UTC (permalink / raw)
To: linux-btrfs
Btrfs send reads data from disk and then writes to a stream via pipe or
a file via flush.
Currently we're going to read each page at a time, so every page results
in a disk read, which is not friendly to disks, esp. HDD. Given that,
the performance can be gained by adding readahead for those pages.
Here is a quick test:
$ btrfs subvolume create send
$ xfs_io -f -c "pwrite 0 1G" send/foobar
$ btrfs subvolume snap -r send ro
$ time "btrfs send ro -f /dev/null"
w/o w
real 1m37.527s 0m9.097s
user 0m0.122s 0m0.086s
sys 0m53.191s 0m12.857s
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
v1->v2: return ENOMEM on failing to allocate memory.
fs/btrfs/send.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index 9dde971..d55faa7 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -3972,6 +3972,7 @@ static ssize_t fill_read_buf(struct send_ctx *sctx, u64 offset, u32 len)
pgoff_t last_index;
unsigned pg_offset = offset & ~PAGE_CACHE_MASK;
ssize_t ret = 0;
+ struct file_ra_state *ra = NULL;
key.objectid = sctx->cur_ino;
key.type = BTRFS_INODE_ITEM_KEY;
@@ -3991,6 +3992,17 @@ static ssize_t fill_read_buf(struct send_ctx *sctx, u64 offset, u32 len)
goto out;
last_index = (offset + len - 1) >> PAGE_CACHE_SHIFT;
+
+ /* initial readahead */
+ ra = kzalloc(sizeof(*ra), GFP_NOFS);
+ if (!ra) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ file_ra_state_init(ra, inode->i_mapping);
+ btrfs_force_ra(inode->i_mapping, ra, NULL, index, last_index-index + 1);
+
while (index <= last_index) {
unsigned cur_len = min_t(unsigned, len,
PAGE_CACHE_SIZE - pg_offset);
@@ -4022,6 +4034,7 @@ static ssize_t fill_read_buf(struct send_ctx *sctx, u64 offset, u32 len)
ret += cur_len;
}
out:
+ kfree(ra);
iput(inode);
return ret;
}
--
1.8.1.4
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v2] Btrfs: add readahead for send_write
2014-03-03 9:24 [PATCH v2] Btrfs: add readahead for send_write Liu Bo
@ 2014-03-03 14:25 ` David Sterba
2014-03-04 2:49 ` Liu Bo
0 siblings, 1 reply; 4+ messages in thread
From: David Sterba @ 2014-03-03 14:25 UTC (permalink / raw)
To: Liu Bo; +Cc: linux-btrfs
On Mon, Mar 03, 2014 at 05:24:43PM +0800, Liu Bo wrote:
> --- a/fs/btrfs/send.c
> +++ b/fs/btrfs/send.c
> @@ -3972,6 +3972,7 @@ static ssize_t fill_read_buf(struct send_ctx *sctx, u64 offset, u32 len)
> pgoff_t last_index;
> unsigned pg_offset = offset & ~PAGE_CACHE_MASK;
> ssize_t ret = 0;
> + struct file_ra_state *ra = NULL;
>
> key.objectid = sctx->cur_ino;
> key.type = BTRFS_INODE_ITEM_KEY;
> @@ -3991,6 +3992,17 @@ static ssize_t fill_read_buf(struct send_ctx *sctx, u64 offset, u32 len)
> goto out;
>
> last_index = (offset + len - 1) >> PAGE_CACHE_SHIFT;
> +
> + /* initial readahead */
> + ra = kzalloc(sizeof(*ra), GFP_NOFS);
> + if (!ra) {
> + ret = -ENOMEM;
This should not be a hard failure, it can continue without RA for this
buffer. Besides, the RA buffer can be allocated at the beginning of send
operation and pointer stored in the send context.
> + goto out;
> + }
> +
> + file_ra_state_init(ra, inode->i_mapping);
> + btrfs_force_ra(inode->i_mapping, ra, NULL, index, last_index-index + 1);
> +
> while (index <= last_index) {
> unsigned cur_len = min_t(unsigned, len,
> PAGE_CACHE_SIZE - pg_offset);
> @@ -4022,6 +4034,7 @@ static ssize_t fill_read_buf(struct send_ctx *sctx, u64 offset, u32 len)
> ret += cur_len;
> }
> out:
> + kfree(ra);
> iput(inode);
> return ret;
> }
> --
> 1.8.1.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v2] Btrfs: add readahead for send_write
2014-03-03 14:25 ` David Sterba
@ 2014-03-04 2:49 ` Liu Bo
2014-03-04 12:31 ` David Sterba
0 siblings, 1 reply; 4+ messages in thread
From: Liu Bo @ 2014-03-04 2:49 UTC (permalink / raw)
To: dsterba; +Cc: linux-btrfs
On Mon, Mar 03, 2014 at 03:25:28PM +0100, David Sterba wrote:
> On Mon, Mar 03, 2014 at 05:24:43PM +0800, Liu Bo wrote:
> > --- a/fs/btrfs/send.c
> > +++ b/fs/btrfs/send.c
> > @@ -3972,6 +3972,7 @@ static ssize_t fill_read_buf(struct send_ctx *sctx, u64 offset, u32 len)
> > pgoff_t last_index;
> > unsigned pg_offset = offset & ~PAGE_CACHE_MASK;
> > ssize_t ret = 0;
> > + struct file_ra_state *ra = NULL;
> >
> > key.objectid = sctx->cur_ino;
> > key.type = BTRFS_INODE_ITEM_KEY;
> > @@ -3991,6 +3992,17 @@ static ssize_t fill_read_buf(struct send_ctx *sctx, u64 offset, u32 len)
> > goto out;
> >
> > last_index = (offset + len - 1) >> PAGE_CACHE_SHIFT;
> > +
> > + /* initial readahead */
> > + ra = kzalloc(sizeof(*ra), GFP_NOFS);
> > + if (!ra) {
> > + ret = -ENOMEM;
>
> This should not be a hard failure, it can continue without RA for this
> buffer. Besides, the RA buffer can be allocated at the beginning of send
> operation and pointer stored in the send context.
Good point, I think we can fold this into 'struct send_ctx', do you agree?
Thanks,
-liubo
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v2] Btrfs: add readahead for send_write
2014-03-04 2:49 ` Liu Bo
@ 2014-03-04 12:31 ` David Sterba
0 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2014-03-04 12:31 UTC (permalink / raw)
To: Liu Bo; +Cc: linux-btrfs
On Tue, Mar 04, 2014 at 10:49:52AM +0800, Liu Bo wrote:
> On Mon, Mar 03, 2014 at 03:25:28PM +0100, David Sterba wrote:
> > This should not be a hard failure, it can continue without RA for this
> > buffer. Besides, the RA buffer can be allocated at the beginning of send
> > operation and pointer stored in the send context.
>
> Good point, I think we can fold this into 'struct send_ctx', do you agree?
Sure, size of send_ctx + readahead state will remain below 512.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-03-04 12:31 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-03 9:24 [PATCH v2] Btrfs: add readahead for send_write Liu Bo
2014-03-03 14:25 ` David Sterba
2014-03-04 2:49 ` Liu Bo
2014-03-04 12:31 ` David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox