Skip to content

Commit 6af82f7

Browse files
committed
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 <[email protected]>
1 parent 01ee194 commit 6af82f7

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

io_uring/rsrc.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,8 @@ struct io_rsrc_node *io_rsrc_node_alloc(struct io_ring_ctx *ctx, int type)
124124

125125
node = kzalloc(sizeof(*node), GFP_KERNEL);
126126
if (node) {
127-
node->ctx = ctx;
127+
node->ctx_ptr = (unsigned long) ctx | type;
128128
node->refs = 1;
129-
node->type = type;
130129
}
131130
return node;
132131
}
@@ -445,21 +444,21 @@ int io_files_update(struct io_kiocb *req, unsigned int issue_flags)
445444

446445
void io_free_rsrc_node(struct io_rsrc_node *node)
447446
{
448-
struct io_ring_ctx *ctx = node->ctx;
447+
struct io_ring_ctx *ctx = io_rsrc_node_ctx(node);
449448

450449
lockdep_assert_held(&ctx->uring_lock);
451450

452451
if (node->tag)
453-
io_post_aux_cqe(node->ctx, node->tag, 0, 0);
452+
io_post_aux_cqe(ctx, node->tag, 0, 0);
454453

455-
switch (node->type) {
454+
switch (io_rsrc_node_type(node)) {
456455
case IORING_RSRC_FILE:
457456
if (io_slot_file(node))
458457
fput(io_slot_file(node));
459458
break;
460459
case IORING_RSRC_BUFFER:
461460
if (node->buf)
462-
io_buffer_unmap(node->ctx, node);
461+
io_buffer_unmap(ctx, node);
463462
break;
464463
default:
465464
WARN_ON_ONCE(1);

io_uring/rsrc.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
enum {
1212
IORING_RSRC_FILE = 0,
1313
IORING_RSRC_BUFFER = 1,
14+
15+
IORING_RSRC_TYPE_MASK = 0x3UL,
1416
};
1517

1618
struct io_rsrc_node {
17-
struct io_ring_ctx *ctx;
19+
unsigned long ctx_ptr;
1820
int refs;
19-
u16 type;
2021

2122
u64 tag;
2223
union {
@@ -100,11 +101,21 @@ static inline void io_req_put_rsrc_nodes(struct io_kiocb *req)
100101
req->rsrc_nodes[IORING_RSRC_BUFFER] = NULL;
101102
}
102103

104+
static inline struct io_ring_ctx *io_rsrc_node_ctx(struct io_rsrc_node *node)
105+
{
106+
return (struct io_ring_ctx *) (node->ctx_ptr & ~IORING_RSRC_TYPE_MASK);
107+
}
108+
109+
static inline int io_rsrc_node_type(struct io_rsrc_node *node)
110+
{
111+
return node->ctx_ptr & IORING_RSRC_TYPE_MASK;
112+
}
113+
103114
static inline void io_req_assign_rsrc_node(struct io_kiocb *req,
104115
struct io_rsrc_node *node)
105116
{
106117
node->refs++;
107-
req->rsrc_nodes[node->type] = node;
118+
req->rsrc_nodes[io_rsrc_node_type(node)] = node;
108119
}
109120

110121
int io_files_update(struct io_kiocb *req, unsigned int issue_flags);

0 commit comments

Comments
 (0)