Skip to content

Commit 6f02527

Browse files
normanmaureraxboe
authored andcommitted
io_uring/net: Allow to do vectorized send
At the moment you have to use sendmsg for vectorized send. While this works it's suboptimal as it also means you need to allocate a struct msghdr that needs to be kept alive until a submission happens. We can remove this limitation by just allowing to use send directly. Signed-off-by: Norman Maurer <[email protected]> Link: https://lore.kernel.org/r/[email protected] [axboe: remove -EINVAL return for SENDMSG and SEND_VECTORIZED] [axboe: allow send_zc to set SEND_VECTORIZED too] Signed-off-by: Jens Axboe <[email protected]>
1 parent 4b290aa commit 6f02527

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

include/uapi/linux/io_uring.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,16 @@ enum io_uring_op {
392392
* the starting buffer ID in cqe->flags as per
393393
* usual for provided buffer usage. The buffers
394394
* will be contiguous from the starting buffer ID.
395+
*
396+
* IORING_SEND_VECTORIZED If set, SEND[_ZC] will take a pointer to a io_vec
397+
* to allow vectorized send operations.
395398
*/
396399
#define IORING_RECVSEND_POLL_FIRST (1U << 0)
397400
#define IORING_RECV_MULTISHOT (1U << 1)
398401
#define IORING_RECVSEND_FIXED_BUF (1U << 2)
399402
#define IORING_SEND_ZC_REPORT_USAGE (1U << 3)
400403
#define IORING_RECVSEND_BUNDLE (1U << 4)
404+
#define IORING_SEND_VECTORIZED (1U << 5)
401405

402406
/*
403407
* cqe.res for IORING_CQE_F_NOTIF if

io_uring/net.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,10 @@ static int io_send_setup(struct io_kiocb *req, const struct io_uring_sqe *sqe)
382382
}
383383
if (req->flags & REQ_F_BUFFER_SELECT)
384384
return 0;
385+
386+
if (sr->flags & IORING_SEND_VECTORIZED)
387+
return io_net_import_vec(req, kmsg, sr->buf, sr->len, ITER_SOURCE);
388+
385389
return import_ubuf(ITER_SOURCE, sr->buf, sr->len, &kmsg->msg.msg_iter);
386390
}
387391

@@ -409,7 +413,7 @@ static int io_sendmsg_setup(struct io_kiocb *req, const struct io_uring_sqe *sqe
409413
return io_net_import_vec(req, kmsg, msg.msg_iov, msg.msg_iovlen, ITER_SOURCE);
410414
}
411415

412-
#define SENDMSG_FLAGS (IORING_RECVSEND_POLL_FIRST | IORING_RECVSEND_BUNDLE)
416+
#define SENDMSG_FLAGS (IORING_RECVSEND_POLL_FIRST | IORING_RECVSEND_BUNDLE | IORING_SEND_VECTORIZED)
413417

414418
int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
415419
{
@@ -1318,7 +1322,8 @@ void io_send_zc_cleanup(struct io_kiocb *req)
13181322
}
13191323

13201324
#define IO_ZC_FLAGS_COMMON (IORING_RECVSEND_POLL_FIRST | IORING_RECVSEND_FIXED_BUF)
1321-
#define IO_ZC_FLAGS_VALID (IO_ZC_FLAGS_COMMON | IORING_SEND_ZC_REPORT_USAGE)
1325+
#define IO_ZC_FLAGS_VALID (IO_ZC_FLAGS_COMMON | IORING_SEND_ZC_REPORT_USAGE | \
1326+
IORING_SEND_VECTORIZED)
13221327

13231328
int io_send_zc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
13241329
{

0 commit comments

Comments
 (0)