From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>,
[email protected], [email protected]
Subject: [PATCH v2 3/5] io_uring/io-wq: allow put_work return next work
Date: Sat, 29 Feb 2020 02:37:27 +0300 [thread overview]
Message-ID: <6280f7ebf6bec855f8667ecc7bc97bb07fb39b83.1582932860.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
Formerly work->func() was returning next work to exeucute. Make put_work
do the same. As put_work() is the last thing happening with work during
issuing, it have all info needed to deduce the next job.
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io-wq.c | 17 +++++------------
fs/io-wq.h | 2 +-
fs/io_uring.c | 29 ++++++++++++++++++++++++++---
3 files changed, 32 insertions(+), 16 deletions(-)
diff --git a/fs/io-wq.c b/fs/io-wq.c
index a830eddaffbe..8bdda5e23dcd 100644
--- a/fs/io-wq.c
+++ b/fs/io-wq.c
@@ -443,7 +443,7 @@ static void io_wq_switch_creds(struct io_worker *worker,
static void io_worker_handle_work(struct io_worker *worker)
__releases(wqe->lock)
{
- struct io_wq_work *work, *old_work = NULL, *put_work = NULL;
+ struct io_wq_work *work, *old_work = NULL;
struct io_wqe *wqe = worker->wqe;
struct io_wq *wq = wqe->wq;
@@ -464,8 +464,6 @@ static void io_worker_handle_work(struct io_worker *worker)
wqe->flags |= IO_WQE_FLAG_STALLED;
spin_unlock_irq(&wqe->lock);
- if (put_work && wq->put_work)
- wq->put_work(old_work);
if (!work)
break;
next:
@@ -497,10 +495,8 @@ static void io_worker_handle_work(struct io_worker *worker)
if (test_bit(IO_WQ_BIT_CANCEL, &wq->state))
work->flags |= IO_WQ_WORK_CANCEL;
- if (wq->get_work && !(work->flags & IO_WQ_WORK_INTERNAL)) {
- put_work = work;
+ if (wq->get_work && !(work->flags & IO_WQ_WORK_INTERNAL))
wq->get_work(work);
- }
old_work = work;
work->func(work);
@@ -509,6 +505,9 @@ static void io_worker_handle_work(struct io_worker *worker)
worker->cur_work = NULL;
spin_unlock_irq(&worker->lock);
+ if (wq->put_work && !(work->flags & IO_WQ_WORK_INTERNAL))
+ wq->put_work(&work);
+
spin_lock_irq(&wqe->lock);
if (hash != -1U) {
@@ -517,12 +516,6 @@ static void io_worker_handle_work(struct io_worker *worker)
}
if (work && work != old_work) {
spin_unlock_irq(&wqe->lock);
-
- if (put_work && wq->put_work) {
- wq->put_work(put_work);
- put_work = NULL;
- }
-
/* dependent work not hashed */
hash = -1U;
goto next;
diff --git a/fs/io-wq.h b/fs/io-wq.h
index 508615af4552..f1d717e9acc1 100644
--- a/fs/io-wq.h
+++ b/fs/io-wq.h
@@ -83,7 +83,7 @@ struct io_wq_work {
} while (0) \
typedef void (get_work_fn)(struct io_wq_work *);
-typedef void (put_work_fn)(struct io_wq_work *);
+typedef void (put_work_fn)(struct io_wq_work **);
struct io_wq_data {
struct user_struct *user;
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 54dfa9b71864..5a579f686f9e 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -6064,11 +6064,34 @@ static int io_sqe_files_update(struct io_ring_ctx *ctx, void __user *arg,
return __io_sqe_files_update(ctx, &up, nr_args);
}
-static void io_put_work(struct io_wq_work *work)
+static void io_link_work_cb(struct io_wq_work *work)
{
- struct io_kiocb *req = container_of(work, struct io_kiocb, work);
+ struct io_kiocb *link = work->data;
- io_put_req(req);
+ io_queue_linked_timeout(link);
+ io_wq_submit_work(work);
+}
+
+static void io_wq_assign_next(struct io_wq_work **workptr, struct io_kiocb *req)
+{
+ struct io_kiocb *link;
+
+ io_prep_next_work(req, &link);
+ *workptr = &req->work;
+ if (link) {
+ req->work.func = io_link_work_cb;
+ req->work.data = link;
+ }
+}
+
+static void io_put_work(struct io_wq_work **workptr)
+{
+ struct io_kiocb *req = container_of(*workptr, struct io_kiocb, work);
+ struct io_kiocb *nxt = NULL;
+
+ io_put_req_find_next(req, &nxt);
+ if (nxt)
+ io_wq_assign_next(workptr, nxt);
}
static void io_get_work(struct io_wq_work *work)
--
2.24.0
next prev parent reply other threads:[~2020-02-28 23:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-28 23:37 [PATCH REBASE v2 0/5] return nxt propagation within io-wq ctx Pavel Begunkov
2020-02-28 23:37 ` [PATCH v2 1/5] io_uring: remove @nxt from the handlers Pavel Begunkov
2020-02-28 23:37 ` [PATCH v2 2/5] io_uring/io-wq: pass *work instead of **workptr Pavel Begunkov
2020-02-28 23:37 ` Pavel Begunkov [this message]
2020-02-28 23:37 ` [PATCH v2 4/5] io_uring: remove extra nxt check after punt Pavel Begunkov
2020-02-28 23:37 ` [PATCH v2 5/5] io_uring: remove io_prep_next_work() Pavel Begunkov
2020-02-29 18:44 ` [PATCH REBASE v2 0/5] return nxt propagation within io-wq ctx Pavel Begunkov
2020-02-29 19:00 ` 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=6280f7ebf6bec855f8667ecc7bc97bb07fb39b83.1582932860.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