From patchwork Thu Jan 16 23:17:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13942462 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35909246A09 for ; Thu, 16 Jan 2025 23:17:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069449; cv=none; b=Vo3HYL2qNTU6FIx/cgvqHpwrnmM0YC59vvTbOTxbTmcSm2N7sL8dI4yHE0VkDTwpKGw2QNiS07Vi1ulYxuCyUkmztGKA4eXsnysztKwVPQle+z/3w4j57ArydIDMfU80ahKsijnxD3qno5N6CiZ+lms+OXv+3wKXhaCHYfYHEvE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737069449; c=relaxed/simple; bh=a0yytqucfmG1Nfx2iu7A4JDn1CAOzvKCv+TQ/9N91bk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CUldC7zUfbFMd4l9kRgJGbxLA+OY0E8iVggL0TeSoygJ9BA74cY9iVS2IK40JUWIN19dHH5lNAGGJ5SF7OGwTGrZrgGubExyRuRD0U/p5zSA1iOm/UG+Zpp8zunD2VeKhtWgiUzjAzfNMmvAL52zzJ6wI3RMmhpSTFo3iAoyR3U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk; spf=none smtp.mailfrom=davidwei.uk; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b=O+gLlPkV; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b="O+gLlPkV" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-21661be2c2dso28582925ad.1 for ; Thu, 16 Jan 2025 15:17:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1737069447; x=1737674247; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SuAE6fDwK//h41IEaYgXJ1RaqDuWb9ybdIHvBrGsuDQ=; b=O+gLlPkV52bHn1XRniav5XFAlgW77hcATQL58hLTv+u9mXVeYbbGONGivIWbhIxK0M WlNEHeU+vjFJ03pglNcqyO6nTRkmYt7/4AEm7yP6bsBrjIa3axP6g0clwItFl3mcTciN Qo2UaOp5FW121vekzW11r5lDbLmxKswD8BhtRFC29jS3WM2V2c296b7UvxqlTTFVJdwv t2ZDn6NTWzZzRw97seYPK0SNVMfUjHXmXzX1a/+7+7ozRlmUxWJ+MjbHF7xtEmkXHr4R oHAGgj9ETbPndG5LDVt5hF2K4Z01kUoDiI8fzUmIVtrWKR0uUO6CuNP/dKmDGqKuF0Vc L4Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737069447; x=1737674247; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SuAE6fDwK//h41IEaYgXJ1RaqDuWb9ybdIHvBrGsuDQ=; b=mVApsHg3z+8ly5iLpzVrynqMm56LP0kIT3fKZkiFuW40yQabBgeqhzCrCOjably7bW JZLgXS9mQb+gqGByf2EMQFKYZ9CO3jQThCgslAmOGfcf8Pn1gusWsOMeH/lcgx2IiTWQ 0y0Q2h14VDlgJmdvuBcHEfIdeJWgUajsLfpomH9Pkjg09+LSqLXUsbgBWcmDLGf8UGn3 LRyJQ84uz7Gsl+ossRy9o4ToQAtcIwK57sbLIEIdoqy2yrztY/TcVg41wtX48EBIidHT yshRP7osbz+RP7eXZ5yuSDN/ARnNHGu3RtB2VLDOAlpCUiU7cZ6ERiNBTn9ZfbGPxMak zpvA== X-Forwarded-Encrypted: i=1; AJvYcCUapOTshnOlvhpizREFgdSc0NRtdwTavK6sStYgS+iw0fgVwp8KIuvGXtF4ehVW3sQyyrZ2G+g=@vger.kernel.org X-Gm-Message-State: AOJu0YyYyL/rYJkVvqpCXj1c9REnRW48jskWNZ9dVKreNVAUmfyqrM70 +QjRjd/qowNn1TFQKshnsCrapjJbTi/+1cYafb1Bco0FQce5HhFTekybXWrtBzI= X-Gm-Gg: ASbGncuB1LIqC9S4fa6XdCgoP0UYVeM3iclwq8RYiVr7JEA282TXD6/+x6j3xq5oxlb +it3u5RiufJdOClf+YRWv9KuJ717W7onuG6Gr9jhyQ/gKTDnOBOzIoZ51BtY8UsHjuG22g6WzbX YTQtYyBfA085JkVWCNssKROidjPXZ5UYWUp+eh+8IVbealeRbvo7mysRY4bUAClsn0kaHuHzF8O wXvkRS5aGUIK6E3ZK6OqqOeWusLWZLPPj1LaxMJeQ== X-Google-Smtp-Source: AGHT+IFqPtYTzhwR/lxML7Vm56sgRoBNvogqzdMHmjzhV3yhmtRlZcd4FMZX5F+JH/qyvtKHo2F0KQ== X-Received: by 2002:a17:903:947:b0:216:5b64:90f6 with SMTP id d9443c01a7336-21c355fa2eamr7843835ad.45.1737069447373; Thu, 16 Jan 2025 15:17:27 -0800 (PST) Received: from localhost ([2a03:2880:ff:14::]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2d404755sm4862385ad.243.2025.01.16.15.17.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 15:17:27 -0800 (PST) From: David Wei To: io-uring@vger.kernel.org, netdev@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov , Jakub Kicinski , Paolo Abeni , "David S. Miller" , Eric Dumazet , Jesper Dangaard Brouer , David Ahern , Mina Almasry , Stanislav Fomichev , Joe Damato , Pedro Tammela Subject: [PATCH net-next v11 18/21] io_uring/zcrx: throttle receive requests Date: Thu, 16 Jan 2025 15:17:00 -0800 Message-ID: <20250116231704.2402455-19-dw@davidwei.uk> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250116231704.2402455-1-dw@davidwei.uk> References: <20250116231704.2402455-1-dw@davidwei.uk> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Pavel Begunkov 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 Signed-off-by: Pavel Begunkov Signed-off-by: David Wei --- io_uring/net.c | 2 ++ io_uring/zcrx.c | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/io_uring/net.c b/io_uring/net.c index 5d8b9a016766..86eaba37e739 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -1267,6 +1267,8 @@ int io_recvzc(struct io_kiocb *req, unsigned int issue_flags) if (unlikely(ret <= 0) && ret != -EAGAIN) { if (ret == -ERESTARTSYS) ret = -EINTR; + if (ret == IOU_REQUEUE) + return IOU_REQUEUE; req_set_fail(req); io_req_set_res(req, ret, 0); diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c index 0cfa8c0ecff8..6f3fbb9337db 100644 --- a/io_uring/zcrx.c +++ b/io_uring/zcrx.c @@ -94,10 +94,13 @@ static void io_zcrx_sync_for_device(const struct page_pool *pool, #define IO_RQ_MAX_ENTRIES 32768 +#define IO_SKBS_PER_CALL_LIMIT 20 + struct io_zcrx_args { struct io_kiocb *req; struct io_zcrx_ifq *ifq; struct socket *sock; + unsigned nr_skbs; }; static const struct memory_provider_ops io_uring_pp_zc_ops; @@ -713,6 +716,9 @@ io_zcrx_recv_skb(read_descriptor_t *desc, struct sk_buff *skb, int i, copy, end, off; int ret = 0; + if (unlikely(args->nr_skbs++ > IO_SKBS_PER_CALL_LIMIT)) + return -EAGAIN; + start = skb_headlen(skb); start_off = offset; @@ -803,6 +809,9 @@ static int io_zcrx_tcp_recvmsg(struct io_kiocb *req, struct io_zcrx_ifq *ifq, ret = -ENOTCONN; else ret = -EAGAIN; + } else if (unlikely(args.nr_skbs > IO_SKBS_PER_CALL_LIMIT) && + (issue_flags & IO_URING_F_MULTISHOT)) { + ret = IOU_REQUEUE; } else if (sock_flag(sk, SOCK_DONE)) { /* Make it to retry until it finally gets 0. */ if (issue_flags & IO_URING_F_MULTISHOT)