public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCHSET 0/2] io_uring tweaks for poll retry
@ 2020-04-28 19:20 Jens Axboe
  2020-04-28 19:20 ` [PATCH 1/2] io_uring: enable poll retry for any file with ->read_iter / ->write_iter Jens Axboe
  2020-04-28 19:20 ` [PATCH 2/2] io_uring: only force async punt if poll based retry can't handle it Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Jens Axboe @ 2020-04-28 19:20 UTC (permalink / raw)
  To: io-uring

Just a few minor tweaks here:

- Base decision on whether we can support async EAGAIN try on a file on
  whether it has ->read_iter or ->write_iter, depending on direction.

- Only force punt to async worker for read/write if we can't poll for
  the retry.

Should go into 5.7.

-- 
Jens Axboe



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

* [PATCH 1/2] io_uring: enable poll retry for any file with ->read_iter / ->write_iter
  2020-04-28 19:20 [PATCHSET 0/2] io_uring tweaks for poll retry Jens Axboe
@ 2020-04-28 19:20 ` Jens Axboe
  2020-04-28 19:20 ` [PATCH 2/2] io_uring: only force async punt if poll based retry can't handle it Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2020-04-28 19:20 UTC (permalink / raw)
  To: io-uring; +Cc: Jens Axboe

We can have files like eventfd where it's perfectly fine to do poll
based retry on them, right now io_file_supports_async() doesn't take
that into account.

Pass in data direction and check the f_op instead of just always needing
an async worker.

Signed-off-by: Jens Axboe <[email protected]>
---
 fs/io_uring.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 084dfade5cda..53cadadc7f89 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -2038,7 +2038,7 @@ static struct file *__io_file_get(struct io_submit_state *state, int fd)
  * any file. For now, just ensure that anything potentially problematic is done
  * inline.
  */
-static bool io_file_supports_async(struct file *file)
+static bool io_file_supports_async(struct file *file, int rw)
 {
 	umode_t mode = file_inode(file)->i_mode;
 
@@ -2047,7 +2047,10 @@ static bool io_file_supports_async(struct file *file)
 	if (S_ISREG(mode) && file->f_op != &io_uring_fops)
 		return true;
 
-	return false;
+	if (rw == READ)
+		return file->f_op->read_iter != NULL;
+
+	return file->f_op->write_iter != NULL;
 }
 
 static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe,
@@ -2575,7 +2578,7 @@ static int io_read(struct io_kiocb *req, bool force_nonblock)
 	 * If the file doesn't support async, mark it as REQ_F_MUST_PUNT so
 	 * we know to async punt it even if it was opened O_NONBLOCK
 	 */
-	if (force_nonblock && !io_file_supports_async(req->file))
+	if (force_nonblock && !io_file_supports_async(req->file, READ))
 		goto copy_iov;
 
 	iov_count = iov_iter_count(&iter);
@@ -2666,7 +2669,7 @@ static int io_write(struct io_kiocb *req, bool force_nonblock)
 	 * If the file doesn't support async, mark it as REQ_F_MUST_PUNT so
 	 * we know to async punt it even if it was opened O_NONBLOCK
 	 */
-	if (force_nonblock && !io_file_supports_async(req->file))
+	if (force_nonblock && !io_file_supports_async(req->file, WRITE))
 		goto copy_iov;
 
 	/* file path doesn't support NOWAIT for non-direct_IO */
@@ -2760,11 +2763,11 @@ static int io_splice_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 	return 0;
 }
 
-static bool io_splice_punt(struct file *file)
+static bool io_splice_punt(struct file *file, int rw)
 {
 	if (get_pipe_info(file))
 		return false;
-	if (!io_file_supports_async(file))
+	if (!io_file_supports_async(file, rw))
 		return true;
 	return !(file->f_flags & O_NONBLOCK);
 }
@@ -2779,7 +2782,7 @@ static int io_splice(struct io_kiocb *req, bool force_nonblock)
 	long ret;
 
 	if (force_nonblock) {
-		if (io_splice_punt(in) || io_splice_punt(out))
+		if (io_splice_punt(in, READ) || io_splice_punt(out, WRITE))
 			return -EAGAIN;
 		flags |= SPLICE_F_NONBLOCK;
 	}
-- 
2.26.2


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

* [PATCH 2/2] io_uring: only force async punt if poll based retry can't handle it
  2020-04-28 19:20 [PATCHSET 0/2] io_uring tweaks for poll retry Jens Axboe
  2020-04-28 19:20 ` [PATCH 1/2] io_uring: enable poll retry for any file with ->read_iter / ->write_iter Jens Axboe
@ 2020-04-28 19:20 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2020-04-28 19:20 UTC (permalink / raw)
  To: io-uring; +Cc: Jens Axboe

We do blocking retry from our poll handler, if the file supports polled
notifications. Only mark the request as needing an async worker if we
can't poll for it.

Signed-off-by: Jens Axboe <[email protected]>
---
 fs/io_uring.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 53cadadc7f89..75ff4cc9818b 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -2601,7 +2601,8 @@ static int io_read(struct io_kiocb *req, bool force_nonblock)
 			if (ret)
 				goto out_free;
 			/* any defer here is final, must blocking retry */
-			if (!(req->flags & REQ_F_NOWAIT))
+			if (!(req->flags & REQ_F_NOWAIT) &&
+			    !file_can_poll(req->file))
 				req->flags |= REQ_F_MUST_PUNT;
 			return -EAGAIN;
 		}
@@ -2723,7 +2724,8 @@ static int io_write(struct io_kiocb *req, bool force_nonblock)
 			if (ret)
 				goto out_free;
 			/* any defer here is final, must blocking retry */
-			req->flags |= REQ_F_MUST_PUNT;
+			if (!file_can_poll(req->file))
+				req->flags |= REQ_F_MUST_PUNT;
 			return -EAGAIN;
 		}
 	}
-- 
2.26.2


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

end of thread, other threads:[~2020-04-28 19:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-28 19:20 [PATCHSET 0/2] io_uring tweaks for poll retry Jens Axboe
2020-04-28 19:20 ` [PATCH 1/2] io_uring: enable poll retry for any file with ->read_iter / ->write_iter Jens Axboe
2020-04-28 19:20 ` [PATCH 2/2] io_uring: only force async punt if poll based retry can't handle it Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox