Skip to contentSkip to conversation

REQ_NOAIT cleanups

PATCH In review Christoph Hellwig 5 participants 11 messages May 18 – May 26

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi all,

this series cleans up spurious code related to REQ_NOWAIT handling.

I have block layer work depending on this pending, so merging it through the block tree would be helpful.

Diffstat:

 fs/direct-io.c      |   15 ++++-----------
 include/linux/bio.h |    1 -
 2 files changed, 4 insertions(+), 12 deletions(-)
#1 lore raw

PATCH 1/2 direct-io: remove IOCB_NOWAIT support

None of the file systems using the legacy direct I/O code actually sets FMODE_NOWAIT, and if they did this would not work, as the write locking could not handle the retry. Remove this dead code.

---
 fs/direct-io.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
fs/direct-io.c +4 -11
index 2267f5ae7f77..9e4976716985 100644
@@ -502,12 +502,8 @@ static blk_status_t dio_bio_complete(struct dio *dio, struct bio *bio)
 	const enum req_op dio_op = dio->opf & REQ_OP_MASK;
 	bool should_dirty = dio_op == REQ_OP_READ && dio->should_dirty;
 
-	if (err) {
-		if (err == BLK_STS_AGAIN && (bio->bi_opf & REQ_NOWAIT))
-			dio->io_error = -EAGAIN;
-		else
-			dio->io_error = -EIO;
-	}
+	if (err)
+		dio->io_error = -EIO;
 
 	if (dio->is_async && should_dirty) {
 		bio_check_pages_dirty(bio);	/* transfers ownership */
@@ -1178,13 +1174,10 @@ ssize_t __blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
 		dio->is_async = true;
 
 	dio->inode = inode;
-	if (iov_iter_rw(iter) == WRITE) {
+	if (iov_iter_rw(iter) == WRITE)
 		dio->opf = REQ_OP_WRITE | REQ_SYNC | REQ_IDLE;
-		if (iocb->ki_flags & IOCB_NOWAIT)
-			dio->opf |= REQ_NOWAIT;
-	} else {
+	else
 		dio->opf = REQ_OP_READ;
-	}
 
 	/*
 	 * For AIO O_(D)SYNC writes we need to defer completions to a workqueue
Signature · 1 line
2.53.0
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] direct-io: remove IOCB_NOWAIT support

Quoted 5 lines · Christoph Hellwig

None of the file systems using the legacy direct I/O code actually sets FMODE_NOWAIT, and if they did this would not work, as the write locking could not handle the retry. Remove this dead code.

Looks OK to me.

Signature · 2 lines
Damien Le Moal
Western Digital Research
reviewer Reviewed-by on v1 1/2
#3 lore raw

Re: [PATCH 1/2] direct-io: remove IOCB_NOWAIT support

In reply to Christoph Hellwig
Quoted 5 lines · Christoph Hellwig

None of the file systems using the legacy direct I/O code actually sets FMODE_NOWAIT, and if they did this would not work, as the write locking could not handle the retry. Remove this dead code.

I agree there's no point in bothering with this. Feel free to add:

Honza

Quoted 42 lines
---
 fs/direct-io.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
fs/direct-io.c +4 -11
index 2267f5ae7f77..9e4976716985 100644
@@ -502,12 +502,8 @@ static blk_status_t dio_bio_complete(struct dio *dio, struct bio *bio)
 	const enum req_op dio_op = dio->opf & REQ_OP_MASK;
 	bool should_dirty = dio_op == REQ_OP_READ && dio->should_dirty;
 
-	if (err) {
-		if (err == BLK_STS_AGAIN && (bio->bi_opf & REQ_NOWAIT))
-			dio->io_error = -EAGAIN;
-		else
-			dio->io_error = -EIO;
-	}
+	if (err)
+		dio->io_error = -EIO;
 
 	if (dio->is_async && should_dirty) {
 		bio_check_pages_dirty(bio);	/* transfers ownership */
@@ -1178,13 +1174,10 @@ ssize_t __blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
 		dio->is_async = true;
 
 	dio->inode = inode;
-	if (iov_iter_rw(iter) == WRITE) {
+	if (iov_iter_rw(iter) == WRITE)
 		dio->opf = REQ_OP_WRITE | REQ_SYNC | REQ_IDLE;
-		if (iocb->ki_flags & IOCB_NOWAIT)
-			dio->opf |= REQ_NOWAIT;
-	} else {
+	else
 		dio->opf = REQ_OP_READ;
-	}
 
 	/*
 	 * For AIO O_(D)SYNC writes we need to defer completions to a workqueue
Signature · 1 line
2.53.0
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
maintainer Reviewed-by on v1 1/2
#4 lore raw

Re: [PATCH 1/2] direct-io: remove IOCB_NOWAIT support

In reply to Christoph Hellwig
Quoted 6 lines · Christoph Hellwig

None of the file systems using the legacy direct I/O code actually sets FMODE_NOWAIT, and if they did this would not work, as the write locking could not handle the retry. Remove this dead code.

---

#5 lore raw

PATCH 2/2 block: don't set BIO_QUIET for BLK_STS_AGAIN

In reply to Christoph Hellwig

Commit abb30460bda2 ("block: mark bio_wouldblock_error() bio with BIO_QUIET") added this to suppress buffer_head warnings, but neither when this commit was added nor now any buffer_head using code actually ever sets REQ_NOWAIT which can lead to BLK_STS_AGAIN.

Remove the special handling for now. If we ever plan to use REQ_NOWAIT for buffer_head based I/O we're better off handling BLK_STS_AGAIN in the completion handler as it actually needs to retry the I/O as well.

---
 include/linux/bio.h | 1 -
 1 file changed, 1 deletion(-)
include/linux/bio.h +0 -1
index 85463981d0f5..7597ae4dc52b 100644
@@ -379,7 +379,6 @@ static inline void bio_io_error(struct bio *bio)
 
 static inline void bio_wouldblock_error(struct bio *bio)
 {
-	bio_set_flag(bio, BIO_QUIET);
 	bio->bi_status = BLK_STS_AGAIN;
 	bio_endio(bio);
 }
Signature · 1 line
2.53.0
Reviewed-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] block: don't set BIO_QUIET for BLK_STS_AGAIN

Quoted 10 lines · Christoph Hellwig

Commit abb30460bda2 ("block: mark bio_wouldblock_error() bio with BIO_QUIET") added this to suppress buffer_head warnings, but neither when this commit was added nor now any buffer_head using code actually ever sets REQ_NOWAIT which can lead to BLK_STS_AGAIN.

Remove the special handling for now. If we ever plan to use REQ_NOWAIT for buffer_head based I/O we're better off handling BLK_STS_AGAIN in the completion handler as it actually needs to retry the I/O as well.

Looks OK to me.

Signature · 2 lines
Damien Le Moal
Western Digital Research
reviewer
#7 lore raw

Re: [PATCH 2/2] block: don't set BIO_QUIET for BLK_STS_AGAIN

In reply to Christoph Hellwig
Quoted 10 lines · Christoph Hellwig

Commit abb30460bda2 ("block: mark bio_wouldblock_error() bio with BIO_QUIET") added this to suppress buffer_head warnings, but neither when this commit was added nor now any buffer_head using code actually ever sets REQ_NOWAIT which can lead to BLK_STS_AGAIN.

Remove the special handling for now. If we ever plan to use REQ_NOWAIT for buffer_head based I/O we're better off handling BLK_STS_AGAIN in the completion handler as it actually needs to retry the I/O as well.

So I agree about the bh argument but bio_wouldblock_error() is not specific to bh path in any way, is it? So do we expect all bi_end_io handlers to check for BLK_STS_AGAIN and avoid complaining to logs in case of that? Not that all of them would be currently checking for BIO_QUIET either so I'm mostly trying to figure out what's the expected handling.

Honza

Quoted 19 lines
---
 include/linux/bio.h | 1 -
 1 file changed, 1 deletion(-)
include/linux/bio.h +0 -1
index 85463981d0f5..7597ae4dc52b 100644
@@ -379,7 +379,6 @@ static inline void bio_io_error(struct bio *bio)
 
 static inline void bio_wouldblock_error(struct bio *bio)
 {
-	bio_set_flag(bio, BIO_QUIET);
 	bio->bi_status = BLK_STS_AGAIN;
 	bio_endio(bio);
 }
Signature · 1 line
2.53.0
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#8 lore raw

Re: [PATCH 2/2] block: don't set BIO_QUIET for BLK_STS_AGAIN

Quoted 9 lines · Jan Kara
Quoted 9 lines

Commit abb30460bda2 ("block: mark bio_wouldblock_error() bio with BIO_QUIET") added this to suppress buffer_head warnings, but neither when this commit was added nor now any buffer_head using code actually ever sets REQ_NOWAIT which can lead to BLK_STS_AGAIN.

Remove the special handling for now. If we ever plan to use REQ_NOWAIT for buffer_head based I/O we're better off handling BLK_STS_AGAIN in the completion handler as it actually needs to retry the I/O as well.

Quoted 7 lines
Quoted 1 line

So I agree about the bh argument but bio_wouldblock_error() is not specific to bh path in any way, is it? So do we expect all bi_end_io handlers to check for BLK_STS_AGAIN and avoid complaining to logs in case of that? Not that all of them would be currently checking for BIO_QUIET either so I'm mostly trying to figure out what's the expected handling.

File system would need special handling for BLK_STS_AGAIN were we to wire it up again (in upstream we have the dead direct-io code removed in patch 1, and an incorrect use in iomap polled I/O I sent a separate patch for), because simply bubbling it up as -EAGAIN will generally do the wrong thing. We ran into file system corruption last time we did it due to non-idempotency of writes and general locking issues with just retrying at a higher level.

Thus the rough consensus was that If we want to support fs-issued REQ_NOWAIT I/O we'd first need to add infrastructure to retry them from a blocking context at the bio-level, preferably in the block layer itself.

reviewer Reviewed-by
#9 lore raw

Re: [PATCH 2/2] block: don't set BIO_QUIET for BLK_STS_AGAIN

Quoted 26 lines · Christoph Hellwig
Quoted 9 lines · Jan Kara
Quoted 9 lines

Commit abb30460bda2 ("block: mark bio_wouldblock_error() bio with BIO_QUIET") added this to suppress buffer_head warnings, but neither when this commit was added nor now any buffer_head using code actually ever sets REQ_NOWAIT which can lead to BLK_STS_AGAIN.

Remove the special handling for now. If we ever plan to use REQ_NOWAIT for buffer_head based I/O we're better off handling BLK_STS_AGAIN in the completion handler as it actually needs to retry the I/O as well.

Quoted 7 lines
Quoted 1 line

So I agree about the bh argument but bio_wouldblock_error() is not specific to bh path in any way, is it? So do we expect all bi_end_io handlers to check for BLK_STS_AGAIN and avoid complaining to logs in case of that? Not that all of them would be currently checking for BIO_QUIET either so I'm mostly trying to figure out what's the expected handling.

File system would need special handling for BLK_STS_AGAIN were we to wire it up again (in upstream we have the dead direct-io code removed in patch 1, and an incorrect use in iomap polled I/O I sent a separate patch for), because simply bubbling it up as -EAGAIN will generally do the wrong thing. We ran into file system corruption last time we did it due to non-idempotency of writes and general locking issues with just retrying at a higher level.

Quoted 4 lines

Thus the rough consensus was that If we want to support fs-issued REQ_NOWAIT I/O we'd first need to add infrastructure to retry them from a blocking context at the bio-level, preferably in the block layer itself.

OK, fair. Thanks for explanation. So this flagging with quiet is indeed pointless. Feel free to add:

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
maintainer Applied
#10 lore raw
In reply to Christoph Hellwig
Quoted 11 lines · Christoph Hellwig

this series cleans up spurious code related to REQ_NOWAIT handling.

I have block layer work depending on this pending, so merging it through the block tree would be helpful.

Diffstat:

 fs/direct-io.c      |   15 ++++-----------
 include/linux/bio.h |    1 -
 2 files changed, 4 insertions(+), 12 deletions(-)

[...]

Applied, thanks!

[1/2] direct-io: remove IOCB_NOWAIT support

      commit: ef9049ec8b9fd6c508832d9f7ab12029f3355102
[2/2] block: don't set BIO_QUIET for BLK_STS_AGAIN
      commit: 481105a949c8d11f7aa770b45fc4c8efcc53f205

Best regards,

Signature · 1 line
Jens Axboe