From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH v4 01/26] io_uring: name rsrc bits consistently
Date: Thu, 1 Apr 2021 15:43:40 +0100 [thread overview]
Message-ID: <962f5acdf810f3a62831e65da3932cde24f6d9df.1617287883.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
Keep resource related structs' and functions' naming consistent, in
particular use "io_rsrc" prefix for everything.
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 150 ++++++++++++++++++++++++--------------------------
1 file changed, 71 insertions(+), 79 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 8ad6ab708083..5dfd33753471 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -219,22 +219,22 @@ struct fixed_rsrc_table {
struct file **files;
};
-struct fixed_rsrc_ref_node {
+struct io_rsrc_node {
struct percpu_ref refs;
struct list_head node;
struct list_head rsrc_list;
- struct fixed_rsrc_data *rsrc_data;
+ struct io_rsrc_data *rsrc_data;
void (*rsrc_put)(struct io_ring_ctx *ctx,
struct io_rsrc_put *prsrc);
struct llist_node llist;
bool done;
};
-struct fixed_rsrc_data {
+struct io_rsrc_data {
struct fixed_rsrc_table *table;
struct io_ring_ctx *ctx;
- struct fixed_rsrc_ref_node *node;
+ struct io_rsrc_node *node;
struct percpu_ref refs;
struct completion done;
bool quiesce;
@@ -393,7 +393,7 @@ struct io_ring_ctx {
* readers must ensure that ->refs is alive as long as the file* is
* used. Only updated through io_uring_register(2).
*/
- struct fixed_rsrc_data *file_data;
+ struct io_rsrc_data *file_data;
unsigned nr_user_files;
/* if used, fixed mapped user buffers */
@@ -447,7 +447,7 @@ struct io_ring_ctx {
struct llist_head rsrc_put_llist;
struct list_head rsrc_ref_list;
spinlock_t rsrc_ref_lock;
- struct fixed_rsrc_ref_node *rsrc_backup_node;
+ struct io_rsrc_node *rsrc_backup_node;
struct io_restriction restrictions;
@@ -1024,9 +1024,8 @@ static void io_uring_try_cancel_requests(struct io_ring_ctx *ctx,
struct task_struct *task,
struct files_struct *files);
static void io_uring_cancel_sqpoll(struct io_ring_ctx *ctx);
-static void destroy_fixed_rsrc_ref_node(struct fixed_rsrc_ref_node *ref_node);
-static struct fixed_rsrc_ref_node *alloc_fixed_rsrc_ref_node(
- struct io_ring_ctx *ctx);
+static void io_rsrc_node_destroy(struct io_rsrc_node *ref_node);
+static struct io_rsrc_node *io_rsrc_node_alloc(struct io_ring_ctx *ctx);
static void io_ring_file_put(struct io_ring_ctx *ctx, struct io_rsrc_put *prsrc);
static void io_cqring_fill_event(struct io_kiocb *req, long res);
@@ -1072,7 +1071,7 @@ EXPORT_SYMBOL(io_uring_get_socket);
#define io_for_each_link(pos, head) \
for (pos = (head); pos; pos = pos->link)
-static inline void io_set_resource_node(struct io_kiocb *req)
+static inline void io_req_set_rsrc_node(struct io_kiocb *req)
{
struct io_ring_ctx *ctx = req->ctx;
@@ -6272,7 +6271,7 @@ static void io_wq_submit_work(struct io_wq_work *work)
#endif
#define FFS_MASK ~(FFS_ASYNC_READ|FFS_ASYNC_WRITE|FFS_ISREG)
-static inline struct file **io_fixed_file_slot(struct fixed_rsrc_data *file_data,
+static inline struct file **io_fixed_file_slot(struct io_rsrc_data *file_data,
unsigned i)
{
struct fixed_rsrc_table *table;
@@ -6306,7 +6305,7 @@ static struct file *io_file_get(struct io_submit_state *state,
file_ptr &= ~FFS_MASK;
/* mask in overlapping REQ_F and FFS bits */
req->flags |= (file_ptr << REQ_F_ASYNC_READ_BIT);
- io_set_resource_node(req);
+ io_req_set_rsrc_node(req);
} else {
trace_io_uring_file_get(ctx, fd);
file = __io_file_get(state, fd);
@@ -7060,9 +7059,8 @@ static void __io_sqe_files_unregister(struct io_ring_ctx *ctx)
static void io_rsrc_data_ref_zero(struct percpu_ref *ref)
{
- struct fixed_rsrc_data *data;
+ struct io_rsrc_data *data = container_of(ref, struct io_rsrc_data, refs);
- data = container_of(ref, struct fixed_rsrc_data, refs);
complete(&data->done);
}
@@ -7076,20 +7074,20 @@ static inline void io_rsrc_ref_unlock(struct io_ring_ctx *ctx)
spin_unlock_bh(&ctx->rsrc_ref_lock);
}
-static void io_sqe_rsrc_set_node(struct io_ring_ctx *ctx,
- struct fixed_rsrc_data *rsrc_data,
- struct fixed_rsrc_ref_node *ref_node)
+static void io_rsrc_node_set(struct io_ring_ctx *ctx,
+ struct io_rsrc_data *rsrc_data,
+ struct io_rsrc_node *rsrc_node)
{
io_rsrc_ref_lock(ctx);
- rsrc_data->node = ref_node;
- list_add_tail(&ref_node->node, &ctx->rsrc_ref_list);
+ rsrc_data->node = rsrc_node;
+ list_add_tail(&rsrc_node->node, &ctx->rsrc_ref_list);
io_rsrc_ref_unlock(ctx);
percpu_ref_get(&rsrc_data->refs);
}
-static void io_sqe_rsrc_kill_node(struct io_ring_ctx *ctx, struct fixed_rsrc_data *data)
+static void io_rsrc_node_kill(struct io_ring_ctx *ctx, struct io_rsrc_data *data)
{
- struct fixed_rsrc_ref_node *ref_node = NULL;
+ struct io_rsrc_node *ref_node = NULL;
io_rsrc_ref_lock(ctx);
ref_node = data->node;
@@ -7099,21 +7097,21 @@ static void io_sqe_rsrc_kill_node(struct io_ring_ctx *ctx, struct fixed_rsrc_dat
percpu_ref_kill(&ref_node->refs);
}
-static int io_rsrc_refnode_prealloc(struct io_ring_ctx *ctx)
+static int io_rsrc_node_prealloc(struct io_ring_ctx *ctx)
{
if (ctx->rsrc_backup_node)
return 0;
- ctx->rsrc_backup_node = alloc_fixed_rsrc_ref_node(ctx);
+ ctx->rsrc_backup_node = io_rsrc_node_alloc(ctx);
return ctx->rsrc_backup_node ? 0 : -ENOMEM;
}
-static struct fixed_rsrc_ref_node *
-io_rsrc_refnode_get(struct io_ring_ctx *ctx,
- struct fixed_rsrc_data *rsrc_data,
- void (*rsrc_put)(struct io_ring_ctx *ctx,
- struct io_rsrc_put *prsrc))
+static struct io_rsrc_node *
+io_rsrc_node_get(struct io_ring_ctx *ctx,
+ struct io_rsrc_data *rsrc_data,
+ void (*rsrc_put)(struct io_ring_ctx *ctx,
+ struct io_rsrc_put *prsrc))
{
- struct fixed_rsrc_ref_node *node = ctx->rsrc_backup_node;
+ struct io_rsrc_node *node = ctx->rsrc_backup_node;
WARN_ON_ONCE(!node);
@@ -7123,12 +7121,12 @@ io_rsrc_refnode_get(struct io_ring_ctx *ctx,
return node;
}
-static int io_rsrc_ref_quiesce(struct fixed_rsrc_data *data,
+static int io_rsrc_ref_quiesce(struct io_rsrc_data *data,
struct io_ring_ctx *ctx,
void (*rsrc_put)(struct io_ring_ctx *ctx,
struct io_rsrc_put *prsrc))
{
- struct fixed_rsrc_ref_node *node;
+ struct io_rsrc_node *node;
int ret;
if (data->quiesce)
@@ -7136,10 +7134,10 @@ static int io_rsrc_ref_quiesce(struct fixed_rsrc_data *data,
data->quiesce = true;
do {
- ret = io_rsrc_refnode_prealloc(ctx);
+ ret = io_rsrc_node_prealloc(ctx);
if (ret)
break;
- io_sqe_rsrc_kill_node(ctx, data);
+ io_rsrc_node_kill(ctx, data);
percpu_ref_kill(&data->refs);
flush_delayed_work(&ctx->rsrc_put_work);
@@ -7148,8 +7146,8 @@ static int io_rsrc_ref_quiesce(struct fixed_rsrc_data *data,
break;
percpu_ref_resurrect(&data->refs);
- node = io_rsrc_refnode_get(ctx, data, rsrc_put);
- io_sqe_rsrc_set_node(ctx, data, node);
+ node = io_rsrc_node_get(ctx, data, rsrc_put);
+ io_rsrc_node_set(ctx, data, node);
reinit_completion(&data->done);
mutex_unlock(&ctx->uring_lock);
@@ -7161,9 +7159,9 @@ static int io_rsrc_ref_quiesce(struct fixed_rsrc_data *data,
return ret;
}
-static struct fixed_rsrc_data *alloc_fixed_rsrc_data(struct io_ring_ctx *ctx)
+static struct io_rsrc_data *io_rsrc_data_alloc(struct io_ring_ctx *ctx)
{
- struct fixed_rsrc_data *data;
+ struct io_rsrc_data *data;
data = kzalloc(sizeof(*data), GFP_KERNEL);
if (!data)
@@ -7179,7 +7177,7 @@ static struct fixed_rsrc_data *alloc_fixed_rsrc_data(struct io_ring_ctx *ctx)
return data;
}
-static void free_fixed_rsrc_data(struct fixed_rsrc_data *data)
+static void io_rsrc_data_free(struct io_rsrc_data *data)
{
percpu_ref_exit(&data->refs);
kfree(data->table);
@@ -7188,7 +7186,7 @@ static void free_fixed_rsrc_data(struct fixed_rsrc_data *data)
static int io_sqe_files_unregister(struct io_ring_ctx *ctx)
{
- struct fixed_rsrc_data *data = ctx->file_data;
+ struct io_rsrc_data *data = ctx->file_data;
unsigned nr_tables, i;
int ret;
@@ -7207,7 +7205,7 @@ static int io_sqe_files_unregister(struct io_ring_ctx *ctx)
nr_tables = DIV_ROUND_UP(ctx->nr_user_files, IORING_MAX_FILES_TABLE);
for (i = 0; i < nr_tables; i++)
kfree(data->table[i].files);
- free_fixed_rsrc_data(data);
+ io_rsrc_data_free(data);
ctx->file_data = NULL;
ctx->nr_user_files = 0;
return 0;
@@ -7436,7 +7434,7 @@ static int io_sqe_files_scm(struct io_ring_ctx *ctx)
}
#endif
-static int io_sqe_alloc_file_tables(struct fixed_rsrc_data *file_data,
+static int io_sqe_alloc_file_tables(struct io_rsrc_data *file_data,
unsigned nr_tables, unsigned nr_files)
{
int i;
@@ -7526,9 +7524,9 @@ static void io_ring_file_put(struct io_ring_ctx *ctx, struct io_rsrc_put *prsrc)
#endif
}
-static void __io_rsrc_put_work(struct fixed_rsrc_ref_node *ref_node)
+static void __io_rsrc_put_work(struct io_rsrc_node *ref_node)
{
- struct fixed_rsrc_data *rsrc_data = ref_node->rsrc_data;
+ struct io_rsrc_data *rsrc_data = ref_node->rsrc_data;
struct io_ring_ctx *ctx = rsrc_data->ctx;
struct io_rsrc_put *prsrc, *tmp;
@@ -7552,10 +7550,10 @@ static void io_rsrc_put_work(struct work_struct *work)
node = llist_del_all(&ctx->rsrc_put_llist);
while (node) {
- struct fixed_rsrc_ref_node *ref_node;
+ struct io_rsrc_node *ref_node;
struct llist_node *next = node->next;
- ref_node = llist_entry(node, struct fixed_rsrc_ref_node, llist);
+ ref_node = llist_entry(node, struct io_rsrc_node, llist);
__io_rsrc_put_work(ref_node);
node = next;
}
@@ -7563,27 +7561,23 @@ static void io_rsrc_put_work(struct work_struct *work)
static void io_rsrc_node_ref_zero(struct percpu_ref *ref)
{
- struct fixed_rsrc_ref_node *ref_node;
- struct fixed_rsrc_data *data;
- struct io_ring_ctx *ctx;
+ struct io_rsrc_node *node = container_of(ref, struct io_rsrc_node, refs);
+ struct io_rsrc_data *data = node->rsrc_data;
+ struct io_ring_ctx *ctx = data->ctx;
bool first_add = false;
int delay = HZ;
- ref_node = container_of(ref, struct fixed_rsrc_ref_node, refs);
- data = ref_node->rsrc_data;
- ctx = data->ctx;
-
io_rsrc_ref_lock(ctx);
- ref_node->done = true;
+ node->done = true;
while (!list_empty(&ctx->rsrc_ref_list)) {
- ref_node = list_first_entry(&ctx->rsrc_ref_list,
- struct fixed_rsrc_ref_node, node);
+ node = list_first_entry(&ctx->rsrc_ref_list,
+ struct io_rsrc_node, node);
/* recycle ref nodes in order */
- if (!ref_node->done)
+ if (!node->done)
break;
- list_del(&ref_node->node);
- first_add |= llist_add(&ref_node->llist, &ctx->rsrc_put_llist);
+ list_del(&node->node);
+ first_add |= llist_add(&node->llist, &ctx->rsrc_put_llist);
}
io_rsrc_ref_unlock(ctx);
@@ -7596,10 +7590,9 @@ static void io_rsrc_node_ref_zero(struct percpu_ref *ref)
queue_delayed_work(system_wq, &ctx->rsrc_put_work, delay);
}
-static struct fixed_rsrc_ref_node *alloc_fixed_rsrc_ref_node(
- struct io_ring_ctx *ctx)
+static struct io_rsrc_node *io_rsrc_node_alloc(struct io_ring_ctx *ctx)
{
- struct fixed_rsrc_ref_node *ref_node;
+ struct io_rsrc_node *ref_node;
ref_node = kzalloc(sizeof(*ref_node), GFP_KERNEL);
if (!ref_node)
@@ -7617,19 +7610,18 @@ static struct fixed_rsrc_ref_node *alloc_fixed_rsrc_ref_node(
}
static void init_fixed_file_ref_node(struct io_ring_ctx *ctx,
- struct fixed_rsrc_ref_node *ref_node)
+ struct io_rsrc_node *ref_node)
{
ref_node->rsrc_data = ctx->file_data;
ref_node->rsrc_put = io_ring_file_put;
}
-static void destroy_fixed_rsrc_ref_node(struct fixed_rsrc_ref_node *ref_node)
+static void io_rsrc_node_destroy(struct io_rsrc_node *ref_node)
{
percpu_ref_exit(&ref_node->refs);
kfree(ref_node);
}
-
static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
unsigned nr_args)
{
@@ -7637,8 +7629,8 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
unsigned nr_tables, i;
struct file *file;
int fd, ret = -ENOMEM;
- struct fixed_rsrc_ref_node *ref_node;
- struct fixed_rsrc_data *file_data;
+ struct io_rsrc_node *ref_node;
+ struct io_rsrc_data *file_data;
if (ctx->file_data)
return -EBUSY;
@@ -7647,7 +7639,7 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
if (nr_args > IORING_MAX_FIXED_FILES)
return -EMFILE;
- file_data = alloc_fixed_rsrc_data(ctx);
+ file_data = io_rsrc_data_alloc(ctx);
if (!file_data)
return -ENOMEM;
ctx->file_data = file_data;
@@ -7704,14 +7696,14 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
return ret;
}
- ref_node = alloc_fixed_rsrc_ref_node(ctx);
+ ref_node = io_rsrc_node_alloc(ctx);
if (!ref_node) {
io_sqe_files_unregister(ctx);
return -ENOMEM;
}
init_fixed_file_ref_node(ctx, ref_node);
- io_sqe_rsrc_set_node(ctx, file_data, ref_node);
+ io_rsrc_node_set(ctx, file_data, ref_node);
return ret;
out_fput:
for (i = 0; i < ctx->nr_user_files; i++) {
@@ -7723,7 +7715,7 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
kfree(file_data->table[i].files);
ctx->nr_user_files = 0;
out_free:
- free_fixed_rsrc_data(ctx->file_data);
+ io_rsrc_data_free(ctx->file_data);
ctx->file_data = NULL;
return ret;
}
@@ -7771,10 +7763,10 @@ static int io_sqe_file_register(struct io_ring_ctx *ctx, struct file *file,
#endif
}
-static int io_queue_rsrc_removal(struct fixed_rsrc_data *data, void *rsrc)
+static int io_queue_rsrc_removal(struct io_rsrc_data *data, void *rsrc)
{
struct io_rsrc_put *prsrc;
- struct fixed_rsrc_ref_node *ref_node = data->node;
+ struct io_rsrc_node *ref_node = data->node;
prsrc = kzalloc(sizeof(*prsrc), GFP_KERNEL);
if (!prsrc)
@@ -7786,7 +7778,7 @@ static int io_queue_rsrc_removal(struct fixed_rsrc_data *data, void *rsrc)
return 0;
}
-static inline int io_queue_file_removal(struct fixed_rsrc_data *data,
+static inline int io_queue_file_removal(struct io_rsrc_data *data,
struct file *file)
{
return io_queue_rsrc_removal(data, (void *)file);
@@ -7796,8 +7788,8 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
struct io_uring_rsrc_update *up,
unsigned nr_args)
{
- struct fixed_rsrc_data *data = ctx->file_data;
- struct fixed_rsrc_ref_node *ref_node;
+ struct io_rsrc_data *data = ctx->file_data;
+ struct io_rsrc_node *ref_node;
struct file *file, **file_slot;
__s32 __user *fds;
int fd, i, err;
@@ -7808,7 +7800,7 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
return -EOVERFLOW;
if (done > ctx->nr_user_files)
return -EINVAL;
- err = io_rsrc_refnode_prealloc(ctx);
+ err = io_rsrc_node_prealloc(ctx);
if (err)
return err;
@@ -7864,8 +7856,8 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
if (needs_switch) {
percpu_ref_kill(&data->node->refs);
- ref_node = io_rsrc_refnode_get(ctx, data, io_ring_file_put);
- io_sqe_rsrc_set_node(ctx, data, ref_node);
+ ref_node = io_rsrc_node_get(ctx, data, io_ring_file_put);
+ io_rsrc_node_set(ctx, data, ref_node);
}
return done ? done : err;
}
@@ -8541,7 +8533,7 @@ static void io_ring_ctx_free(struct io_ring_ctx *ctx)
io_destroy_buffers(ctx);
if (ctx->rsrc_backup_node)
- destroy_fixed_rsrc_ref_node(ctx->rsrc_backup_node);
+ io_rsrc_node_destroy(ctx->rsrc_backup_node);
#if defined(CONFIG_UNIX)
if (ctx->ring_sock) {
--
2.24.0
next prev parent reply other threads:[~2021-04-01 17:45 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-01 14:43 [PATCH v4 00/26] ctx wide rsrc nodes + Pavel Begunkov
2021-04-01 14:43 ` Pavel Begunkov [this message]
2021-04-01 14:43 ` [PATCH v4 02/26] io_uring: simplify io_rsrc_node_ref_zero Pavel Begunkov
2021-04-01 14:43 ` [PATCH v4 03/26] io_uring: use rsrc prealloc infra for files reg Pavel Begunkov
2021-04-01 14:43 ` [PATCH v4 04/26] io_uring: encapsulate rsrc node manipulations Pavel Begunkov
2021-04-01 14:43 ` [PATCH v4 05/26] io_uring: move rsrc_put callback into io_rsrc_data Pavel Begunkov
2021-04-01 14:43 ` [PATCH v4 06/26] io_uring: refactor io_queue_rsrc_removal() Pavel Begunkov
2021-04-01 14:43 ` [PATCH v4 07/26] io_uring: ctx-wide rsrc nodes Pavel Begunkov
2021-04-01 14:43 ` [PATCH v4 08/26] io_uring: reuse io_rsrc_node_destroy() Pavel Begunkov
2021-04-01 14:43 ` [PATCH v4 09/26] io_uring: remove useless is_dying check on quiesce Pavel Begunkov
2021-04-01 14:43 ` [PATCH v4 10/26] io_uring: refactor rw reissue Pavel Begunkov
2021-04-01 14:43 ` [PATCH v4 11/26] io_uring: combine lock/unlock sections on exit Pavel Begunkov
2021-04-01 14:43 ` [PATCH v4 12/26] io_uring: better ref handling in poll_remove_one Pavel Begunkov
2021-04-01 14:43 ` [PATCH v4 13/26] io_uring: remove unused hash_wait Pavel Begunkov
2021-04-01 14:43 ` [PATCH v4 14/26] io_uring: refactor io_async_cancel() Pavel Begunkov
2021-04-01 14:43 ` [PATCH v4 15/26] io_uring: improve import_fixed overflow checks Pavel Begunkov
2021-04-01 14:43 ` [PATCH v4 16/26] io_uring: store reg buffer end instead of length Pavel Begunkov
2021-04-01 14:43 ` [PATCH v4 17/26] io_uring: kill unused forward decls Pavel Begunkov
2021-04-01 14:43 ` [PATCH v4 18/26] io_uring: lock annotate timeouts and poll Pavel Begunkov
2021-04-01 14:43 ` [PATCH v4 19/26] io_uring: simplify overflow handling Pavel Begunkov
2021-04-01 14:43 ` [PATCH v4 20/26] io_uring: put link timeout req consistently Pavel Begunkov
2021-04-01 14:44 ` [PATCH v4 21/26] io_uring: deduplicate NOSIGNAL setting Pavel Begunkov
2021-04-01 14:44 ` [PATCH v4 22/26] io_uring: set proper FFS* flags on reg file update Pavel Begunkov
2021-04-01 14:44 ` [PATCH v4 23/26] io_uring: don't quiesce intial files register Pavel Begunkov
2021-04-01 14:44 ` [PATCH v4 24/26] io_uring: refactor file tables alloc/free Pavel Begunkov
2021-04-01 14:44 ` [PATCH v4 25/26] io_uring: encapsulate fixed files into struct Pavel Begunkov
2021-04-01 14:44 ` [PATCH v4 26/26] io_uring: kill outdated comment about splice punt Pavel Begunkov
2021-04-04 19:16 ` [PATCH v4 00/26] ctx wide rsrc nodes + Jens Axboe
2021-04-04 19:22 ` Pavel Begunkov
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=962f5acdf810f3a62831e65da3932cde24f6d9df.1617287883.git.asml.silence@gmail.com \
[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