All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] block: add sync_blockdev_range()
@ 2022-04-02  3:28 Yuezhang.Mo
  2022-04-04  4:52 ` Christoph Hellwig
  0 siblings, 1 reply; 5+ messages in thread
From: Yuezhang.Mo @ 2022-04-02  3:28 UTC (permalink / raw)
  To: Namjae Jeon, sj1557.seo
  Cc: linux-kernel, linux-fsdevel, Andy.Wu, Wataru.Aoyama, axboe,
	Christoph Hellwig

[-- Attachment #1: Type: text/plain, Size: 2038 bytes --]

sync_blockdev_range() is to support syncing multiple sectors
with as few block device requests as possible, it is helpful
to make the block device to give full play to its performance.

Signed-off-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
Suggested-by: Christoph Hellwig <hch@infradead.org>
Reviewed-by: Andy Wu <Andy.Wu@sony.com>
Reviewed-by: Aoyama Wataru <wataru.aoyama@sony.com>
cc: Jens Axboe <axboe@kernel.dk>
---
 block/bdev.c           | 10 ++++++++++
 include/linux/blkdev.h |  6 ++++++
 2 files changed, 16 insertions(+)

diff --git a/block/bdev.c b/block/bdev.c
index 102837a37051..57043e4f3322 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -200,6 +200,16 @@ int sync_blockdev(struct block_device *bdev)
 }
 EXPORT_SYMBOL(sync_blockdev);
 
+int sync_blockdev_range(struct block_device *bdev, loff_t lstart, loff_t lend)
+{
+	if (!bdev)
+		return 0;
+
+	return filemap_write_and_wait_range(bdev->bd_inode->i_mapping,
+			lstart, lend);
+}
+EXPORT_SYMBOL(sync_blockdev_range);
+
 /*
  * Write out and wait upon all dirty data associated with this
  * device.   Filesystem data as well as the underlying block
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 16b47035e4b0..1e85d0688d9c 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1310,6 +1310,7 @@ int truncate_bdev_range(struct block_device *bdev, fmode_t mode, loff_t lstart,
 #ifdef CONFIG_BLOCK
 void invalidate_bdev(struct block_device *bdev);
 int sync_blockdev(struct block_device *bdev);
+int sync_blockdev_range(struct block_device *bdev, loff_t lstart, loff_t lend);
 int sync_blockdev_nowait(struct block_device *bdev);
 void sync_bdevs(bool wait);
 #else
@@ -1320,6 +1321,11 @@ static inline int sync_blockdev(struct block_device *bdev)
 {
 	return 0;
 }
+static inline int sync_blockdev_range(struct block_device *bdev, loff_t lstart,
+		loff_t lend)
+{
+	return 0;
+}
 static inline int sync_blockdev_nowait(struct block_device *bdev)
 {
 	return 0;
-- 
2.25.1


[-- Attachment #2: v2-0001-block-add-sync_blockdev_range.patch --]
[-- Type: application/octet-stream, Size: 1976 bytes --]

sync_blockdev_range() is to support syncing multiple sectors
with as few block device requests as possible, it is helpful
to make the block device to give full play to its performance.

Signed-off-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
Suggested-by: Christoph Hellwig <hch@infradead.org>
Reviewed-by: Andy Wu <Andy.Wu@sony.com>
Reviewed-by: Aoyama Wataru <wataru.aoyama@sony.com>
cc: Jens Axboe <axboe@kernel.dk>
---
 block/bdev.c           | 10 ++++++++++
 include/linux/blkdev.h |  6 ++++++
 2 files changed, 16 insertions(+)

diff --git a/block/bdev.c b/block/bdev.c
index 102837a37051..57043e4f3322 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -200,6 +200,16 @@ int sync_blockdev(struct block_device *bdev)
 }
 EXPORT_SYMBOL(sync_blockdev);
 
+int sync_blockdev_range(struct block_device *bdev, loff_t lstart, loff_t lend)
+{
+	if (!bdev)
+		return 0;
+
+	return filemap_write_and_wait_range(bdev->bd_inode->i_mapping,
+			lstart, lend);
+}
+EXPORT_SYMBOL(sync_blockdev_range);
+
 /*
  * Write out and wait upon all dirty data associated with this
  * device.   Filesystem data as well as the underlying block
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 16b47035e4b0..1e85d0688d9c 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1310,6 +1310,7 @@ int truncate_bdev_range(struct block_device *bdev, fmode_t mode, loff_t lstart,
 #ifdef CONFIG_BLOCK
 void invalidate_bdev(struct block_device *bdev);
 int sync_blockdev(struct block_device *bdev);
+int sync_blockdev_range(struct block_device *bdev, loff_t lstart, loff_t lend);
 int sync_blockdev_nowait(struct block_device *bdev);
 void sync_bdevs(bool wait);
 #else
@@ -1320,6 +1321,11 @@ static inline int sync_blockdev(struct block_device *bdev)
 {
 	return 0;
 }
+static inline int sync_blockdev_range(struct block_device *bdev, loff_t lstart,
+		loff_t lend)
+{
+	return 0;
+}
 static inline int sync_blockdev_nowait(struct block_device *bdev)
 {
 	return 0;
-- 
2.25.1


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

* Re: [PATCH v2 1/2] block: add sync_blockdev_range()
  2022-04-02  3:28 [PATCH v2 1/2] block: add sync_blockdev_range() Yuezhang.Mo
@ 2022-04-04  4:52 ` Christoph Hellwig
  2022-04-06 10:21   ` Yuezhang.Mo
  0 siblings, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2022-04-04  4:52 UTC (permalink / raw)
  To: Yuezhang.Mo
  Cc: Namjae Jeon, sj1557.seo, linux-kernel, linux-fsdevel, Andy.Wu,
	Wataru.Aoyama, axboe, Christoph Hellwig

On Sat, Apr 02, 2022 at 03:28:00AM +0000, Yuezhang.Mo@sony.com wrote:
> sync_blockdev_range() is to support syncing multiple sectors
> with as few block device requests as possible, it is helpful
> to make the block device to give full play to its performance.
> 
> Signed-off-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
> Suggested-by: Christoph Hellwig <hch@infradead.org>
> Reviewed-by: Andy Wu <Andy.Wu@sony.com>
> Reviewed-by: Aoyama Wataru <wataru.aoyama@sony.com>
> cc: Jens Axboe <axboe@kernel.dk>
> ---
>  block/bdev.c           | 10 ++++++++++
>  include/linux/blkdev.h |  6 ++++++
>  2 files changed, 16 insertions(+)
> 
> diff --git a/block/bdev.c b/block/bdev.c
> index 102837a37051..57043e4f3322 100644
> --- a/block/bdev.c
> +++ b/block/bdev.c
> @@ -200,6 +200,16 @@ int sync_blockdev(struct block_device *bdev)
>  }
>  EXPORT_SYMBOL(sync_blockdev);
>  
> +int sync_blockdev_range(struct block_device *bdev, loff_t lstart, loff_t lend)
> +{
> +	if (!bdev)
> +		return 0;

This check isn't really needed, and I don't think we need a
!CONFIG_BLOCK stub for this either.

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

* RE: [PATCH v2 1/2] block: add sync_blockdev_range()
  2022-04-04  4:52 ` Christoph Hellwig
