Skip to content

Commit 6f94cbc

Browse files
committed
io_uring/rsrc: split io_kiocb node type assignments
Currently the io_rsrc_node assignment in io_kiocb is an array of two pointers, as two nodes may be assigned to a request - one file node, and one buffer node. However, the buffer node can co-exist with the provided buffers, as currently it's not supported to use both provided and registered buffers at the same time. This crucially brings struct io_kiocb down to 4 cache lines again, as before it spilled into the 5th cacheline. Signed-off-by: Jens Axboe <[email protected]>
1 parent 6af82f7 commit 6f94cbc

File tree

8 files changed

+29
-17
lines changed

8 files changed

+29
-17
lines changed

include/linux/io_uring_types.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ enum {
475475
REQ_F_BL_EMPTY_BIT,
476476
REQ_F_BL_NO_RECYCLE_BIT,
477477
REQ_F_BUFFERS_COMMIT_BIT,
478+
REQ_F_BUF_NODE_BIT,
478479

479480
/* not a real bit, just to check we're not overflowing the space */
480481
__REQ_F_LAST_BIT,
@@ -553,6 +554,8 @@ enum {
553554
REQ_F_BL_NO_RECYCLE = IO_REQ_FLAG(REQ_F_BL_NO_RECYCLE_BIT),
554555
/* buffer ring head needs incrementing on put */
555556
REQ_F_BUFFERS_COMMIT = IO_REQ_FLAG(REQ_F_BUFFERS_COMMIT_BIT),
557+
/* buf node is valid */
558+
REQ_F_BUF_NODE = IO_REQ_FLAG(REQ_F_BUF_NODE_BIT),
556559
};
557560

558561
typedef void (*io_req_tw_func_t)(struct io_kiocb *req, struct io_tw_state *ts);
@@ -633,6 +636,8 @@ struct io_kiocb {
633636
* REQ_F_BUFFER_RING is set.
634637
*/
635638
struct io_buffer_list *buf_list;
639+
640+
struct io_rsrc_node *buf_node;
636641
};
637642

638643
union {
@@ -642,7 +647,7 @@ struct io_kiocb {
642647
__poll_t apoll_events;
643648
};
644649

645-
struct io_rsrc_node *rsrc_nodes[2];
650+
struct io_rsrc_node *file_node;
646651

647652
atomic_t refs;
648653
bool cancel_seq_set;

io_uring/io_uring.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -948,8 +948,8 @@ void io_req_defer_failed(struct io_kiocb *req, s32 res)
948948
static void io_preinit_req(struct io_kiocb *req, struct io_ring_ctx *ctx)
949949
{
950950
req->ctx = ctx;
951-
req->rsrc_nodes[IORING_RSRC_FILE] = NULL;
952-
req->rsrc_nodes[IORING_RSRC_BUFFER] = NULL;
951+
req->buf_node = NULL;
952+
req->file_node = NULL;
953953
req->link = NULL;
954954
req->async_data = NULL;
955955
/* not necessary, but safer to zero */
@@ -1882,7 +1882,7 @@ inline struct file *io_file_get_fixed(struct io_kiocb *req, int fd,
18821882
io_ring_submit_lock(ctx, issue_flags);
18831883
node = io_rsrc_node_lookup(&ctx->file_table.data, fd);
18841884
if (node) {
1885-
io_req_assign_rsrc_node(req, node);
1885+
io_req_assign_rsrc_node(&req->file_node, node);
18861886
req->flags |= io_slot_flags(node);
18871887
file = io_slot_file(node);
18881888
}

io_uring/net.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1348,7 +1348,8 @@ static int io_send_zc_import(struct io_kiocb *req, unsigned int issue_flags)
13481348
io_ring_submit_lock(ctx, issue_flags);
13491349
node = io_rsrc_node_lookup(&ctx->buf_table, sr->buf_index);
13501350
if (node) {
1351-
io_req_assign_rsrc_node(sr->notif, node);
1351+
io_req_assign_rsrc_node(&sr->notif->buf_node, node);
1352+
sr->notif->flags |= REQ_F_BUF_NODE;
13521353
ret = 0;
13531354
}
13541355
io_ring_submit_unlock(ctx, issue_flags);

io_uring/nop.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ int io_nop(struct io_kiocb *req, unsigned int issue_flags)
6767
io_ring_submit_lock(ctx, issue_flags);
6868
node = io_rsrc_node_lookup(&ctx->buf_table, nop->buffer);
6969
if (node) {
70-
io_req_assign_rsrc_node(req, node);
70+
io_req_assign_rsrc_node(&req->buf_node, node);
71+
req->flags |= REQ_F_BUF_NODE;
7172
ret = 0;
7273
}
7374
io_ring_submit_unlock(ctx, issue_flags);

io_uring/notif.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ struct io_kiocb *io_alloc_notif(struct io_ring_ctx *ctx)
117117
notif->file = NULL;
118118
notif->task = current;
119119
io_get_task_refs(1);
120-
notif->rsrc_nodes[IORING_RSRC_FILE] = NULL;
121-
notif->rsrc_nodes[IORING_RSRC_BUFFER] = NULL;
120+
notif->file_node = NULL;
121+
notif->buf_node = NULL;
122122

123123
nd = io_notif_to_data(notif);
124124
nd->zc_report = false;

io_uring/rsrc.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,14 @@ static inline bool io_reset_rsrc_node(struct io_rsrc_data *data, int index)
9595

9696
static inline void io_req_put_rsrc_nodes(struct io_kiocb *req)
9797
{
98-
io_put_rsrc_node(req->rsrc_nodes[IORING_RSRC_FILE]);
99-
io_put_rsrc_node(req->rsrc_nodes[IORING_RSRC_BUFFER]);
100-
req->rsrc_nodes[IORING_RSRC_FILE] = NULL;
101-
req->rsrc_nodes[IORING_RSRC_BUFFER] = NULL;
98+
if (req->file_node) {
99+
io_put_rsrc_node(req->file_node);
100+
req->file_node = NULL;
101+
}
102+
if (req->flags & REQ_F_BUF_NODE) {
103+
io_put_rsrc_node(req->buf_node);
104+
req->buf_node = NULL;
105+
}
102106
}
103107

104108
static inline struct io_ring_ctx *io_rsrc_node_ctx(struct io_rsrc_node *node)
@@ -111,11 +115,11 @@ static inline int io_rsrc_node_type(struct io_rsrc_node *node)
111115
return node->ctx_ptr & IORING_RSRC_TYPE_MASK;
112116
}
113117

114-
static inline void io_req_assign_rsrc_node(struct io_kiocb *req,
118+
static inline void io_req_assign_rsrc_node(struct io_rsrc_node **dst_node,
115119
struct io_rsrc_node *node)
116120
{
117121
node->refs++;
118-
req->rsrc_nodes[io_rsrc_node_type(node)] = node;
122+
*dst_node = node;
119123
}
120124

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

io_uring/rw.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,8 @@ static int io_prep_rw_fixed(struct io_kiocb *req, const struct io_uring_sqe *sqe
341341
node = io_rsrc_node_lookup(&ctx->buf_table, req->buf_index);
342342
if (!node)
343343
return -EFAULT;
344-
io_req_assign_rsrc_node(req, node);
344+
io_req_assign_rsrc_node(&req->buf_node, node);
345+
req->flags |= REQ_F_BUF_NODE;
345346

346347
io = req->async_data;
347348
ret = io_import_fixed(ddir, &io->iter, node->buf, rw->addr, rw->len);

io_uring/uring_cmd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ int io_uring_cmd_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
219219
* being called. This prevents destruction of the mapped buffer
220220
* we'll need at actual import time.
221221
*/
222-
io_req_assign_rsrc_node(req, node);
222+
io_req_assign_rsrc_node(&req->buf_node, node);
223223
}
224224
ioucmd->cmd_op = READ_ONCE(sqe->cmd_op);
225225

@@ -275,7 +275,7 @@ int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
275275
struct iov_iter *iter, void *ioucmd)
276276
{
277277
struct io_kiocb *req = cmd_to_io_kiocb(ioucmd);
278-
struct io_rsrc_node *node = req->rsrc_nodes[IORING_RSRC_BUFFER];
278+
struct io_rsrc_node *node = req->buf_node;
279279

280280
/* Must have had rsrc_node assigned at prep time */
281281
if (node)

0 commit comments

Comments
 (0)