Skip to content

Commit d581076

Browse files
isilenceaxboe
authored andcommitted
io_uring/rsrc: extract SCM file put helper
SCM file accounting is a slow path and is only used for UNIX files. Extract a helper out of io_rsrc_file_put() that does the SCM unaccounting. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/58cc7bffc2ee96bec8c2b89274a51febcbfa5556.1681210788.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 2933ae6 commit d581076

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

io_uring/rsrc.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -832,20 +832,14 @@ int __io_scm_file_account(struct io_ring_ctx *ctx, struct file *file)
832832
return 0;
833833
}
834834

835-
static void io_rsrc_file_put(struct io_ring_ctx *ctx, struct io_rsrc_put *prsrc)
835+
static __cold void io_rsrc_file_scm_put(struct io_ring_ctx *ctx, struct file *file)
836836
{
837-
struct file *file = prsrc->file;
838837
#if defined(CONFIG_UNIX)
839838
struct sock *sock = ctx->ring_sock->sk;
840839
struct sk_buff_head list, *head = &sock->sk_receive_queue;
841840
struct sk_buff *skb;
842841
int i;
843842

844-
if (!io_file_need_scm(file)) {
845-
fput(file);
846-
return;
847-
}
848-
849843
__skb_queue_head_init(&list);
850844

851845
/*
@@ -895,11 +889,19 @@ static void io_rsrc_file_put(struct io_ring_ctx *ctx, struct io_rsrc_put *prsrc)
895889
__skb_queue_tail(head, skb);
896890
spin_unlock_irq(&head->lock);
897891
}
898-
#else
899-
fput(file);
900892
#endif
901893
}
902894

895+
static void io_rsrc_file_put(struct io_ring_ctx *ctx, struct io_rsrc_put *prsrc)
896+
{
897+
struct file *file = prsrc->file;
898+
899+
if (likely(!io_file_need_scm(file)))
900+
fput(file);
901+
else
902+
io_rsrc_file_scm_put(ctx, file);
903+
}
904+
903905
int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
904906
unsigned nr_args, u64 __user *tags)
905907
{

0 commit comments

Comments
 (0)