@ 2022-04-06 10:21   ` Yuezhang.Mo
  2022-04-07  8:11     ` Christoph Hellwig
  0 siblings, 1 reply; 5+ messages in thread
From: Yuezhang.Mo @ 2022-04-06 10:21 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Namjae Jeon, sj1557.seo, linux-kernel, linux-fsdevel, Andy.Wu,
	Wataru.Aoyama, axboe

> From: Christoph Hellwig <hch@infradead.org>
> > --- a/block/bdev.c
> > +++ b/block/bdev.c
> > @@ -200,6 +200,16 @@ int sync_blockdev(struct block_device *bdev)  }
> > EXPORT_SYMBOL(sync_blockdev);
> >
> > +int sync_blockdev_range(struct block_device *bdev, loff_t lstart,
> > +loff_t lend) {
> > +	if (!bdev)
> > +		return 0;
> 
> This check isn't really needed, and I don't think we need a !CONFIG_BLOCK
> stub for this either.

sync_blockdev() and related helpers have this check and a !CONFIG_BLOCK stub.
I would like to understand the background of your comment, could you explain a little more?

Thanks.

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

* Re: [PATCH v2 1/2] block: add sync_blockdev_range()
  2022-04-06 10:21   ` Yuezhang.Mo
@ 2022-04-07  8:11     ` Christoph Hellwig
  2022-04-08  2:29       ` Yuezhang.Mo
  0 siblings, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2022-04-07  8:11 UTC (permalink / raw)
  To: Yuezhang.Mo
  Cc: Christoph Hellwig, Namjae Jeon, sj1557.seo, linux-kernel,
	linux-fsdevel, Andy.Wu, Wataru.Aoyama, axboe

On Wed, Apr 06, 2022 at 10:21:15AM +0000, Yuezhang.Mo@sony.com wrote:
> > From: Christoph Hellwig <hch@infradead.org>
> > > --- a/block/bdev.c
> > > +++ b/block/bdev.c
> > > @@ -200,6 +200,16 @@ int sync_blockdev(struct block_device *bdev)  }
> > > EXPORT_SYMBOL(sync_blockdev);
> > >
> > > +int sync_blockdev_range(struct block_device *bdev, loff_t lstart,
> > > +loff_t lend) {
> > > +	if (!bdev)
> > > +		return 0;
> > 
> > This check isn't really needed, and I don't think we need a !CONFIG_BLOCK
> > stub for this either.
> 
> sync_blockdev() and related helpers have this check and a !CONFIG_BLOCK stub.
> I would like to understand the background of your comment, could you explain a little more?

sync_blockdev and sync_blockdev do that because they are unconditionally
called from sync_filesystem, and not just from block-dependent code.
Eventually that should be cleaned up as well, but please don't add it to
new code.

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

* RE: [PATCH v2 1/2] block: add sync_blockdev_range()
  2022-04-07  8:11     ` Christoph Hellwig
@ 2022-04-08  2:29       ` Yuezhang.Mo
  0 siblings, 0 replies; 5+ messages in thread
From: Yuezhang.Mo @ 2022-04-08  2:29 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Namjae Jeon, sj1557.seo, linux-kernel, linux-fsdevel, Andy.Wu,
	Wataru.Aoyama, axboe

> From: Christoph Hellwig <hch@infradead.org>
> > > This check isn't really needed, and I don't think we need a
> > > !CONFIG_BLOCK stub for this either.
> >
> > sync_blockdev() and related helpers have this check and a !CONFIG_BLOCK
> stub.
> > I would like to understand the background of your comment, could you
> explain a little more?
> 
> sync_blockdev and sync_blockdev do that because they are unconditionally
> called from sync_filesystem, and not just from block-dependent code.
> Eventually that should be cleaned up as well, but please don't add it to new
> code.

Thank you for your explanation.
I will update the patch to remove the check and the !CONFIG_BLOCK stub.

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

end of thread, other threads:[~2022-04-08  2:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-02  3:28 [PATCH v2 1/2] block: add sync_blockdev_range() Yuezhang.Mo
2022-04-04  4:52 ` Christoph Hellwig
2022-04-06 10:21   ` Yuezhang.Mo
2022-04-07  8:11     ` Christoph Hellwig
2022-04-08  2:29       ` Yuezhang.Mo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.