From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>,
[email protected], [email protected]
Subject: [PATCH 9/9] io_uring: pass submission ref to async
Date: Sun, 1 Mar 2020 19:18:26 +0300 [thread overview]
Message-ID: <29efa25e63ea86b9b038fff202a5f7423b5482c8.1583078091.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
Currenlty, every async work handler accepts a submission reference,
which it should put. Also there is a reference grabbed in io_get_work()
and dropped in io_put_work(). This patch merge them together.
- So, ownership of the submission reference passed to io-wq, and it'll
be put in io_put_work().
- io_get_put() doesn't take a ref now and so deleted.
- async handlers don't put the submission ref anymore.
- make cancellation bits of io-wq to call {get,put}_work() handlers
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io-wq.c | 17 +++++++++++++----
fs/io_uring.c | 32 +++++++++++++-------------------
2 files changed, 26 insertions(+), 23 deletions(-)
diff --git a/fs/io-wq.c b/fs/io-wq.c
index f9b18c16ebd8..686ad043c6ac 100644
--- a/fs/io-wq.c
+++ b/fs/io-wq.c
@@ -751,14 +751,23 @@ static bool io_wq_can_queue(struct io_wqe *wqe, struct io_wqe_acct *acct,
return true;
}
-static void io_run_cancel(struct io_wq_work *work)
+static void io_run_cancel(struct io_wq_work *work, struct io_wqe *wqe)
{
+ struct io_wq *wq = wqe->wq;
+
do {
struct io_wq_work *old_work = work;
+ bool is_internal = work->flags & IO_WQ_WORK_INTERNAL;
+
+ if (wq->get_work && !is_internal)
+ wq->get_work(work);
work->flags |= IO_WQ_WORK_CANCEL;
work->func(&work);
work = (work == old_work) ? NULL : work;
+
+ if (wq->put_work && !is_internal)
+ wq->put_work(old_work);
} while (work);
}
@@ -775,7 +784,7 @@ static void io_wqe_enqueue(struct io_wqe *wqe, struct io_wq_work *work)
* It's close enough to not be an issue, fork() has the same delay.
*/
if (unlikely(!io_wq_can_queue(wqe, acct, work))) {
- io_run_cancel(work);
+ io_run_cancel(work, wqe);
return;
}
@@ -914,7 +923,7 @@ static enum io_wq_cancel io_wqe_cancel_cb_work(struct io_wqe *wqe,
spin_unlock_irqrestore(&wqe->lock, flags);
if (found) {
- io_run_cancel(work);
+ io_run_cancel(work, wqe);
return IO_WQ_CANCEL_OK;
}
@@ -989,7 +998,7 @@ static enum io_wq_cancel io_wqe_cancel_work(struct io_wqe *wqe,
spin_unlock_irqrestore(&wqe->lock, flags);
if (found) {
- io_run_cancel(work);
+ io_run_cancel(work, wqe);
return IO_WQ_CANCEL_OK;
}
diff --git a/fs/io_uring.c b/fs/io_uring.c
index d456b0ff6835..c6845a1e5aaa 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -1556,12 +1556,13 @@ static struct io_kiocb *io_put_req_submission(struct io_kiocb *req)
return nxt;
}
-static void io_put_req_async_submission(struct io_kiocb *req,
- struct io_wq_work **workptr)
+static void io_steal_work(struct io_kiocb *req,
+ struct io_wq_work **workptr)
{
- static struct io_kiocb *nxt;
+ struct io_kiocb *nxt = NULL;
- nxt = io_put_req_submission(req);
+ if (!(req->flags & REQ_F_DONT_STEAL_NEXT))
+ io_req_find_next(req, &nxt);
if (nxt)
io_wq_assign_next(workptr, nxt);
}
@@ -2575,7 +2576,7 @@ static bool io_req_cancelled(struct io_kiocb *req)
if (req->work.flags & IO_WQ_WORK_CANCEL) {
req_set_fail_links(req);
io_cqring_add_event(req, -ECANCELED);
- io_double_put_req(req);
+ io_put_req(req);
return true;
}
@@ -2603,7 +2604,7 @@ static void io_fsync_finish(struct io_wq_work **workptr)
if (io_req_cancelled(req))
return;
__io_fsync(req);
- io_put_req_async_submission(req, workptr);
+ io_steal_work(req, workptr);
}
static int io_fsync(struct io_kiocb *req, bool force_nonblock)
@@ -2636,7 +2637,7 @@ static void io_fallocate_finish(struct io_wq_work **workptr)
if (io_req_cancelled(req))
return;
__io_fallocate(req);
- io_put_req_async_submission(req, workptr);
+ io_steal_work(req, workptr);
}
static int io_fallocate_prep(struct io_kiocb *req,
@@ -3003,7 +3004,7 @@ static void io_close_finish(struct io_wq_work **workptr)
/* not cancellable, don't do io_req_cancelled() */
__io_close_finish(req);
- io_put_req_async_submission(req, workptr);
+ io_steal_work(req, workptr);
}
static int io_close(struct io_kiocb *req, bool force_nonblock)
@@ -3076,7 +3077,7 @@ static void io_sync_file_range_finish(struct io_wq_work **workptr)
if (io_req_cancelled(req))
return;
__io_sync_file_range(req);
- io_put_req_async_submission(req, workptr);
+ io_steal_work(req, workptr);
}
static int io_sync_file_range(struct io_kiocb *req, bool force_nonblock)
@@ -3446,7 +3447,7 @@ static void io_accept_finish(struct io_wq_work **workptr)
if (io_req_cancelled(req))
return;
__io_accept(req, false);
- io_put_req_async_submission(req, workptr);
+ io_steal_work(req, workptr);
}
#endif
@@ -4716,7 +4717,7 @@ static void io_wq_submit_work(struct io_wq_work **workptr)
io_put_req(req);
}
- io_put_req_async_submission(req, workptr);
+ io_steal_work(req, workptr);
}
static int io_req_needs_file(struct io_kiocb *req, int fd)
@@ -6107,13 +6108,6 @@ static void io_put_work(struct io_wq_work *work)
io_put_req(req);
}
-static void io_get_work(struct io_wq_work *work)
-{
- struct io_kiocb *req = container_of(work, struct io_kiocb, work);
-
- refcount_inc(&req->refs);
-}
-
static int io_init_wq_offload(struct io_ring_ctx *ctx,
struct io_uring_params *p)
{
@@ -6124,7 +6118,7 @@ static int io_init_wq_offload(struct io_ring_ctx *ctx,
int ret = 0;
data.user = ctx->user;
- data.get_work = io_get_work;
+ data.get_work = NULL;
data.put_work = io_put_work;
if (!(p->flags & IORING_SETUP_ATTACH_WQ)) {
--
2.24.0
next prev parent reply other threads:[~2020-03-01 16:19 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-01 16:18 [PATCH RFC 0/9] nxt propagation + locking optimisation Pavel Begunkov
2020-03-01 16:18 ` [PATCH 1/9] io_uring: clean up io_close Pavel Begunkov
2020-03-01 16:18 ` [PATCH 2/9] io-wq: fix IO_WQ_WORK_NO_CANCEL cancellation Pavel Begunkov
2020-03-02 14:24 ` Jens Axboe
2020-03-01 16:18 ` [PATCH 3/9] io_uring: make submission ref putting consistent Pavel Begunkov
2020-03-01 16:18 ` [PATCH 4/9] io_uring: remove @nxt from handlers Pavel Begunkov
2020-03-01 16:18 ` [PATCH 5/9] io_uring: get next req on subm ref drop Pavel Begunkov
2020-03-01 21:31 ` Pavel Begunkov
2020-03-01 16:18 ` [PATCH 6/9] io-wq: shuffle io_worker_handle_work() code Pavel Begunkov
2020-03-01 16:18 ` [PATCH 7/9] io-wq: io_worker_handle_work() optimise locking Pavel Begunkov
2020-03-01 16:18 ` [PATCH 8/9] io-wq: optimise double lock for io_get_next_work() Pavel Begunkov
2020-03-01 16:18 ` Pavel Begunkov [this message]
2020-03-01 21:39 ` [PATCH 9/9] io_uring: pass submission ref to async Pavel Begunkov
2020-03-02 15:08 ` Pavel Begunkov
2020-03-02 15:12 ` Jens Axboe
2020-03-02 15:26 ` Pavel Begunkov
2020-03-01 16:23 ` [PATCH RFC 0/9] nxt propagation + locking optimisation Pavel Begunkov
2020-03-01 16:41 ` Pavel Begunkov
2020-03-01 19:14 ` Jens Axboe
2020-03-01 20:33 ` Pavel Begunkov
2020-03-02 14:39 ` Jens Axboe
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=29efa25e63ea86b9b038fff202a5f7423b5482c8.1583078091.git.asml.silence@gmail.com \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/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