From: Jens Axboe <[email protected]>
To: [email protected]
Cc: Jens Axboe <[email protected]>
Subject: [PATCH 3/4] io-wq: allow lookup of existing io_wq with given id
Date: Fri, 24 Jan 2020 14:31:40 -0700 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
If the id and user/creds match, return an existing io_wq if we can safely
grab a reference to it.
Signed-off-by: Jens Axboe <[email protected]>
---
fs/io-wq.c | 37 ++++++++++++++++++++++++++++++++++++-
fs/io-wq.h | 11 ++++++++++-
2 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/fs/io-wq.c b/fs/io-wq.c
index 51b3677d6fbd..08ef69b498f6 100644
--- a/fs/io-wq.c
+++ b/fs/io-wq.c
@@ -1024,7 +1024,7 @@ void io_wq_flush(struct io_wq *wq)
}
}
-struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data)
+static struct io_wq *__io_wq_create(unsigned bounded, struct io_wq_data *data)
{
int ret = -ENOMEM, node;
struct io_wq *wq;
@@ -1106,6 +1106,36 @@ struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data)
return ERR_PTR(ret);
}
+static bool io_wq_match(struct io_wq *wq, struct io_wq_data *data)
+{
+ if (data->creds != wq->creds || data->user != wq->user)
+ return false;
+ if (data->get_work != wq->get_work || data->put_work != wq->put_work)
+ return false;
+ return refcount_inc_not_zero(&wq->use_refs);
+}
+
+/*
+ * Find and return io_wq with given id and grab a reference to it.
+ */
+struct io_wq *io_wq_create_id(unsigned bounded, struct io_wq_data *data,
+ unsigned int id)
+{
+ if (id) {
+ struct io_wq *wq;
+
+ mutex_lock(&wq_lock);
+ wq = idr_find(&wq_idr, id);
+ if (wq && io_wq_match(wq, data)) {
+ mutex_unlock(&wq_lock);
+ return wq;
+ }
+ mutex_unlock(&wq_lock);
+ }
+
+ return __io_wq_create(bounded, data);
+}
+
static bool io_wq_worker_wake(struct io_worker *worker, void *data)
{
wake_up_process(worker->task);
@@ -1145,3 +1175,8 @@ void io_wq_destroy(struct io_wq *wq)
__io_wq_destroy(wq);
}
}
+
+unsigned int io_wq_id(struct io_wq *wq)
+{
+ return wq->id;
+}
diff --git a/fs/io-wq.h b/fs/io-wq.h
index 1cd039af8813..dee7bb3b7cd4 100644
--- a/fs/io-wq.h
+++ b/fs/io-wq.h
@@ -97,8 +97,17 @@ struct io_wq_data {
put_work_fn *put_work;
};
-struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data);
+struct io_wq *io_wq_create_id(unsigned bounded, struct io_wq_data *data,
+ unsigned int id);
+
+static inline struct io_wq *io_wq_create(unsigned bounded,
+ struct io_wq_data *data)
+{
+ return io_wq_create_id(bounded, data, 0);
+}
+
void io_wq_destroy(struct io_wq *wq);
+unsigned int io_wq_id(struct io_wq *wq);
void io_wq_enqueue(struct io_wq *wq, struct io_wq_work *work);
void io_wq_enqueue_hashed(struct io_wq *wq, struct io_wq_work *work, void *val);
--
2.25.0
next prev parent reply other threads:[~2020-01-24 21:31 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-24 21:31 [PATCHSET v2 0/4] Add support for shared io-wq backends Jens Axboe
2020-01-24 21:31 ` [PATCH 1/4] io-wq: make the io_wq ref counted Jens Axboe
2020-01-24 21:31 ` [PATCH 2/4] io-wq: add 'id' to io_wq Jens Axboe
2020-01-24 21:31 ` Jens Axboe [this message]
2020-01-24 21:31 ` [PATCH 4/4] io_uring: add support for sharing kernel io-wq workqueue Jens Axboe
2020-01-25 7:45 ` Stefan Metzmacher
2020-01-25 16:44 ` Jens Axboe
-- strict thread matches above, loose matches on Subject: below --
2020-01-23 23:16 [PATCHSET 0/4] Add support for shared io-wq backends Jens Axboe
2020-01-23 23:16 ` [PATCH 3/4] io-wq: allow lookup of existing io_wq with given id Jens Axboe
2020-01-24 9:54 ` Stefan Metzmacher
2020-01-24 16:41 ` 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 \
[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