Skip to content

Commit 931dfae

Browse files
isilenceaxboe
authored andcommitted
io_uring/zcrx: throttle receive requests
io_zc_rx_tcp_recvmsg() continues until it fails or there is nothing to receive. If the other side sends fast enough, we might get stuck in io_zc_rx_tcp_recvmsg() producing more and more CQEs but not letting the user to handle them leading to unbound latencies. Break out of it based on an arbitrarily chosen limit, the upper layer will either return to userspace or requeue the request. Reviewed-by: Jens Axboe <[email protected]> Signed-off-by: Pavel Begunkov <[email protected]> Signed-off-by: David Wei <[email protected]> Acked-by: Jakub Kicinski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent e0793de commit 931dfae

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

io_uring/net.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,8 @@ int io_recvzc(struct io_kiocb *req, unsigned int issue_flags)
12851285
if (unlikely(ret <= 0) && ret != -EAGAIN) {
12861286
if (ret == -ERESTARTSYS)
12871287
ret = -EINTR;
1288+
if (ret == IOU_REQUEUE)
1289+
return IOU_REQUEUE;
12881290

12891291
req_set_fail(req);
12901292
io_req_set_res(req, ret, 0);

io_uring/zcrx.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,13 @@ static void io_zcrx_sync_for_device(const struct page_pool *pool,
9494

9595
#define IO_RQ_MAX_ENTRIES 32768
9696

97+
#define IO_SKBS_PER_CALL_LIMIT 20
98+
9799
struct io_zcrx_args {
98100
struct io_kiocb *req;
99101
struct io_zcrx_ifq *ifq;
100102
struct socket *sock;
103+
unsigned nr_skbs;
101104
};
102105

103106
static const struct memory_provider_ops io_uring_pp_zc_ops;
@@ -720,6 +723,9 @@ io_zcrx_recv_skb(read_descriptor_t *desc, struct sk_buff *skb,
720723
int i, copy, end, off;
721724
int ret = 0;
722725

726+
if (unlikely(args->nr_skbs++ > IO_SKBS_PER_CALL_LIMIT))
727+
return -EAGAIN;
728+
723729
start = skb_headlen(skb);
724730
start_off = offset;
725731

@@ -810,6 +816,9 @@ static int io_zcrx_tcp_recvmsg(struct io_kiocb *req, struct io_zcrx_ifq *ifq,
810816
ret = -ENOTCONN;
811817
else
812818
ret = -EAGAIN;
819+
} else if (unlikely(args.nr_skbs > IO_SKBS_PER_CALL_LIMIT) &&
820+
(issue_flags & IO_URING_F_MULTISHOT)) {
821+
ret = IOU_REQUEUE;
813822
} else if (sock_flag(sk, SOCK_DONE)) {
814823
/* Make it to retry until it finally gets 0. */
815824
if (issue_flags & IO_URING_F_MULTISHOT)

0 commit comments

Comments
 (0)