mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-23 16:53:58 -05:00
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 <axboe@kernel.dk>
This commit is contained in:
parent
7dcc758cca
commit
d3da8e9859
2 changed files with 9 additions and 1 deletions
|
@ -380,6 +380,7 @@ enum io_uring_op {
|
||||||
*/
|
*/
|
||||||
#define IORING_ACCEPT_MULTISHOT (1U << 0)
|
#define IORING_ACCEPT_MULTISHOT (1U << 0)
|
||||||
#define IORING_ACCEPT_DONTWAIT (1U << 1)
|
#define IORING_ACCEPT_DONTWAIT (1U << 1)
|
||||||
|
#define IORING_ACCEPT_POLL_FIRST (1U << 2)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* IORING_OP_MSG_RING command types, stored in sqe->addr
|
* IORING_OP_MSG_RING command types, stored in sqe->addr
|
||||||
|
|
|
@ -1487,6 +1487,9 @@ void io_sendrecv_fail(struct io_kiocb *req)
|
||||||
req->cqe.flags |= IORING_CQE_F_MORE;
|
req->cqe.flags |= IORING_CQE_F_MORE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ACCEPT_FLAGS (IORING_ACCEPT_MULTISHOT | IORING_ACCEPT_DONTWAIT | \
|
||||||
|
IORING_ACCEPT_POLL_FIRST)
|
||||||
|
|
||||||
int io_accept_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
|
int io_accept_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
|
||||||
{
|
{
|
||||||
struct io_accept *accept = io_kiocb_to_cmd(req, struct io_accept);
|
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)
|
||||||
accept->flags = READ_ONCE(sqe->accept_flags);
|
accept->flags = READ_ONCE(sqe->accept_flags);
|
||||||
accept->nofile = rlimit(RLIMIT_NOFILE);
|
accept->nofile = rlimit(RLIMIT_NOFILE);
|
||||||
accept->iou_flags = READ_ONCE(sqe->ioprio);
|
accept->iou_flags = READ_ONCE(sqe->ioprio);
|
||||||
if (accept->iou_flags & ~(IORING_ACCEPT_MULTISHOT | IORING_ACCEPT_DONTWAIT))
|
if (accept->iou_flags & ~ACCEPT_FLAGS)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
accept->file_slot = READ_ONCE(sqe->file_index);
|
accept->file_slot = READ_ONCE(sqe->file_index);
|
||||||
|
@ -1530,6 +1533,10 @@ int io_accept(struct io_kiocb *req, unsigned int issue_flags)
|
||||||
struct file *file;
|
struct file *file;
|
||||||
int ret, fd;
|
int ret, fd;
|
||||||
|
|
||||||
|
if (!(req->flags & REQ_F_POLLED) &&
|
||||||
|
accept->iou_flags & IORING_ACCEPT_POLL_FIRST)
|
||||||
|
return -EAGAIN;
|
||||||
|
|
||||||
retry:
|
retry:
|
||||||
if (!fixed) {
|
if (!fixed) {
|
||||||
fd = __get_unused_fd_flags(accept->flags, accept->nofile);
|
fd = __get_unused_fd_flags(accept->flags, accept->nofile);
|
||||||
|
|
Loading…
Add table
Reference in a new issue