linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/8] loop: improve dio on backing file
@ 2021-10-25  9:44 Ming Lei
  2021-10-25  9:44 ` [PATCH 1/8] loop: move flush_dcache_page to ->complete of request Ming Lei
                   ` (7 more replies)
  0 siblings, 8 replies; 15+ messages in thread
From: Ming Lei @ 2021-10-25  9:44 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, Christoph Hellwig, Ming Lei

Hello,

Improve dio on backing file:

1) cover simple read/write via aio style(lo_rw_aio)

2) fallback to buffered io in case of dio failure

3) relax dio use condition and not check if lo->lo_offset & loop queue's
bs is aligned with backing queue

4) enable backing dio at default(RFC)


Ming Lei (8):
  loop: move flush_dcache_page to ->complete of request
  loop: remove always true check
  loop: add one helper for submitting IO on backing file
  loop: cover simple read/write via lo_rw_aio()
  loop: fallback to buffered IO in case of dio submission
  loop: relax loop dio use condition
  loop: remove lo->use_dio
  loop: use backing dio at default

 drivers/block/loop.c | 182 +++++++++++++------------------------------
 drivers/block/loop.h |   2 +-
 2 files changed, 57 insertions(+), 127 deletions(-)

-- 
2.31.1


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

* [PATCH 1/8] loop: move flush_dcache_page to ->complete of request
  2021-10-25  9:44 [PATCH 0/8] loop: improve dio on backing file Ming Lei
@ 2021-10-25  9:44 ` Ming Lei
  2021-10-26  7:21   ` Christoph Hellwig
  2021-10-25  9:44 ` [PATCH 2/8] loop: remove always true check Ming Lei
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 15+ messages in thread
From: Ming Lei @ 2021-10-25  9:44 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, Christoph Hellwig, Ming Lei

Prepare for unifying backing buffered IO code, so move
flush_dcache_page() into ->complete() of read request.

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

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 7bf4686af774..8f140d637435 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -405,8 +405,6 @@ static int lo_read_simple(struct loop_device *lo, struct request *rq,
 		if (len < 0)
 			return len;
 
-		flush_dcache_page(bvec.bv_page);
-
 		if (len != bvec.bv_len) {
 			struct bio *bio;
 
@@ -507,11 +505,24 @@ static int lo_req_flush(struct loop_device *lo, struct request *rq)
 	return ret;
 }
 
+static void lo_flush_dcache_for_read(struct request *rq)
+{
+	struct bio_vec bvec;
+	struct req_iterator iter;
+
+	rq_for_each_segment(bvec, rq, iter)
+		flush_dcache_page(bvec.bv_page);
+}
+
 static void lo_complete_rq(struct request *rq)
 {
 	struct loop_cmd *cmd = blk_mq_rq_to_pdu(rq);
 	blk_status_t ret = BLK_STS_OK;
 
+	/* Kernel wrote to our pages, call flush_dcache_page */
+	if (req_op(rq) == REQ_OP_READ && !cmd->use_aio && cmd->ret >= 0)
+		lo_flush_dcache_for_read(rq);
+
 	if (!cmd->use_aio || cmd->ret < 0 || cmd->ret == blk_rq_bytes(rq) ||
 	    req_op(rq) != REQ_OP_READ) {
 		if (cmd->ret < 0)
-- 
2.31.1


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

* [PATCH 2/8] loop: remove always true check
  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-25  9:44 ` 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
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 15+ messages in thread
From: Ming Lei @ 2021-10-25  9:44 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, Christoph Hellwig, Ming Lei

