Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

+19 -9
+5 -6
io_uring/rsrc.c
··· 124 124 125 125 node = kzalloc(sizeof(*node), GFP_KERNEL); 126 126 if (node) { 127 - node->ctx = ctx; 127 + node->ctx_ptr = (unsigned long) ctx | type; 128 128 node->refs = 1; 129 - node->type = type; 130 129 } 131 130 return node; 132 131 } ··· 444 445 445 446 void io_free_rsrc_node(struct io_rsrc_node *node) 446 447 { 447 - struct io_ring_ctx *ctx = node->ctx; 448 + struct io_ring_ctx *ctx = io_rsrc_node_ctx(node); 448 449 449 450 lockdep_assert_held(&ctx->uring_lock); 450 451 451 452 if (node->tag) 452 - io_post_aux_cqe(node->ctx, node->tag, 0, 0); 453 + io_post_aux_cqe(ctx, node->tag, 0, 0); 453 454 454 - switch (node->type) { 455 + switch (io_rsrc_node_type(node)) { 455 456 case IORING_RSRC_FILE: 456 457 if (io_slot_file(node)) 457 458 fput(io_slot_file(node)); 458 459 break; 459 460 case IORING_RSRC_BUFFER: 460 461 if (node->buf) 461 - io_buffer_unmap(node->ctx, node); 462 + io_buffer_unmap(ctx, node); 462 463 break; 463 464 default: 464 465 WARN_ON_ONCE(1);
+14 -3
io_uring/rsrc.h
··· 11 11 enum { 12 12 IORING_RSRC_FILE = 0, 13 13 IORING_RSRC_BUFFER = 1, 14 + 15 + IORING_RSRC_TYPE_MASK = 0x3UL, 14 16 }; 15 17 16 18 struct io_rsrc_node { 17 - struct io_ring_ctx *ctx; 19 + unsigned long ctx_ptr; 18 20 int refs; 19 - u16 type; 20 21 21 22 u64 tag; 22 23 union { ··· 101 100 req->rsrc_nodes[IORING_RSRC_BUFFER] = NULL; 102 101 } 103 102 103 + static inline struct io_ring_ctx *io_rsrc_node_ctx(struct io_rsrc_node *node) 104 + { 105 + return (struct io_ring_ctx *) (node->ctx_ptr & ~IORING_RSRC_TYPE_MASK); 106 + } 107 + 108 + static inline int io_rsrc_node_type(struct io_rsrc_node *node) 109 + { 110 + return node->ctx_ptr & IORING_RSRC_TYPE_MASK; 111 + } 112 + 104 113 static inline void io_req_assign_rsrc_node(struct io_kiocb *req, 105 114 struct io_rsrc_node *node) 106 115 { 107 116 node->refs++; 108 - req->rsrc_nodes[node->type] = node; 117 + req->rsrc_nodes[io_rsrc_node_type(node)] = node; 109 118 } 110 119 111 120 int io_files_update(struct io_kiocb *req, unsigned int issue_flags);