linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
	Ming Lei <ming.lei@redhat.com>
Subject: [PATCH 6/8] loop: relax loop dio use condition
Date: Mon, 25 Oct 2021 17:44:35 +0800	[thread overview]
Message-ID: <20211025094437.2837701-7-ming.lei@redhat.com> (raw)
In-Reply-To: <20211025094437.2837701-1-ming.lei@redhat.com>

So far loop dio requires the following conditions:

1) lo->lo_offset is aligned with backing queue's logical block size

2) loop queue's logical block size is <= backing queue's logical block
   size

We have supported to fallback to buffered IO, so unaligned IO can't be
completed successfully.

Also the current usage wrt. loop queue's logical block size is hardly
to work as expected, set dio and updating logical block size are done
in different ioctls, and logical block size is often set before setting
direct io. Relaxing dio use in this way won't cause real effect in
reality.

Then we needn't to freeze queue any more when updating dio since loop
IO can be done successfully with the fallback buffered io.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 drivers/block/loop.c | 36 +-----------------------------------
 1 file changed, 1 insertion(+), 35 deletions(-)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index fee78a640f75..f42630246758 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -215,31 +215,10 @@ static void __loop_update_dio(struct loop_device *lo, bool dio)
 {
 	struct file *file = lo->lo_backing_file;
 	struct address_space *mapping = file->f_mapping;
-	struct inode *inode = mapping->host;
-	unsigned short sb_bsize = 0;
-	unsigned dio_align = 0;
 	bool use_dio;
 
-	if (inode->i_sb->s_bdev) {
-		sb_bsize = bdev_logical_block_size(inode->i_sb->s_bdev);
-		dio_align = sb_bsize - 1;
-	}
-
-	/*
-	 * We support direct I/O only if lo_offset is aligned with the
-	 * logical I/O size of backing device, and the logical block
-	 * size of loop is bigger than the backing device's and the loop
-	 * needn't transform transfer.
-	 *
-	 * TODO: the above condition may be loosed in the future, and
-	 * direct I/O may be switched runtime at that time because most
-	 * of requests in sane applications should be PAGE_SIZE aligned
-	 */
 	if (dio) {
-		if (queue_logical_block_size(lo->lo_queue) >= sb_bsize &&
-				!(lo->lo_offset & dio_align) &&
-				mapping->a_ops->direct_IO &&
-				!lo->transfer)
+		if (mapping->a_ops->direct_IO && !lo->transfer)
 			use_dio = true;
 		else
 			use_dio = false;
@@ -253,13 +232,6 @@ static void __loop_update_dio(struct loop_device *lo, bool dio)
 	/* flush dirty pages before changing direct IO */
 	vfs_fsync(file, 0);
 
-	/*
-	 * The flag of LO_FLAGS_DIRECT_IO is handled similarly with
-	 * LO_FLAGS_READ_ONLY, both are set from kernel, and losetup
-	 * will get updated by ioctl(LOOP_GET_STATUS)
-	 */
-	if (lo->lo_state == Lo_bound)
-		blk_mq_freeze_queue(lo->lo_queue);
 	lo->use_dio = use_dio;
 	if (use_dio) {
 		blk_queue_flag_clear(QUEUE_FLAG_NOMERGES, lo->lo_queue);
@@ -268,8 +240,6 @@ static void __loop_update_dio(struct loop_device *lo, bool dio)
 		blk_queue_flag_set(QUEUE_FLAG_NOMERGES, lo->lo_queue);
 		lo->lo_flags &= ~LO_FLAGS_DIRECT_IO;
 	}
-	if (lo->lo_state == Lo_bound)
-		blk_mq_unfreeze_queue(lo->lo_queue);
 }
 
 /**
@@ -1248,9 +1218,6 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
 
 	if (config->block_size)
 		bsize = config->block_size;
-	else if ((lo->lo_backing_file->f_flags & O_DIRECT) && inode->i_sb->s_bdev)
-		/* In case of direct I/O, match underlying block size */
-		bsize = bdev_logical_block_size(inode->i_sb->s_bdev);
 	else
 		bsize = 512;
 
@@ -1753,7 +1720,6 @@ static int loop_set_block_size(struct loop_device *lo, unsigned long arg)
 	blk_queue_logical_block_size(lo->lo_queue, arg);
 	blk_queue_physical_block_size(lo->lo_queue, arg);
 	blk_queue_io_min(lo->lo_queue, arg);
-	loop_update_dio(lo);
 out_unfreeze:
 	blk_mq_unfreeze_queue(lo->lo_queue);
 
-- 
2.31.1


  parent reply	other threads:[~2021-10-25  9:47 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-25  9:44 [PATCH 0/8] loop: improve dio on backing file Ming Lei
2021-10-25  9:44 ` [PATCH 1/8] loop: move flush_dcache_page to ->complete of request Ming Lei
2021-10-26  7:21   ` Christoph Hellwig
2021-10-25  9:44 ` [PATCH 2/8] loop: remove always true check Ming Lei
2021-10-26  7:31   ` Christoph Hellwig
2021-10-25  9:44 ` [PATCH 3/8] loop: add one helper for submitting IO on backing file Ming Lei
2021-10-25  9:44 ` [PATCH 4/8] loop: cover simple read/write via lo_rw_aio() Ming Lei
2021-10-26  7:35   ` Christoph Hellwig
2021-10-25  9:44 ` [PATCH 5/8] loop: fallback to buffered IO in case of dio submission Ming Lei
2021-10-26  7:36   ` Christoph Hellwig
2021-10-25  9:44 ` Ming Lei [this message]
2021-10-26  7:37   ` [PATCH 6/8] loop: relax loop dio use condition Christoph Hellwig
2021-10-27  0:20   ` kernel test robot
2021-10-25  9:44 ` [PATCH 7/8] loop: remove lo->use_dio Ming Lei
2021-10-25  9:44 ` [RFC PATCH 8/8] loop: use backing dio at default Ming Lei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211025094437.2837701-7-ming.lei@redhat.com \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).