Skip to content

Commit d3da8e9

Browse files
committed
io_uring/net: add IORING_ACCEPT_POLL_FIRST flag
Similarly to how polling first is supported for receive, it makes sense to provide the same for accept. An accept operation does a lot of expensive setup, like allocating an fd, a socket/inode, etc. If no connection request is already pending, this is wasted and will just be cleaned up and freed, only to retry via the usual poll trigger. Add IORING_ACCEPT_POLL_FIRST, which tells accept to only initiate the accept request if poll says we have something to accept. Signed-off-by: Jens Axboe <[email protected]>
1 parent 7dcc758 commit d3da8e9

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

include/uapi/linux/io_uring.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ enum io_uring_op {
380380
*/
381381
#define IORING_ACCEPT_MULTISHOT (1U << 0)
382382
#define IORING_ACCEPT_DONTWAIT (1U << 1)
383+
#define IORING_ACCEPT_POLL_FIRST (1U << 2)
383384

384385
/*
385386
* IORING_OP_MSG_RING command types, stored in sqe->addr

io_uring/net.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1487,6 +1487,9 @@ void io_sendrecv_fail(struct io_kiocb *req)
14871487
req->cqe.flags |= IORING_CQE_F_MORE;
14881488
}
14891489

1490+
#define ACCEPT_FLAGS (IORING_ACCEPT_MULTISHOT | IORING_ACCEPT_DONTWAIT | \
1491+
IORING_ACCEPT_POLL_FIRST)
1492+
14901493
int io_accept_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
14911494
{
14921495
struct io_accept *accept = io_kiocb_to_cmd(req, struct io_accept);
@@ -1499,7 +1502,7 @@ int io_accept_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
14991502
accept->flags = READ_ONCE(sqe->accept_flags);
15001503
accept->nofile = rlimit(RLIMIT_NOFILE);
15011504
accept->iou_flags = READ_ONCE(sqe->ioprio);
1502-
if (accept->iou_flags & ~(IORING_ACCEPT_MULTISHOT | IORING_ACCEPT_DONTWAIT))
1505+
if (accept->iou_flags & ~ACCEPT_FLAGS)
15031506
return -EINVAL;
15041507

15051508
accept->file_slot = READ_ONCE(sqe->file_index);
@@ -1530,6 +1533,10 @@ int io_accept(struct io_kiocb *req, unsigned int issue_flags)
15301533
struct file *file;
15311534
int ret, fd;
15321535

1536+
if (!(req->flags & REQ_F_POLLED) &&
1537+
accept->iou_flags & IORING_ACCEPT_POLL_FIRST)
1538+
return -EAGAIN;
1539+
15331540
retry:
15341541
if (!fixed) {
15351542
fd = __get_unused_fd_flags(accept->flags, accept->nofile);

0 commit comments

Comments
 (0)