Skip to content

Commit b2e9685

Browse files
isilenceaxboe
authored andcommitted
io_uring: keep a pointer ref_node in file_data
->cur_refs of struct fixed_file_data always points to percpu_ref embedded into struct fixed_file_ref_node. Don't overuse container_of() and offsetting, and point directly to fixed_file_ref_node. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 600cf3f commit b2e9685

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

fs/io_uring.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ struct fixed_file_data {
210210
struct fixed_file_table *table;
211211
struct io_ring_ctx *ctx;
212212

213-
struct percpu_ref *cur_refs;
213+
struct fixed_file_ref_node *node;
214214
struct percpu_ref refs;
215215
struct completion done;
216216
struct list_head ref_list;
@@ -5980,7 +5980,7 @@ static struct file *io_file_get(struct io_submit_state *state,
59805980
fd = array_index_nospec(fd, ctx->nr_user_files);
59815981
file = io_file_from_index(ctx, fd);
59825982
if (file) {
5983-
req->fixed_file_refs = ctx->file_data->cur_refs;
5983+
req->fixed_file_refs = &ctx->file_data->node->refs;
59845984
percpu_ref_get(req->fixed_file_refs);
59855985
}
59865986
} else {
@@ -7362,7 +7362,7 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
73627362
return PTR_ERR(ref_node);
73637363
}
73647364

7365-
file_data->cur_refs = &ref_node->refs;
7365+
file_data->node = ref_node;
73667366
spin_lock(&file_data->lock);
73677367
list_add(&ref_node->node, &file_data->ref_list);
73687368
spin_unlock(&file_data->lock);
@@ -7432,14 +7432,12 @@ static int io_queue_file_removal(struct fixed_file_data *data,
74327432
struct file *file)
74337433
{
74347434
struct io_file_put *pfile;
7435-
struct percpu_ref *refs = data->cur_refs;
7436-
struct fixed_file_ref_node *ref_node;
7435+
struct fixed_file_ref_node *ref_node = data->node;
74377436

74387437
pfile = kzalloc(sizeof(*pfile), GFP_KERNEL);
74397438
if (!pfile)
74407439
return -ENOMEM;
74417440

7442-
ref_node = container_of(refs, struct fixed_file_ref_node, refs);
74437441
pfile->file = file;
74447442
list_add(&pfile->list, &ref_node->file_list);
74457443

@@ -7522,10 +7520,10 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
75227520
}
75237521

75247522
if (needs_switch) {
7525-
percpu_ref_kill(data->cur_refs);
7523+
percpu_ref_kill(&data->node->refs);
75267524
spin_lock(&data->lock);
75277525
list_add(&ref_node->node, &data->ref_list);
7528-
data->cur_refs = &ref_node->refs;
7526+
data->node = ref_node;
75297527
spin_unlock(&data->lock);
75307528
percpu_ref_get(&ctx->file_data->refs);
75317529
} else

0 commit comments

Comments
 (0)