In lo_complete_rq(), in case of !cmd->use_aio, we simply call
blk_mq_end_request(), so the check of cmd->use_aio isn't necessary,
since it is always true when the check is run.

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

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 8f140d637435..8c3f5d2affc7 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -539,13 +539,11 @@ static void lo_complete_rq(struct request *rq)
 		cmd->ret = 0;
 		blk_mq_requeue_request(rq, true);
 	} else {
-		if (cmd->use_aio) {
-			struct bio *bio = rq->bio;
+		struct bio *bio = rq->bio;
 
-			while (bio) {
-				zero_fill_bio(bio);
-				bio = bio->bi_next;
-			}
+		while (bio) {
+			zero_fill_bio(bio);
+			bio = bio->bi_next;
 		}
 		ret = BLK_STS_IOERR;
 end_io:
-- 
2.31.1


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

* [PATCH 3/8] loop: add one helper for submitting IO on backing file
  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-25  9:44 ` [PATCH 2/8] loop: remove always true check Ming Lei
@ 2021-10-25  9:44 ` Ming Lei
  2021-10-25  9:44 ` [PATCH 4/8] loop: cover simple read/write via lo_rw_aio() Ming Lei
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 15+ messages in thread
From: Ming Lei @ 2021-10-25  9:44 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, Christoph Hellwig, Ming Lei

No functional change, new helper is added so that we can unifying buffered
IO on backing file.

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

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 8c3f5d2affc7..769cf84c6899 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -571,6 +571,14 @@ static void lo_rw_aio_complete(struct kiocb *iocb, long ret, long ret2)
 	lo_rw_aio_do_completion(cmd);
 }
 
+static inline int lo_call_backing_rw_iter(struct file *file,
+		struct kiocb *iocb, struct iov_iter *iter, bool rw)
+{
+	if (rw == WRITE)
+		return call_write_iter(file, iocb, iter);
+	return call_read_iter(file, iocb, iter);
+}
+
 static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
 		     loff_t pos, bool rw)
 {
@@ -628,10 +636,7 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
 	cmd->iocb.ki_flags = IOCB_DIRECT;
 	cmd->iocb.ki_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0);
 
-	if (rw == WRITE)
-		ret = call_write_iter(file, &cmd->iocb, &iter);
-	else
-		ret = call_read_iter(file, &cmd->iocb, &iter);
+	ret = lo_call_backing_rw_iter(file, &cmd->iocb, &iter, rw);
 
 	lo_rw_aio_do_completion(cmd);
 
-- 
2.31.1


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

* [PATCH 4/8] loop: cover simple read/write via lo_rw_aio()
  2021-10-25  9:44 [PATCH 0/8] loop: improve dio on backing file Ming Lei
                   ` (2 preceding siblings ...)
  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 ` 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
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 15+ messages in thread
From: Ming Lei @ 2021-10-25  9:44 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, Christoph Hellwig, Ming Lei

lo_rw_aio() is capable of doing simple buffered read/write, not
necessary to use lo_simple_read()/lo_simple_write() for that.

Add cmd->use_dio for real loop dio, then cmd->use_aio is only used
in case that lo_rw_aio() is used for submitting IO against backing file.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 drivers/block/loop.c | 83 +++++++++-----------------------------------
 drivers/block/loop.h |  1 +
 2 files changed, 18 insertions(+), 66 deletions(-)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 769cf84c6899..d1784f825b6b 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -339,23 +339,6 @@ static int lo_write_bvec(struct file *file, struct bio_vec *bvec, loff_t *ppos)
 	return bw;
 }
 
-static int lo_write_simple(struct loop_device *lo, struct request *rq,
-		loff_t pos)
-{
-	struct bio_vec bvec;
-	struct req_iterator iter;
-	int ret = 0;
-
-	rq_for_each_segment(bvec, rq, iter) {
-		ret = lo_write_bvec(lo->lo_backing_file, &bvec, &pos);
-		if (ret < 0)
-			break;
-		cond_resched();
-	}
-
-	return ret;
-}
-
 /*
  * This is the slow, transforming version that needs to double buffer the
  * data as it cannot do the transformations in place without having direct
@@ -391,33 +374,6 @@ static int lo_write_transfer(struct loop_device *lo, struct request *rq,
 	return ret;
 }
 
-static int lo_read_simple(struct loop_device *lo, struct request *rq,
-		loff_t pos)
-{
-	struct bio_vec bvec;
-	struct req_iterator iter;
-	struct iov_iter i;
-	ssize_t len;
-
-	rq_for_each_segment(bvec, rq, iter) {
-		iov_iter_bvec(&i, READ, &bvec, 1, bvec.bv_len);
-		len = vfs_iter_read(lo->lo_backing_file, &i, &pos, 0);
-		if (len < 0)
-			return len;
-
-		if (len != bvec.bv_len) {
-			struct bio *bio;
-
-			__rq_for_each_bio(bio, rq)
-				zero_fill_bio(bio);
-			break;
-		}
-		cond_resched();
-	}
-
-	return 0;
-}
-
 static int lo_read_transfer(struct loop_device *lo, struct request *rq,
 		loff_t pos)
 {
@@ -520,10 +476,10 @@ static void lo_complete_rq(struct request *rq)
 	blk_status_t ret = BLK_STS_OK;
 
 	/* Kernel wrote to our pages, call flush_dcache_page */
-	if (req_op(rq) == REQ_OP_READ && !cmd->use_aio && cmd->ret >= 0)
+	if (req_op(rq) == REQ_OP_READ && !cmd->use_dio && cmd->ret >= 0)
 		lo_flush_dcache_for_read(rq);
 
-	if (!cmd->use_aio || cmd->ret < 0 || cmd->ret == blk_rq_bytes(rq) ||
+	if (!cmd->use_dio || cmd->ret < 0 || cmd->ret == blk_rq_bytes(rq) ||
 	    req_op(rq) != REQ_OP_READ) {
 		if (cmd->ret < 0)
 			ret = errno_to_blk_status(cmd->ret);
@@ -625,17 +581,24 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
 		offset = bio->bi_iter.bi_bvec_done;
 		bvec = __bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter);
 	}
-	atomic_set(&cmd->ref, 2);
-
 	iov_iter_bvec(&iter, rw, bvec, nr_bvec, blk_rq_bytes(rq));
 	iter.iov_offset = offset;
 
 	cmd->iocb.ki_pos = pos;
 	cmd->iocb.ki_filp = file;
-	cmd->iocb.ki_complete = lo_rw_aio_complete;
-	cmd->iocb.ki_flags = IOCB_DIRECT;
+
 	cmd->iocb.ki_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0);
+	if (!cmd->use_dio) {
+		atomic_set(&cmd->ref, 1);
+		cmd->iocb.ki_flags = 0;
+		cmd->ret = lo_call_backing_rw_iter(file, &cmd->iocb, &iter, rw);
+		lo_rw_aio_do_completion(cmd);
+		return 0;
+	}
 
+	atomic_set(&cmd->ref, 2);
+	cmd->iocb.ki_complete = lo_rw_aio_complete;
+	cmd->iocb.ki_flags = IOCB_DIRECT;
 	ret = lo_call_backing_rw_iter(file, &cmd->iocb, &iter, rw);
 
 	lo_rw_aio_do_completion(cmd);
@@ -650,15 +613,6 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq)
 	struct loop_cmd *cmd = blk_mq_rq_to_pdu(rq);
 	loff_t pos = ((loff_t) blk_rq_pos(rq) << 9) + lo->lo_offset;
 
-	/*
-	 * lo_write_simple and lo_read_simple should have been covered
-	 * by io submit style function like lo_rw_aio(), one blocker
-	 * is that lo_read_simple() need to call flush_dcache_page after
-	 * the page is written from kernel, and it isn't easy to handle
-	 * this in io submit style function which submits all segments
-	 * of the req at one time. And direct read IO doesn't need to
-	 * run flush_dcache_page().
-	 */
 	switch (req_op(rq)) {
 	case REQ_OP_FLUSH:
 		return lo_req_flush(lo, rq);
@@ -676,17 +630,13 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq)
 	case REQ_OP_WRITE:
 		if (lo->transfer)
 			return lo_write_transfer(lo, rq, pos);
-		else if (cmd->use_aio)
-			return lo_rw_aio(lo, cmd, pos, WRITE);
 		else
-			return lo_write_simple(lo, rq, pos);
+			return lo_rw_aio(lo, cmd, pos, WRITE);
 	case REQ_OP_READ:
 		if (lo->transfer)
 			return lo_read_transfer(lo, rq, pos);
-		else if (cmd->use_aio)
-			return lo_rw_aio(lo, cmd, pos, READ);
 		else
-			return lo_read_simple(lo, rq, pos);
+			return lo_rw_aio(lo, cmd, pos, READ);
 	default:
 		WARN_ON_ONCE(1);
 		return -EIO;
@@ -2171,7 +2121,8 @@ static blk_status_t loop_queue_rq(struct blk_mq_hw_ctx *hctx,
 		cmd->use_aio = false;
 		break;
 	default:
-		cmd->use_aio = lo->use_dio;
+		cmd->use_aio = !lo->transfer;
+		cmd->use_dio = lo->use_dio && cmd->use_aio;
 		break;
 	}
 
diff --git a/drivers/block/loop.h b/drivers/block/loop.h
index 04c88dd6eabd..b7d611e4f517 100644
--- a/drivers/block/loop.h
+++ b/drivers/block/loop.h
@@ -74,6 +74,7 @@ struct loop_device {
 struct loop_cmd {
 	struct list_head list_entry;
 	bool use_aio; /* use AIO interface to handle I/O */
+	bool use_dio;
 	atomic_t ref; /* only for aio */
 	long ret;
 	struct kiocb iocb;
-- 
2.31.1


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

* [PATCH 5/8] loop: fallback to buffered IO in case of dio submission
  2021-10-25  9:44 [PATCH 0/8] loop: improve dio on backing file Ming Lei
                   ` (3 preceding siblings ...)
  2021-10-25  9:44 ` [PATCH 4/8] loop: cover simple read/write via lo_rw_aio() Ming Lei
@ 2021-10-25  9:44 ` Ming Lei
  2021-10-26  7:36   ` Christoph Hellwig
  2021-10-25  9:44 ` [PATCH 6/8] loop: relax loop dio use condition Ming Lei
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 15+ messages in thread
From: Ming Lei @ 2021-10-25  9:44 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, Christoph Hellwig, Ming Lei

DIO submission on underlying file may fail because of unaligned buffer or
start_sector & sector_length, fallback to buffered IO when that happens,
this way will make loop dio mode more reliable.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 drivers/block/loop.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index d1784f825b6b..fee78a640f75 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -590,6 +590,7 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
 	cmd->iocb.ki_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0);
 	if (!cmd->use_dio) {
 		atomic_set(&cmd->ref, 1);
+buffered_io:
 		cmd->iocb.ki_flags = 0;
 		cmd->ret = lo_call_backing_rw_iter(file, &cmd->iocb, &iter, rw);
 		lo_rw_aio_do_completion(cmd);
@@ -603,8 +604,13 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
 
 	lo_rw_aio_do_completion(cmd);
 
-	if (ret != -EIOCBQUEUED)
+	if (ret != -EIOCBQUEUED) {
+		if (ret < 0) {
+			cmd->use_dio = false;
+			goto buffered_io;
+		}
 		cmd->iocb.ki_complete(&cmd->iocb, ret, 0);
+	}
 	return 0;
 }
 
-- 
2.31.1


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

* [PATCH 6/8] loop: relax loop dio use condition
  2021-10-25  9:44 [PATCH 0/8] loop: improve dio on backing file Ming Lei
                   ` (4 preceding siblings ...)
  2021-10-25  9:44 ` [PATCH 5/8] loop: fallback to buffered IO in case of dio submission Ming Lei
@ 2021-10-25  9:44 ` Ming Lei
  2021-10-26  7:37   ` 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
  7 siblings, 2 replies; 15+ messages in thread
From: Ming Lei @ 2021-10-25  9:44 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, Christoph Hellwig, Ming Lei

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


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

* [PATCH 7/8] loop: remove lo->use_dio
  2021-10-25  9:44 [PATCH 0/8] loop: improve dio on backing file Ming Lei
                   ` (5 preceding siblings ...)
  2021-10-25  9:44 ` [PATCH 6/8] loop: relax loop dio use condition Ming Lei
@ 2021-10-25  9:44 ` Ming Lei
  2021-10-25  9:44 ` [RFC PATCH 8/8] loop: use backing dio at default Ming Lei
  7 siblings, 0 replies; 15+ messages in thread
From: Ming Lei @ 2021-10-25  9:44 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, Christoph Hellwig, Ming Lei

lo->use_dio is just a copy of (lo->lo_flags & LO_FLAGS_DIRECT_IO), no
necessary to keep it.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 drivers/block/loop.c | 12 +++++-------
 drivers/block/loop.h |  1 -
 2 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index f42630246758..e42c0e3601ac 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -226,13 +226,12 @@ static void __loop_update_dio(struct loop_device *lo, bool dio)
 		use_dio = false;
 	}
 
