* [PATCHSET 0/2] Multishot read tweaks
@ 2024-04-01 17:49 Jens Axboe
2024-04-01 17:49 ` [PATCH 1/2] io_uring/rw: don't allow multishot reads without NOWAIT support Jens Axboe
2024-04-01 17:49 ` [PATCH 2/2] io_uring: disable io-wq execution of multishot NOWAIT requests Jens Axboe
0 siblings, 2 replies; 3+ messages in thread
From: Jens Axboe @ 2024-04-01 17:49 UTC (permalink / raw)
To: io-uring
Hi,
We can't properly support multishot reads unless one of the following
conditions are true:
1) The file supports proper FMODE_NOWAIT
2) Barring proper FMODE_NOWAIT support, the file must be opened in
non-blocking O_NONBLOCK mode
Without either one of those, non-blocking retries cannot be attempted.
And without that, it's pointless to support multishot reads.
If this is attempted, fall back to singleshot mode. This will properly
do the initial CQE posting, but will not set IORING_CQE_F_MORE as we
can't reliably perform the retries that multishot requires.
io_uring/io_uring.c | 13 +++++++++----
io_uring/rw.c | 9 ++++++++-
2 files changed, 17 insertions(+), 5 deletions(-)
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] io_uring/rw: don't allow multishot reads without NOWAIT support
2024-04-01 17:49 [PATCHSET 0/2] Multishot read tweaks Jens Axboe
@ 2024-04-01 17:49 ` Jens Axboe
2024-04-01 17:49 ` [PATCH 2/2] io_uring: disable io-wq execution of multishot NOWAIT requests Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2024-04-01 17:49 UTC (permalink / raw)
To: io-uring; +Cc: Jens Axboe, stable
Supporting multishot reads requires support for NOWAIT, as the
alternative would be always having io-wq execute the work item whenever
the poll readiness triggered. Any fast file type will have NOWAIT
support (eg it understands both O_NONBLOCK and IOCB_NOWAIT). If the
given file type does not, then simply resort to single shot execution.
Cc: [email protected]
Fixes: fc68fcda04910 ("io_uring/rw: add support for IORING_OP_READ_MULTISHOT")
Signed-off-by: Jens Axboe <[email protected]>
---
io_uring/rw.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/io_uring/rw.c b/io_uring/rw.c
index 0585ebcc9773..c8d48287439e 100644
--- a/io_uring/rw.c
+++ b/io_uring/rw.c
@@ -936,6 +936,13 @@ int io_read_mshot(struct io_kiocb *req, unsigned int issue_flags)
ret = __io_read(req, issue_flags);
+ /*
+ * If the file doesn't support proper NOWAIT, then disable multishot
+ * and stay in single shot mode.
+ */
+ if (!io_file_supports_nowait(req))
+ req->flags &= ~REQ_F_APOLL_MULTISHOT;
+
/*
* If we get -EAGAIN, recycle our buffer and just let normal poll
* handling arm it.
@@ -955,7 +962,7 @@ int io_read_mshot(struct io_kiocb *req, unsigned int issue_flags)
/*
* Any successful return value will keep the multishot read armed.
*/
- if (ret > 0) {
+ if (ret > 0 && req->flags & REQ_F_APOLL_MULTISHOT) {
/*
* Put our buffer and post a CQE. If we fail to post a CQE, then
* jump to the termination path. This request is then done.
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] io_uring: disable io-wq execution of multishot NOWAIT requests
2024-04-01 17:49 [PATCHSET 0/2] Multishot read tweaks Jens Axboe
2024-04-01 17:49 ` [PATCH 1/2] io_uring/rw: don't allow multishot reads without NOWAIT support Jens Axboe
@ 2024-04-01 17:49 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2024-04-01 17:49 UTC (permalink / raw)
To: io-uring; +Cc: Jens Axboe, stable
Do the same check for direct io-wq execution for multishot requests that
commit 2a975d426c82 did for the inline execution, and disable multishot
mode (and revert to single shot) if the file type doesn't support NOWAIT,
and isn't opened in O_NONBLOCK mode. For multishot to work properly, it's
a requirement that nonblocking read attempts can be done.
Cc: [email protected]
Signed-off-by: Jens Axboe <[email protected]>
---
io_uring/io_uring.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 5d4b448fdc50..8baf8afb79c2 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -1982,10 +1982,15 @@ void io_wq_submit_work(struct io_wq_work *work)
err = -EBADFD;
if (!io_file_can_poll(req))
goto fail;
- err = -ECANCELED;
- if (io_arm_poll_handler(req, issue_flags) != IO_APOLL_OK)
- goto fail;
- return;
+ if (req->file->f_flags & O_NONBLOCK ||
+ req->file->f_mode & FMODE_NOWAIT) {
+ err = -ECANCELED;
+ if (io_arm_poll_handler(req, issue_flags) != IO_APOLL_OK)
+ goto fail;
+ return;
+ } else {
+ req->flags &= ~REQ_F_APOLL_MULTISHOT;
+ }
}
if (req->flags & REQ_F_FORCE_ASYNC) {
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-04-01 17:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-01 17:49 [PATCHSET 0/2] Multishot read tweaks Jens Axboe
2024-04-01 17:49 ` [PATCH 1/2] io_uring/rw: don't allow multishot reads without NOWAIT support Jens Axboe
2024-04-01 17:49 ` [PATCH 2/2] io_uring: disable io-wq execution of multishot NOWAIT requests Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox