Skip to content

Commit fc7f3a8

Browse files
isilenceaxboe
authored andcommitted
io_uring/rsrc: devirtualise rsrc put callbacks
We only have two rsrc types, buffers and files, replace virtual callbacks for putting resources down with a switch..case. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/02ca727bf8e5f7f820c2f404e95ae88c8f472930.1681822823.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 29b26c5 commit fc7f3a8

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

io_uring/rsrc.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ struct io_rsrc_update {
2323
u32 offset;
2424
};
2525

26+
static void io_rsrc_buf_put(struct io_ring_ctx *ctx, struct io_rsrc_put *prsrc);
27+
static void io_rsrc_file_put(struct io_ring_ctx *ctx, struct io_rsrc_put *prsrc);
2628
static int io_sqe_buffer_register(struct io_ring_ctx *ctx, struct iovec *iov,
2729
struct io_mapped_ubuf **pimu,
2830
struct page **last_hpage);
@@ -147,7 +149,18 @@ static void io_rsrc_put_work(struct io_rsrc_node *node)
147149

148150
if (prsrc->tag)
149151
io_post_aux_cqe(data->ctx, prsrc->tag, 0, 0);
150-
data->do_put(data->ctx, prsrc);
152+
153+
switch (data->rsrc_type) {
154+
case IORING_RSRC_FILE:
155+
io_rsrc_file_put(data->ctx, prsrc);
156+
break;
157+
case IORING_RSRC_BUFFER:
158+
io_rsrc_buf_put(data->ctx, prsrc);
159+
break;
160+
default:
161+
WARN_ON_ONCE(1);
162+
break;
163+
}
151164
}
152165

153166
void io_rsrc_node_destroy(struct io_ring_ctx *ctx, struct io_rsrc_node *node)
@@ -297,8 +310,8 @@ static __cold void **io_alloc_page_table(size_t size)
297310
return table;
298311
}
299312

300-
__cold static int io_rsrc_data_alloc(struct io_ring_ctx *ctx,
301-
rsrc_put_fn *do_put, u64 __user *utags,
313+
__cold static int io_rsrc_data_alloc(struct io_ring_ctx *ctx, int type,
314+
u64 __user *utags,
302315
unsigned nr, struct io_rsrc_data **pdata)
303316
{
304317
struct io_rsrc_data *data;
@@ -316,7 +329,7 @@ __cold static int io_rsrc_data_alloc(struct io_ring_ctx *ctx,
316329

317330
data->nr = nr;
318331
data->ctx = ctx;
319-
data->do_put = do_put;
332+
data->rsrc_type = type;
320333
if (utags) {
321334
ret = -EFAULT;
322335
for (i = 0; i < nr; i++) {
@@ -849,7 +862,7 @@ int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
849862
return -EMFILE;
850863
if (nr_args > rlimit(RLIMIT_NOFILE))
851864
return -EMFILE;
852-
ret = io_rsrc_data_alloc(ctx, io_rsrc_file_put, tags, nr_args,
865+
ret = io_rsrc_data_alloc(ctx, IORING_RSRC_FILE, tags, nr_args,
853866
&ctx->file_data);
854867
if (ret)
855868
return ret;
@@ -1184,7 +1197,7 @@ int io_sqe_buffers_register(struct io_ring_ctx *ctx, void __user *arg,
11841197
return -EBUSY;
11851198
if (!nr_args || nr_args > IORING_MAX_REG_BUFFERS)
11861199
return -EINVAL;
1187-
ret = io_rsrc_data_alloc(ctx, io_rsrc_buf_put, tags, nr_args, &data);
1200+
ret = io_rsrc_data_alloc(ctx, IORING_RSRC_BUFFER, tags, nr_args, &data);
11881201
if (ret)
11891202
return ret;
11901203
ret = io_buffers_map_alloc(ctx, nr_args);

io_uring/rsrc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct io_rsrc_data {
3333

3434
u64 **tags;
3535
unsigned int nr;
36-
rsrc_put_fn *do_put;
36+
u16 rsrc_type;
3737
bool quiesce;
3838
};
3939

0 commit comments

Comments
 (0)