Linux filesystem development
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Fengnan <changfengnan@bytedance.com>
Cc: Christian Brauner <brauner@kernel.org>,
	Christoph Hellwig <hch@lst.de>,
	"Darrick J . Wong" <djwong@kernel.org>,
	linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-ext4@vger.kernel.org, tom.leiming@gmail.com,
	John Garry <john.garry@linux.dev>
Subject: Re: [PATCH] iomap: disable I/O polling when direct I/O must wait
Date: Wed, 2 Dec 2026 09:20:08 +0100	[thread overview]
Message-ID: <20261202082008.GA5166@lst.de> (raw)
In-Reply-To: <84dd8106-5b90-4245-a44c-59375382e54f@bytedance.com>

On Wed, Dec 02, 2026 at 03:53:14PM +0800, Fengnan wrote:
> diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
> --- a/fs/iomap/direct-io.c
> +++ b/fs/iomap/direct-io.c
> @@ -68,8 +68,14 @@ static void iomap_dio_submit_bio(const struct iomap_iter *iter,
>  
>  	atomic_inc(&dio->ref);
>  
> -	/* Sync dio can't be polled reliably */
> -	if ((iocb->ki_flags & IOCB_HIPRI) && !is_sync_kiocb(iocb)) {
> +	/*
> +	 * Only poll a bio that starts at the beginning of the request and
> +	 * carries all of it, and only if the dio does not wait for completion.
> +	 * Once that bio is submitted the iteration is done, so a short I/O
> +	 * can't make __iomap_dio_rw() wait for it later.
> +	 */
> +	if ((iocb->ki_flags & IOCB_HIPRI) && !dio->wait_for_completion &&
> +	    pos == iocb->ki_pos && bio->bi_iter.bi_size == iter->len) {

iomap_dio_bio_iter_one already has some of this just before the call
to iomap_dio_submit_bio, and iomap_dio_bio_iter_one already has a
slightly different check for a bio that covers the whole range for
atomics a little bit above, which seems to miss pos check.

Maybe consolidate the entire logic there, something like this (untested):

diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
index d7105b5dba7d..750c2a445282 100644
--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -64,16 +64,8 @@ static struct bio *iomap_dio_alloc_bio(const struct iomap_iter *iter,
 static void iomap_dio_submit_bio(const struct iomap_iter *iter,
 		struct iomap_dio *dio, struct bio *bio, loff_t pos)
 {
-	struct kiocb *iocb = dio->iocb;
-
 	atomic_inc(&dio->ref);
 
-	/* Sync dio can't be polled reliably */
-	if ((iocb->ki_flags & IOCB_HIPRI) && !is_sync_kiocb(iocb)) {
-		bio->bi_opf |= REQ_POLLED;
-		WRITE_ONCE(iocb->private, bio);
-	}
-
 	if (dio->dops && dio->dops->submit_io) {
 		dio->dops->submit_io(iter, bio, pos);
 		return;
@@ -342,6 +334,7 @@ static ssize_t iomap_dio_bio_iter_one(struct iomap_iter *iter,
 		struct iomap_dio *dio, loff_t pos, unsigned int alignment,
 		blk_opf_t op)
 {
+	struct kiocb *iocb = dio->iocb;
 	unsigned int maxsize = iomap_max_bio_size(&iter->iomap);
 	unsigned int nr_vecs;
 	struct bio *bio;
@@ -356,7 +349,7 @@ static ssize_t iomap_dio_bio_iter_one(struct iomap_iter *iter,
 	fscrypt_set_bio_crypt_ctx(bio, iter->inode, pos, GFP_KERNEL);
 	bio->bi_iter.bi_sector = iomap_sector(&iter->iomap, pos);
 	bio->bi_write_hint = iter->inode->i_write_hint;
-	bio->bi_ioprio = dio->iocb->ki_ioprio;
+	bio->bi_ioprio = iocb->ki_ioprio;
 	bio->bi_private = dio;
 	bio->bi_end_io = iomap_dio_bio_end_io;
 
@@ -368,15 +361,26 @@ static ssize_t iomap_dio_bio_iter_one(struct iomap_iter *iter,
 				bdev_dma_alignment(bio->bi_bdev), alignment - 1);
 	if (unlikely(ret))
 		goto out_put_bio;
-	ret = bio->bi_iter.bi_size;
 
-	/*
-	 * An atomic write bio must cover the complete length.  If it doesn't,
-	 * error out.
-	 */
-	if ((op & REQ_ATOMIC) && WARN_ON_ONCE(ret != iomap_length(iter))) {
-		ret = -EINVAL;
-		goto out_bio_release_pages;
+	if (pos == iocb->ki_pos && bio->bi_iter.bi_size == iomap_length(iter)) {
+		/*
+		 * Only async bios can be polled, and polling is only supported
+		 * for single bio per kiocb.
+		 */
+		if ((iocb->ki_flags & IOCB_HIPRI) &&
+		    !dio->wait_for_completion) {
+			bio->bi_opf |= REQ_POLLED;
+			WRITE_ONCE(iocb->private, bio);
+		}
+	} else {
+		/*
+		 * An atomic write bio must cover the complete length.  If it
+		 * doesn't, error out.
+		 */
+		if (WARN_ON_ONCE(op & REQ_ATOMIC)) {
+			ret = -EINVAL;
+			goto out_bio_release_pages;
+		}
 	}
 
 	if (dio->flags & IOMAP_DIO_WRITE)
@@ -385,11 +389,7 @@ static ssize_t iomap_dio_bio_iter_one(struct iomap_iter *iter,
 		 !(dio->flags & IOMAP_DIO_BOUNCE))
 		bio_set_pages_dirty(bio);
 
-	/*
-	 * We can only poll for single bio I/Os.
-	 */
-	if (iov_iter_count(dio->submit.iter))
-		dio->iocb->ki_flags &= ~IOCB_HIPRI;
+	ret = bio->bi_iter.bi_size;
 	iomap_dio_submit_bio(iter, dio, bio, pos);
 	return ret;
 

  reply	other threads:[~2026-12-02  8:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  3:49 [PATCH] iomap: disable I/O polling when direct I/O must wait Fengnan Chang
2026-12-01  8:08 ` Christoph Hellwig
2026-12-01  8:48   ` Fengnan Chang
2026-12-01 13:25 ` Christian Brauner
2026-12-01 13:26 ` Christian Brauner
2026-12-02  1:56   ` Fengnan
2026-12-02  7:53     ` Fengnan
2026-12-02  8:20       ` Christoph Hellwig [this message]
2026-12-02  8:43         ` changfengnan
2026-12-02  9:20         ` John Garry

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=20261202082008.GA5166@lst.de \
    --to=hch@lst.de \
    --cc=brauner@kernel.org \
    --cc=changfengnan@bytedance.com \
    --cc=djwong@kernel.org \
    --cc=john.garry@linux.dev \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=tom.leiming@gmail.com \
    /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