Commit 25a15d3c authored by Pavel Begunkov's avatar Pavel Begunkov Committed by Jens Axboe

io_uring: add a helper for putting rsrc nodes

Add a simple helper to encapsulating dropping rsrc nodes references,
it's cleaner and will help if we'd change rsrc refcounting or play with
percpu_ref_put() [no]inlining.
Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/63fdd953ac75898734cd50e8f69e95e6664f46fe.1650311386.git.asml.silence@gmail.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent c1bdf8ed
...@@ -1326,6 +1326,11 @@ static inline void io_req_set_refcount(struct io_kiocb *req) ...@@ -1326,6 +1326,11 @@ static inline void io_req_set_refcount(struct io_kiocb *req)
#define IO_RSRC_REF_BATCH 100 #define IO_RSRC_REF_BATCH 100
static void io_rsrc_put_node(struct io_rsrc_node *node, int nr)
{
percpu_ref_put_many(&node->refs, nr);
}
static inline void io_req_put_rsrc_locked(struct io_kiocb *req, static inline void io_req_put_rsrc_locked(struct io_kiocb *req,
struct io_ring_ctx *ctx) struct io_ring_ctx *ctx)
__must_hold(&ctx->uring_lock) __must_hold(&ctx->uring_lock)
...@@ -1336,21 +1341,21 @@ static inline void io_req_put_rsrc_locked(struct io_kiocb *req, ...@@ -1336,21 +1341,21 @@ static inline void io_req_put_rsrc_locked(struct io_kiocb *req,
if (node == ctx->rsrc_node) if (node == ctx->rsrc_node)
ctx->rsrc_cached_refs++; ctx->rsrc_cached_refs++;
else else
percpu_ref_put(&node->refs); io_rsrc_put_node(node, 1);
} }
} }
static inline void io_req_put_rsrc(struct io_kiocb *req, struct io_ring_ctx *ctx) static inline void io_req_put_rsrc(struct io_kiocb *req, struct io_ring_ctx *ctx)
{ {
if (req->rsrc_node) if (req->rsrc_node)
percpu_ref_put(&req->rsrc_node->refs); io_rsrc_put_node(req->rsrc_node, 1);
} }
static __cold void io_rsrc_refs_drop(struct io_ring_ctx *ctx) static __cold void io_rsrc_refs_drop(struct io_ring_ctx *ctx)
__must_hold(&ctx->uring_lock) __must_hold(&ctx->uring_lock)
{ {
if (ctx->rsrc_cached_refs) { if (ctx->rsrc_cached_refs) {
percpu_ref_put_many(&ctx->rsrc_node->refs, ctx->rsrc_cached_refs); io_rsrc_put_node(ctx->rsrc_node, ctx->rsrc_cached_refs);
ctx->rsrc_cached_refs = 0; ctx->rsrc_cached_refs = 0;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment