linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Btrfs: set plug for fsync
@ 2017-11-10  0:16 Liu Bo
  2017-11-13 17:00 ` David Sterba
  2017-11-15 23:10 ` [PATCH v2] " Liu Bo
  0 siblings, 2 replies; 4+ messages in thread
From: Liu Bo @ 2017-11-10  0:16 UTC (permalink / raw)
  To: linux-btrfs

Setting plug can merge adjacent IOs before dispatching IOs to the disk
driver.

Without plug, it'd not be a problem for single disk usecases, but for
multiple disks using raid profile, a large IO can be split to several
IOs of stripe length, and plug can be helpful to bring them together
for each disk so that we can save several disk access.

Moreover, fsync issues synchronous writes, so plug can really take
effect.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
 fs/btrfs/file.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index e43da6c..063180b 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -2018,10 +2018,13 @@ int btrfs_release_file(struct inode *inode, struct file *filp)
 static int start_ordered_ops(struct inode *inode, loff_t start, loff_t end)
 {
 	int ret;
+	struct blk_plug plug;
 
+	blk_start_plug(&plug);
 	atomic_inc(&BTRFS_I(inode)->sync_writers);
 	ret = btrfs_fdatawrite_range(inode, start, end);
 	atomic_dec(&BTRFS_I(inode)->sync_writers);
+	blk_finish_plug(&plug);
 
 	return ret;
 }
-- 
2.9.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Btrfs: set plug for fsync
  2017-11-10  0:16 [PATCH] Btrfs: set plug for fsync Liu Bo
@ 2017-11-13 17:00 ` David Sterba
  2017-11-15 23:10 ` [PATCH v2] " Liu Bo
  1 sibling, 0 replies; 4+ messages in thread
From: David Sterba @ 2017-11-13 17:00 UTC (permalink / raw)
  To: Liu Bo; +Cc: linux-btrfs

On Thu, Nov 09, 2017 at 05:16:16PM -0700, Liu Bo wrote:
> Setting plug can merge adjacent IOs before dispatching IOs to the disk
> driver.
> 
> Without plug, it'd not be a problem for single disk usecases, but for
> multiple disks using raid profile, a large IO can be split to several
> IOs of stripe length, and plug can be helpful to bring them together
> for each disk so that we can save several disk access.
> 
> Moreover, fsync issues synchronous writes, so plug can really take
> effect.
> 
> Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
> ---
>  fs/btrfs/file.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
> index e43da6c..063180b 100644
> --- a/fs/btrfs/file.c
> +++ b/fs/btrfs/file.c
> @@ -2018,10 +2018,13 @@ int btrfs_release_file(struct inode *inode, struct file *filp)
>  static int start_ordered_ops(struct inode *inode, loff_t start, loff_t end)
>  {
>  	int ret;
> +	struct blk_plug plug;
>  
> +	blk_start_plug(&plug);

Can you please add a comment here? Essentially repeating the commit
message. The plug/unplug calls are never obvious so the expectations
could be documented.

>  	atomic_inc(&BTRFS_I(inode)->sync_writers);
>  	ret = btrfs_fdatawrite_range(inode, start, end);
>  	atomic_dec(&BTRFS_I(inode)->sync_writers);
> +	blk_finish_plug(&plug);
>  
>  	return ret;
>  }
> -- 
> 2.9.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

* [PATCH v2] Btrfs: set plug for fsync
  2017-11-10  0:16 [PATCH] Btrfs: set plug for fsync Liu Bo
  2017-11-13 17:00 ` David Sterba
@ 2017-11-15 23:10 ` Liu Bo
  2017-11-20 17:14   ` David Sterba
  1 sibling, 1 reply; 4+ messages in thread
From: Liu Bo @ 2017-11-15 23:10 UTC (permalink / raw)
  To: linux-btrfs

Setting plug can merge adjacent IOs before dispatching IOs to the disk
driver.

Without plug, it'd not be a problem for single disk usecases, but for
multiple disks using raid profile, a large IO can be split to several
IOs of stripe length, and plug can be helpful to bring them together
for each disk so that we can save several disk access.

Moreover, fsync issues synchronous writes, so plug can really take
effect.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
v2: Explain why setting plug makes sense.

 fs/btrfs/file.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index e43da6c..504e96d 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -2018,10 +2018,20 @@ int btrfs_release_file(struct inode *inode, struct file *filp)
 static int start_ordered_ops(struct inode *inode, loff_t start, loff_t end)
 {
 	int ret;
+	struct blk_plug plug;
 
+	/*
+	 * This is only called in fsync, which would do synchronous
+	 * writes, so a plug can merge adjacent IOs as much as
+	 * possible.  Esp. in case of multiple disks using raid
+	 * profile, a large IO can be split to several segments of
+	 * stripe length(64K).
+	 */
+	blk_start_plug(&plug);
 	atomic_inc(&BTRFS_I(inode)->sync_writers);
 	ret = btrfs_fdatawrite_range(inode, start, end);
 	atomic_dec(&BTRFS_I(inode)->sync_writers);
+	blk_finish_plug(&plug);
 
 	return ret;
 }
-- 
2.9.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] Btrfs: set plug for fsync
  2017-11-15 23:10 ` [PATCH v2] " Liu Bo
@ 2017-11-20 17:14   ` David Sterba
  0 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2017-11-20 17:14 UTC (permalink / raw)
  To: Liu Bo; +Cc: linux-btrfs

On Wed, Nov 15, 2017 at 04:10:28PM -0700, Liu Bo wrote:
> Setting plug can merge adjacent IOs before dispatching IOs to the disk
> driver.
> 
> Without plug, it'd not be a problem for single disk usecases, but for
> multiple disks using raid profile, a large IO can be split to several
> IOs of stripe length, and plug can be helpful to bring them together
> for each disk so that we can save several disk access.
> 
> Moreover, fsync issues synchronous writes, so plug can really take
> effect.
> 
> Signed-off-by: Liu Bo <bo.li.liu@oracle.com>

Reviewed-by: David Sterba <dsterba@suse.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-11-20 17:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-10  0:16 [PATCH] Btrfs: set plug for fsync Liu Bo
2017-11-13 17:00 ` David Sterba
2017-11-15 23:10 ` [PATCH v2] " Liu Bo
2017-11-20 17:14   ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).