mirror of
https://github.com/torvalds/linux.git
synced 2024-11-22 04:02:20 +00:00
io_uring/rsrc: encode node type and ctx together
Rather than keep the type field separate rom ctx, use the fact that we can encode up to 4 types of nodes in the LSB of the ctx pointer. Doesn't reclaim any space right now on 64-bit archs, but it leaves a full int for future use. Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
01ee194d1a
commit
6af82f7614
@ -124,9 +124,8 @@ struct io_rsrc_node *io_rsrc_node_alloc(struct io_ring_ctx *ctx, int type)
|
|||||||
|
|
||||||
node = kzalloc(sizeof(*node), GFP_KERNEL);
|
node = kzalloc(sizeof(*node), GFP_KERNEL);
|
||||||
if (node) {
|
if (node) {
|
||||||
node->ctx = ctx;
|
node->ctx_ptr = (unsigned long) ctx | type;
|
||||||
node->refs = 1;
|
node->refs = 1;
|
||||||
node->type = type;
|
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
@ -445,21 +444,21 @@ int io_files_update(struct io_kiocb *req, unsigned int issue_flags)
|
|||||||
|
|
||||||
void io_free_rsrc_node(struct io_rsrc_node *node)
|
void io_free_rsrc_node(struct io_rsrc_node *node)
|
||||||
{
|
{
|
||||||
struct io_ring_ctx *ctx = node->ctx;
|
struct io_ring_ctx *ctx = io_rsrc_node_ctx(node);
|
||||||
|
|
||||||
lockdep_assert_held(&ctx->uring_lock);
|
lockdep_assert_held(&ctx->uring_lock);
|
||||||
|
|
||||||
if (node->tag)
|
if (node->tag)
|
||||||
io_post_aux_cqe(node->ctx, node->tag, 0, 0);
|
io_post_aux_cqe(ctx, node->tag, 0, 0);
|
||||||
|
|
||||||
switch (node->type) {
|
switch (io_rsrc_node_type(node)) {
|
||||||
case IORING_RSRC_FILE:
|
case IORING_RSRC_FILE:
|
||||||
if (io_slot_file(node))
|
if (io_slot_file(node))
|
||||||
fput(io_slot_file(node));
|
fput(io_slot_file(node));
|
||||||
break;
|
break;
|
||||||
case IORING_RSRC_BUFFER:
|
case IORING_RSRC_BUFFER:
|
||||||
if (node->buf)
|
if (node->buf)
|
||||||
io_buffer_unmap(node->ctx, node);
|
io_buffer_unmap(ctx, node);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
WARN_ON_ONCE(1);
|
WARN_ON_ONCE(1);
|
||||||
|
@ -11,12 +11,13 @@
|
|||||||
enum {
|
enum {
|
||||||
IORING_RSRC_FILE = 0,
|
IORING_RSRC_FILE = 0,
|
||||||
IORING_RSRC_BUFFER = 1,
|
IORING_RSRC_BUFFER = 1,
|
||||||
|
|
||||||
|
IORING_RSRC_TYPE_MASK = 0x3UL,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct io_rsrc_node {
|
struct io_rsrc_node {
|
||||||
struct io_ring_ctx *ctx;
|
unsigned long ctx_ptr;
|
||||||
int refs;
|
int refs;
|
||||||
u16 type;
|
|
||||||
|
|
||||||
u64 tag;
|
u64 tag;
|
||||||
union {
|
union {
|
||||||
@ -100,11 +101,21 @@ static inline void io_req_put_rsrc_nodes(struct io_kiocb *req)
|
|||||||
req->rsrc_nodes[IORING_RSRC_BUFFER] = NULL;
|
req->rsrc_nodes[IORING_RSRC_BUFFER] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline struct io_ring_ctx *io_rsrc_node_ctx(struct io_rsrc_node *node)
|
||||||
|
{
|
||||||
|
return (struct io_ring_ctx *) (node->ctx_ptr & ~IORING_RSRC_TYPE_MASK);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int io_rsrc_node_type(struct io_rsrc_node *node)
|
||||||
|
{
|
||||||
|
return node->ctx_ptr & IORING_RSRC_TYPE_MASK;
|
||||||
|
}
|
||||||
|
|
||||||
static inline void io_req_assign_rsrc_node(struct io_kiocb *req,
|
static inline void io_req_assign_rsrc_node(struct io_kiocb *req,
|
||||||
struct io_rsrc_node *node)
|
struct io_rsrc_node *node)
|
||||||
{
|
{
|
||||||
node->refs++;
|
node->refs++;
|
||||||
req->rsrc_nodes[node->type] = node;
|
req->rsrc_nodes[io_rsrc_node_type(node)] = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
int io_files_update(struct io_kiocb *req, unsigned int issue_flags);
|
int io_files_update(struct io_kiocb *req, unsigned int issue_flags);
|
||||||
|
Loading…
Reference in New Issue
Block a user