-	if (lo->use_dio == use_dio)
+	if (!!(lo->lo_flags & LO_FLAGS_DIRECT_IO) == use_dio)
 		return;
 
 	/* flush dirty pages before changing direct IO */
 	vfs_fsync(file, 0);
 
-	lo->use_dio = use_dio;
 	if (use_dio) {
 		blk_queue_flag_clear(QUEUE_FLAG_NOMERGES, lo->lo_queue);
 		lo->lo_flags |= LO_FLAGS_DIRECT_IO;
@@ -622,7 +621,7 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq)
 static inline void loop_update_dio(struct loop_device *lo)
 {
 	__loop_update_dio(lo, (lo->lo_backing_file->f_flags & O_DIRECT) |
-				lo->use_dio);
+				(lo->lo_flags & LO_FLAGS_DIRECT_IO));
 }
 
 static void loop_reread_partitions(struct loop_device *lo)
@@ -1207,7 +1206,6 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
 	lo->worker_tree = RB_ROOT;
 	timer_setup(&lo->timer, loop_free_idle_workers,
 		TIMER_DEFERRABLE);
-	lo->use_dio = lo->lo_flags & LO_FLAGS_DIRECT_IO;
 	lo->lo_device = bdev;
 	lo->lo_backing_file = file;
 	lo->old_gfp_mask = mapping_gfp_mask(mapping);
@@ -1495,7 +1493,7 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info)
 	loop_config_discard(lo);
 
 	/* update dio if lo_offset or transfer is changed */
-	__loop_update_dio(lo, lo->use_dio);
+	__loop_update_dio(lo, lo->lo_flags & LO_FLAGS_DIRECT_IO);
 
 out_unfreeze:
 	blk_mq_unfreeze_queue(lo->lo_queue);
@@ -1682,7 +1680,7 @@ static int loop_set_dio(struct loop_device *lo, unsigned long arg)
 		goto out;
 
 	__loop_update_dio(lo, !!arg);
-	if (lo->use_dio == !!arg)
+	if (!!(lo->lo_flags & LO_FLAGS_DIRECT_IO) == !!arg)
 		return 0;
 	error = -EINVAL;
  out:
@@ -2094,7 +2092,7 @@ static blk_status_t loop_queue_rq(struct blk_mq_hw_ctx *hctx,
 		break;
 	default:
 		cmd->use_aio = !lo->transfer;
-		cmd->use_dio = lo->use_dio && cmd->use_aio;
+		cmd->use_dio = (lo->lo_flags & LO_FLAGS_DIRECT_IO) && cmd->use_aio;
 		break;
 	}
 
diff --git a/drivers/block/loop.h b/drivers/block/loop.h
index b7d611e4f517..feb92efb3b57 100644
--- a/drivers/block/loop.h
+++ b/drivers/block/loop.h
@@ -61,7 +61,6 @@ struct loop_device {
 	struct list_head        idle_worker_list;
 	struct rb_root          worker_tree;
 	struct timer_list       timer;
-	bool			use_dio;
 	bool			sysfs_inited;
 
 	struct request_queue	*lo_queue;
-- 
2.31.1


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

* [RFC PATCH 8/8] loop: use backing dio at default
  2021-10-25  9:44 [PATCH 0/8] loop: improve dio on backing file Ming Lei
                   ` (6 preceding siblings ...)
  2021-10-25  9:44 ` [PATCH 7/8] loop: remove lo->use_dio Ming Lei
@ 2021-10-25  9:44 ` Ming Lei
  7 siblings, 0 replies; 15+ messages in thread
From: Ming Lei @ 2021-10-25  9:44 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, Christoph Hellwig, Ming Lei

We have supported to fallback to buffered IO in case dio failure. Also
in reality, most of or quite a lot of IOs(such as FS IO) are actually aligned,
even though loop's logical block size isn't matched with backing
queue's.

So enable direct io at default.

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

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index e42c0e3601ac..df057dca7512 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -2285,13 +2285,8 @@ static int loop_add(int i)
 
 	blk_queue_max_hw_sectors(lo->lo_queue, BLK_DEF_MAX_SECTORS);
 
-	/*
-	 * By default, we do buffer IO, so it doesn't make sense to enable
-	 * merge because the I/O submitted to backing file is handled page by
-	 * page. For directio mode, merge does help to dispatch bigger request
-	 * to underlayer disk. We will enable merge once directio is enabled.
-	 */
-	blk_queue_flag_set(QUEUE_FLAG_NOMERGES, lo->lo_queue);
+	/* use backing dio at default */
+	lo->lo_flags |= LO_FLAGS_DIRECT_IO;
 
 	/*
 	 * Disable partition scanning by default. The in-kernel partition
-- 
2.31.1


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

* Re: [PATCH 1/8] loop: move flush_dcache_page to ->complete of request
  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
  0 siblings, 0 replies; 15+ messages in thread
From: Christoph Hellwig @ 2021-10-26  7:21 UTC (permalink / raw)
  To: Ming Lei; +Cc: Jens Axboe, linux-block, Christoph Hellwig

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH 2/8] loop: remove always true check
  2021-10-25  9:44 ` [PATCH 2/8] loop: remove always true check Ming Lei
@ 2021-10-26  7:31   ` Christoph Hellwig
  0 siblings, 0 replies; 15+ messages in thread
From: Christoph Hellwig @ 2021-10-26  7:31 UTC (permalink / raw)
  To: Ming Lei; +Cc: Jens Axboe, linux-block, Christoph Hellwig

lo_complete_rq is still a complete mess.  I'd suggest something like
this instead:

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 8f140d6374356..1648d30a8cb4a 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -517,40 +517,37 @@ static void lo_flush_dcache_for_read(struct request *rq)
 static void lo_complete_rq(struct request *rq)
 {
 	struct loop_cmd *cmd = blk_mq_rq_to_pdu(rq);
-	blk_status_t ret = BLK_STS_OK;
+
+	if (cmd->ret < 0) {
+		blk_mq_end_request(rq, errno_to_blk_status(cmd->ret));
+		return;
+	}
 
 	/* Kernel wrote to our pages, call flush_dcache_page */
 	if (req_op(rq) == REQ_OP_READ && !cmd->use_aio && cmd->ret >= 0)
 		lo_flush_dcache_for_read(rq);
 
-	if (!cmd->use_aio || cmd->ret < 0 || cmd->ret == blk_rq_bytes(rq) ||
-	    req_op(rq) != REQ_OP_READ) {
-		if (cmd->ret < 0)
-			ret = errno_to_blk_status(cmd->ret);
-		goto end_io;
-	}
-
 	/*
-	 * Short READ - if we got some data, advance our request and
-	 * retry it. If we got no data, end the rest with EIO.
+	 * Short READ - if we got some data, advance our request and retry it.
+	 * If we got no data, end the rest with EIO.
 	 */
-	if (cmd->ret) {
-		blk_update_request(rq, BLK_STS_OK, cmd->ret);
-		cmd->ret = 0;
-		blk_mq_requeue_request(rq, true);
-	} else {
-		if (cmd->use_aio) {
-			struct bio *bio = rq->bio;
+	if (req_op(rq) == REQ_OP_READ && cmd->use_aio &&
+	    cmd->ret != blk_rq_bytes(rq)) {
+		if (cmd->ret) {
+			blk_update_request(rq, BLK_STS_OK, cmd->ret);
+			cmd->ret = 0;
+			blk_mq_requeue_request(rq, true);
+		} else {
+			struct bio *bio;
 
-			while (bio) {
+			for (bio = rq->bio; bio; bio = bio->bi_next)
 				zero_fill_bio(bio);
-				bio = bio->bi_next;
-			}
+			blk_mq_end_request(rq, BLK_STS_IOERR);
 		}
-		ret = BLK_STS_IOERR;
-end_io:
-		blk_mq_end_request(rq, ret);
+		return;
 	}
+
+	blk_mq_end_request(rq, BLK_STS_OK);
 }
 
 static void lo_rw_aio_do_completion(struct loop_cmd *cmd)

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

* Re: [PATCH 4/8] loop: cover simple read/write via lo_rw_aio()
  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
  0 siblings, 0 replies; 15+ messages in thread
From: Christoph Hellwig @ 2021-10-26  7:35 UTC (permalink / raw)
  To: Ming Lei; +Cc: Jens Axboe, linux-block, Christoph Hellwig

> -	cmd->iocb.ki_complete = lo_rw_aio_complete;
> -	cmd->iocb.ki_flags = IOCB_DIRECT;
> +
>  	cmd->iocb.ki_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0);
> +	if (!cmd->use_dio) {
> +		atomic_set(&cmd->ref, 1);
> +		cmd->iocb.ki_flags = 0;
> +		cmd->ret = lo_call_backing_rw_iter(file, &cmd->iocb, &iter, rw);
> +		lo_rw_aio_do_completion(cmd);
> +		return 0;
> +	}

I don't think we even need the special casing.  If you just use the
AIO path here for buffered I/O it will do the same for you at the
small price of an extra refcount operation.

FYI, this seems to be against a kernel that still has cryptoloop/transfers.

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

* Re: [PATCH 5/8] loop: fallback to buffered IO in case of dio submission
  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
  0 siblings, 0 replies; 15+ messages in thread
From: Christoph Hellwig @ 2021-10-26  7:36 UTC (permalink / raw)
  To: Ming Lei; +Cc: Jens Axboe, linux-block, Christoph Hellwig

On Mon, Oct 25, 2021 at 05:44:34PM +0800, Ming Lei wrote:
> DIO submission on underlying file may fail because of unaligned buffer or
> start_sector & sector_length, fallback to buffered IO when that happens,
> this way will make loop dio mode more reliable.

I don't think this is a good idea.  Just do an ahead of time check
that the alignment matches and don't even try to use direct I/O code
in that case.  Otherwise we get a mix and match between buffered and
direct I/O, which is actively harmful.

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

* Re: [PATCH 6/8] loop: relax loop dio use condition
  2021-10-25  9:44 ` [PATCH 6/8] loop: relax loop dio use condition Ming Lei
@ 2021-10-26  7:37   ` Christoph Hellwig
  2021-10-27  0:20   ` kernel test robot
  1 sibling, 0 replies; 15+ messages in thread
From: Christoph Hellwig @ 2021-10-26  7:37 UTC (permalink / raw)
  To: Ming Lei; +Cc: Jens Axboe, linux-block, Christoph Hellwig

On Mon, Oct 25, 2021 at 05:44:35PM +0800, Ming Lei wrote:
> 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

And both these checks absolutely do make sense.  We should not drop
them and gets us into the messy state of mixed direct and buffered
I/O.

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

* Re: [PATCH 6/8] loop: relax loop dio use condition
  2021-10-25  9:44 ` [PATCH 6/8] loop: relax loop dio use condition Ming Lei
  2021-10-26  7:37   ` Christoph Hellwig
@ 2021-10-27  0:20   ` kernel test robot
  1 sibling, 0 replies; 15+ messages in thread
From: kernel test robot @ 2021-10-27  0:20 UTC (permalink / raw)
  To: Ming Lei, Jens Axboe; +Cc: kbuild-all, linux-block, Christoph Hellwig, Ming Lei

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

Hi Ming,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on v5.15-rc6]
[cannot apply to axboe-block/for-next next-20211026]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Ming-Lei/loop-improve-dio-on-backing-file/20211025-174819
base:    519d81956ee277b4419c723adfb154603c2565ba
config: parisc-buildonly-randconfig-r002-20211026 (attached as .config)
compiler: hppa-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/f98a33d68a04634ba8f8314e9da480abc332b1f4
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Ming-Lei/loop-improve-dio-on-backing-file/20211025-174819
        git checkout f98a33d68a04634ba8f8314e9da480abc332b1f4
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross ARCH=parisc 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/block/loop.c: In function 'loop_configure':
>> drivers/block/loop.c:1133:23: error: variable 'inode' set but not used [-Werror=unused-but-set-variable]
    1133 |         struct inode *inode;
         |                       ^~~~~
   cc1: all warnings being treated as errors


vim +/inode +1133 drivers/block/loop.c

62ab466ca881fe2 Martijn Coenen      2020-05-13  1127  
3448914e8cc550b Martijn Coenen      2020-05-13  1128  static int loop_configure(struct loop_device *lo, fmode_t mode,
3448914e8cc550b Martijn Coenen      2020-05-13  1129  			  struct block_device *bdev,
3448914e8cc550b Martijn Coenen      2020-05-13  1130  			  const struct loop_config *config)
^1da177e4c3f415 Linus Torvalds      2005-04-16  1131  {
3ce6e1f662a9109 Tetsuo Handa        2021-07-06  1132  	struct file *file = fget(config->fd);
^1da177e4c3f415 Linus Torvalds      2005-04-16 @1133  	struct inode *inode;
^1da177e4c3f415 Linus Torvalds      2005-04-16  1134  	struct address_space *mapping;
^1da177e4c3f415 Linus Torvalds      2005-04-16  1135  	int error;
^1da177e4c3f415 Linus Torvalds      2005-04-16  1136  	loff_t size;
85b0a54a82e4fbc Jan Kara            2018-11-08  1137  	bool partscan;
3448914e8cc550b Martijn Coenen      2020-05-13  1138  	unsigned short bsize;
3ce6e1f662a9109 Tetsuo Handa        2021-07-06  1139  	bool is_loop;
3ce6e1f662a9109 Tetsuo Handa        2021-07-06  1140  
3ce6e1f662a9109 Tetsuo Handa        2021-07-06  1141  	if (!file)
3ce6e1f662a9109 Tetsuo Handa        2021-07-06  1142  		return -EBADF;
3ce6e1f662a9109 Tetsuo Handa        2021-07-06  1143  	is_loop = is_loop_device(file);
^1da177e4c3f415 Linus Torvalds      2005-04-16  1144  
^1da177e4c3f415 Linus Torvalds      2005-04-16  1145  	/* This is safe, since we have a reference from open(). */
^1da177e4c3f415 Linus Torvalds      2005-04-16  1146  	__module_get(THIS_MODULE);
^1da177e4c3f415 Linus Torvalds      2005-04-16  1147  
33ec3e53e7b1869 Jan Kara            2019-05-16  1148  	/*
33ec3e53e7b1869 Jan Kara            2019-05-16  1149  	 * If we don't hold exclusive handle for the device, upgrade to it
33ec3e53e7b1869 Jan Kara            2019-05-16  1150  	 * here to avoid changing device under exclusive owner.
33ec3e53e7b1869 Jan Kara            2019-05-16  1151  	 */
33ec3e53e7b1869 Jan Kara            2019-05-16  1152  	if (!(mode & FMODE_EXCL)) {
37c3fc9abb25cd7 Christoph Hellwig   2020-11-25  1153  		error = bd_prepare_to_claim(bdev, loop_configure);
ecbe6bc0003bfd5 Christoph Hellwig   2020-07-16  1154  		if (error)
757ecf40b7e0295 Jan Kara            2018-11-08  1155  			goto out_putf;
33ec3e53e7b1869 Jan Kara            2019-05-16  1156  	}
33ec3e53e7b1869 Jan Kara            2019-05-16  1157  
3ce6e1f662a9109 Tetsuo Handa        2021-07-06  1158  	error = loop_global_lock_killable(lo, is_loop);
33ec3e53e7b1869 Jan Kara            2019-05-16  1159  	if (error)
33ec3e53e7b1869 Jan Kara            2019-05-16  1160  		goto out_bdev;
757ecf40b7e0295 Jan Kara            2018-11-08  1161  
^1da177e4c3f415 Linus Torvalds      2005-04-16  1162  	error = -EBUSY;
^1da177e4c3f415 Linus Torvalds      2005-04-16  1163  	if (lo->lo_state != Lo_unbound)
757ecf40b7e0295 Jan Kara            2018-11-08  1164  		goto out_unlock;
^1da177e4c3f415 Linus Torvalds      2005-04-16  1165  
d2ac838e4cd7e5e Theodore Ts'o       2018-05-07  1166  	error = loop_validate_file(file, bdev);
d2ac838e4cd7e5e Theodore Ts'o       2018-05-07  1167  	if (error)
757ecf40b7e0295 Jan Kara            2018-11-08  1168  		goto out_unlock;
^1da177e4c3f415 Linus Torvalds      2005-04-16  1169  
^1da177e4c3f415 Linus Torvalds      2005-04-16  1170  	mapping = file->f_mapping;
^1da177e4c3f415 Linus Torvalds      2005-04-16  1171  	inode = mapping->host;
^1da177e4c3f415 Linus Torvalds      2005-04-16  1172  
3448914e8cc550b Martijn Coenen      2020-05-13  1173  	if ((config->info.lo_flags & ~LOOP_CONFIGURE_SETTABLE_FLAGS) != 0) {
3448914e8cc550b Martijn Coenen      2020-05-13  1174  		error = -EINVAL;
3448914e8cc550b Martijn Coenen      2020-05-13  1175  		goto out_unlock;
3448914e8cc550b Martijn Coenen      2020-05-13  1176  	}
3448914e8cc550b Martijn Coenen      2020-05-13  1177  
3448914e8cc550b Martijn Coenen      2020-05-13  1178  	if (config->block_size) {
3448914e8cc550b Martijn Coenen      2020-05-13  1179  		error = loop_validate_block_size(config->block_size);
3448914e8cc550b Martijn Coenen      2020-05-13  1180  		if (error)
3448914e8cc550b Martijn Coenen      2020-05-13  1181  			goto out_unlock;
3448914e8cc550b Martijn Coenen      2020-05-13  1182  	}
3448914e8cc550b Martijn Coenen      2020-05-13  1183  
3448914e8cc550b Martijn Coenen      2020-05-13  1184  	error = loop_set_status_from_info(lo, &config->info);
3448914e8cc550b Martijn Coenen      2020-05-13  1185  	if (error)
3448914e8cc550b Martijn Coenen      2020-05-13  1186  		goto out_unlock;
3448914e8cc550b Martijn Coenen      2020-05-13  1187  
456be1484ffc72a Christoph Hellwig   2011-10-17  1188  	if (!(file->f_mode & FMODE_WRITE) || !(mode & FMODE_WRITE) ||
283e7e5d249f486 Al Viro             2015-04-03  1189  	    !file->f_op->write_iter)
3448914e8cc550b Martijn Coenen      2020-05-13  1190  		lo->lo_flags |= LO_FLAGS_READ_ONLY;
^1da177e4c3f415 Linus Torvalds      2005-04-16  1191  
87579e9b7d8dc36 Dan Schatzberg      2021-06-28  1192  	lo->workqueue = alloc_workqueue("loop%d",
87579e9b7d8dc36 Dan Schatzberg      2021-06-28  1193  					WQ_UNBOUND | WQ_FREEZABLE,
87579e9b7d8dc36 Dan Schatzberg      2021-06-28  1194  					0,
87579e9b7d8dc36 Dan Schatzberg      2021-06-28  1195  					lo->lo_number);
87579e9b7d8dc36 Dan Schatzberg      2021-06-28  1196  	if (!lo->workqueue) {
87579e9b7d8dc36 Dan Schatzberg      2021-06-28  1197  		error = -ENOMEM;
757ecf40b7e0295 Jan Kara            2018-11-08  1198  		goto out_unlock;
87579e9b7d8dc36 Dan Schatzberg      2021-06-28  1199  	}
^1da177e4c3f415 Linus Torvalds      2005-04-16  1200  
9f65c489b68d424 Matteo Croce        2021-07-13  1201  	disk_force_media_change(lo->lo_disk, DISK_EVENT_MEDIA_CHANGE);
7a2f0ce19f2e2ed Christoph Hellwig   2020-11-03  1202  	set_disk_ro(lo->lo_disk, (lo->lo_flags & LO_FLAGS_READ_ONLY) != 0);
^1da177e4c3f415 Linus Torvalds      2005-04-16  1203  
87579e9b7d8dc36 Dan Schatzberg      2021-06-28  1204  	INIT_WORK(&lo->rootcg_work, loop_rootcg_workfn);
87579e9b7d8dc36 Dan Schatzberg      2021-06-28  1205  	INIT_LIST_HEAD(&lo->rootcg_cmd_list);
87579e9b7d8dc36 Dan Schatzberg      2021-06-28  1206  	INIT_LIST_HEAD(&lo->idle_worker_list);
87579e9b7d8dc36 Dan Schatzberg      2021-06-28  1207  	lo->worker_tree = RB_ROOT;
87579e9b7d8dc36 Dan Schatzberg      2021-06-28  1208  	timer_setup(&lo->timer, loop_free_idle_workers,
87579e9b7d8dc36 Dan Schatzberg      2021-06-28  1209  		TIMER_DEFERRABLE);
3448914e8cc550b Martijn Coenen      2020-05-13  1210  	lo->use_dio = lo->lo_flags & LO_FLAGS_DIRECT_IO;
^1da177e4c3f415 Linus Torvalds      2005-04-16  1211  	lo->lo_device = bdev;
^1da177e4c3f415 Linus Torvalds      2005-04-16  1212  	lo->lo_backing_file = file;
^1da177e4c3f415 Linus Torvalds      2005-04-16  1213  	lo->old_gfp_mask = mapping_gfp_mask(mapping);
^1da177e4c3f415 Linus Torvalds      2005-04-16  1214  	mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
^1da177e4c3f415 Linus Torvalds      2005-04-16  1215  
3448914e8cc550b Martijn Coenen      2020-05-13  1216  	if (!(lo->lo_flags & LO_FLAGS_READ_ONLY) && file->f_op->fsync)
21d0727f639e4ba Jens Axboe          2016-03-30  1217  		blk_queue_write_cache(lo->lo_queue, true, false);
68db1961bbf4e16 Nikanth Karthikesan 2009-03-24  1218  
3448914e8cc550b Martijn Coenen      2020-05-13  1219  	if (config->block_size)
3448914e8cc550b Martijn Coenen      2020-05-13  1220  		bsize = config->block_size;
3448914e8cc550b Martijn Coenen      2020-05-13  1221  	else
3448914e8cc550b Martijn Coenen      2020-05-13  1222  		bsize = 512;
85560117d00f5d5 Martijn Coenen      2019-09-04  1223  
85560117d00f5d5 Martijn Coenen      2019-09-04  1224  	blk_queue_logical_block_size(lo->lo_queue, bsize);
85560117d00f5d5 Martijn Coenen      2019-09-04  1225  	blk_queue_physical_block_size(lo->lo_queue, bsize);
85560117d00f5d5 Martijn Coenen      2019-09-04  1226  	blk_queue_io_min(lo->lo_queue, bsize);
85560117d00f5d5 Martijn Coenen      2019-09-04  1227  
2b9ac22b12a266e Kristian Klausen    2021-06-18  1228  	loop_config_discard(lo);
56a85fd8376ef32 Holger Hoffstätte   2019-02-12  1229  	loop_update_rotational(lo);
2e5ab5f379f96a6 Ming Lei            2015-08-17  1230  	loop_update_dio(lo);
ee86273062cbb31 Milan Broz          2010-08-23  1231  	loop_sysfs_init(lo);
79e5dc59e2974a4 Martijn Coenen      2020-08-25  1232  
79e5dc59e2974a4 Martijn Coenen      2020-08-25  1233  	size = get_loop_size(lo, file);
5795b6f5607f7e4 Martijn Coenen      2020-05-13  1234  	loop_set_size(lo, size);
^1da177e4c3f415 Linus Torvalds      2005-04-16  1235  
3ce6e1f662a9109 Tetsuo Handa        2021-07-06  1236  	/* Order wrt reading lo_state in loop_validate_file(). */
3ce6e1f662a9109 Tetsuo Handa        2021-07-06  1237  	wmb();
3ce6e1f662a9109 Tetsuo Handa        2021-07-06  1238  
6c9979185c7ef4f Serge E. Hallyn     2006-09-29  1239  	lo->lo_state = Lo_bound;
e03c8dd14915fab Kay Sievers         2011-08-23  1240  	if (part_shift)
e03c8dd14915fab Kay Sievers         2011-08-23  1241  		lo->lo_flags |= LO_FLAGS_PARTSCAN;
85b0a54a82e4fbc Jan Kara            2018-11-08  1242  	partscan = lo->lo_flags & LO_FLAGS_PARTSCAN;
fe6a8fc5ed2f008 Lennart Poettering  2020-08-10  1243  	if (partscan)
fe6a8fc5ed2f008 Lennart Poettering  2020-08-10  1244  		lo->lo_disk->flags &= ~GENHD_FL_NO_PART_SCAN;
c1681bf8a7b1b98 Anatol Pomozov      2013-04-01  1245  
3ce6e1f662a9109 Tetsuo Handa        2021-07-06  1246  	loop_global_unlock(lo, is_loop);
85b0a54a82e4fbc Jan Kara            2018-11-08  1247  	if (partscan)
0384264ea8a39bd Christoph Hellwig   2021-06-24  1248  		loop_reread_partitions(lo);
37c3fc9abb25cd7 Christoph Hellwig   2020-11-25  1249  	if (!(mode & FMODE_EXCL))
37c3fc9abb25cd7 Christoph Hellwig   2020-11-25  1250  		bd_abort_claiming(bdev, loop_configure);
^1da177e4c3f415 Linus Torvalds      2005-04-16  1251  	return 0;
^1da177e4c3f415 Linus Torvalds      2005-04-16  1252  
757ecf40b7e0295 Jan Kara            2018-11-08  1253  out_unlock:
3ce6e1f662a9109 Tetsuo Handa        2021-07-06  1254  	loop_global_unlock(lo, is_loop);
33ec3e53e7b1869 Jan Kara            2019-05-16  1255  out_bdev:
37c3fc9abb25cd7 Christoph Hellwig   2020-11-25  1256  	if (!(mode & FMODE_EXCL))
37c3fc9abb25cd7 Christoph Hellwig   2020-11-25  1257  		bd_abort_claiming(bdev, loop_configure);
^1da177e4c3f415 Linus Torvalds      2005-04-16  1258  out_putf:
^1da177e4c3f415 Linus Torvalds      2005-04-16  1259  	fput(file);
^1da177e4c3f415 Linus Torvalds      2005-04-16  1260  	/* This is safe: open() is still holding a reference. */
^1da177e4c3f415 Linus Torvalds      2005-04-16  1261  	module_put(THIS_MODULE);
^1da177e4c3f415 Linus Torvalds      2005-04-16  1262  	return error;
^1da177e4c3f415 Linus Torvalds      2005-04-16  1263  }
^1da177e4c3f415 Linus Torvalds      2005-04-16  1264  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 32969 bytes --]

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

end of thread, other threads:[~2021-10-27  0:21 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 6/8] loop: relax loop dio use condition Ming Lei
2021-10-26  7:37   ` 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

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).