From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: zijianzhang@bytedance.com, netdev@vger.kernel.org
Cc: edumazet@google.com, willemdebruijn.kernel@gmail.com,
davem@davemloft.net, kuba@kernel.org, cong.wang@bytedance.com,
xiaochun.lu@bytedance.com,
Zijian Zhang <zijianzhang@bytedance.com>
Subject: Re: [PATCH net-next v2 1/3] selftests: fix OOM problem in msg_zerocopy selftest
Date: Sun, 21 Apr 2024 11:16:50 -0400 [thread overview]
Message-ID: <66252de247122_1dff992949f@willemb.c.googlers.com.notmuch> (raw)
In-Reply-To: <20240419214819.671536-2-zijianzhang@bytedance.com>
zijianzhang@ wrote:
> From: Zijian Zhang <zijianzhang@bytedance.com>
>
> In selftests/net/msg_zerocopy.c, it has a while loop keeps calling sendmsg
> on a socket with MSG_ZEROCOPY flag, and it will recv the notifications
> until the socket is not writable. Typically, it will start the receiving
> process after around 30+ sendmsgs. However, because of the
> commit dfa2f0483360 ("tcp: get rid of sysctl_tcp_adv_win_scale")
> the sender is always writable and does not get any chance to run recv
> notifications. The selftest always exits with OUT_OF_MEMORY because the
> memory used by opt_skb exceeds the core.sysctl_optmem_max.
>
> According to our experiments, this problem can be solved by open the
> DEBUG_LOCKDEP configuration for the kernel.
Not so much solved, as mitigated.
> But it will makes the
> notificatoins disordered even in good commits before
typo: notifications
We still have no explanation for this behavior, right. OOO
notifications for TCP should be extremely rare.
A completion is queued when both the skb with the send() data was sent
and freed, and the ACK arrived, freeing the clone on the retransmit
queue. This is almost certainly some effect of running over loopback.
OOO being rare is also what makes the notification batch mechanism so
effective for TCP.
> commit dfa2f0483360 ("tcp: get rid of sysctl_tcp_adv_win_scale").
>
> We introduce "cfg_notification_limit" to force sender to receive
> notifications after some number of sendmsgs. And, notifications may not
> come in order, because of the reason we present above. We have order
> checking code managed by cfg_verbose.
>
> Signed-off-by: Zijian Zhang <zijianzhang@bytedance.com>
> Signed-off-by: Xiaochun Lu <xiaochun.lu@bytedance.com>
> ---
> tools/testing/selftests/net/msg_zerocopy.c | 16 ++++++++++++++--
> 1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/net/msg_zerocopy.c b/tools/testing/selftests/net/msg_zerocopy.c
> index bdc03a2097e8..6c18b07cab30 100644
> --- a/tools/testing/selftests/net/msg_zerocopy.c
> +++ b/tools/testing/selftests/net/msg_zerocopy.c
> @@ -1,3 +1,4 @@
> +// SPDX-License-Identifier: GPL-2.0
> /* Evaluate MSG_ZEROCOPY
> *
> * Send traffic between two processes over one of the supported
> @@ -85,6 +86,7 @@ static bool cfg_rx;
> static int cfg_runtime_ms = 4200;
> static int cfg_verbose;
> static int cfg_waittime_ms = 500;
> +static int cfg_notification_limit = 32;
> static bool cfg_zerocopy;
>
> static socklen_t cfg_alen;
> @@ -95,6 +97,8 @@ static char payload[IP_MAXPACKET];
> static long packets, bytes, completions, expected_completions;
> static int zerocopied = -1;
> static uint32_t next_completion;
> +/* The number of sendmsgs which have not received notified yet */
> +static uint32_t sendmsg_counter;
>
> static unsigned long gettimeofday_ms(void)
> {
> @@ -208,6 +212,7 @@ static bool do_sendmsg(int fd, struct msghdr *msg, bool do_zerocopy, int domain)
> error(1, errno, "send");
> if (cfg_verbose && ret != len)
> fprintf(stderr, "send: ret=%u != %u\n", ret, len);
> + sendmsg_counter++;
>
> if (len) {
> packets++;
> @@ -435,7 +440,7 @@ static bool do_recv_completion(int fd, int domain)
> /* Detect notification gaps. These should not happen often, if at all.
> * Gaps can occur due to drops, reordering and retransmissions.
> */
> - if (lo != next_completion)
> + if (cfg_verbose && lo != next_completion)
> fprintf(stderr, "gap: %u..%u does not append to %u\n",
> lo, hi, next_completion);
> next_completion = hi + 1;
> @@ -460,6 +465,7 @@ static bool do_recv_completion(int fd, int domain)
> static void do_recv_completions(int fd, int domain)
> {
> while (do_recv_completion(fd, domain)) {}
> + sendmsg_counter = 0;
> }
>
> /* Wait for all remaining completions on the errqueue */
> @@ -549,6 +555,9 @@ static void do_tx(int domain, int type, int protocol)
> else
> do_sendmsg(fd, &msg, cfg_zerocopy, domain);
>
> + if (cfg_zerocopy && sendmsg_counter >= cfg_notification_limit)
> + do_recv_completions(fd, domain);
> +
> while (!do_poll(fd, POLLOUT)) {
> if (cfg_zerocopy)
> do_recv_completions(fd, domain);
> @@ -708,7 +717,7 @@ static void parse_opts(int argc, char **argv)
>
> cfg_payload_len = max_payload_len;
>
> - while ((c = getopt(argc, argv, "46c:C:D:i:mp:rs:S:t:vz")) != -1) {
> + while ((c = getopt(argc, argv, "46c:C:D:i:mp:rs:S:t:vzl:n")) != -1) {
no n defined
please keep lexicographic order
> switch (c) {
> case '4':
> if (cfg_family != PF_UNSPEC)
> @@ -760,6 +769,9 @@ static void parse_opts(int argc, char **argv)
> case 'z':
> cfg_zerocopy = true;
> break;
> + case 'l':
> + cfg_notification_limit = strtoul(optarg, NULL, 0);
> + break;
> }
> }
>
> --
> 2.20.1
>
next prev parent reply other threads:[~2024-04-21 15:16 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-19 21:48 [PATCH net-next v2 0/3] net: A lightweight zero-copy notification zijianzhang
2024-04-19 21:48 ` [PATCH net-next v2 1/3] selftests: fix OOM problem in msg_zerocopy selftest zijianzhang
2024-04-21 15:16 ` Willem de Bruijn [this message]
2024-04-23 19:31 ` [External] " Zijian Zhang
2024-04-19 21:48 ` [PATCH net-next v2 2/3] sock: add MSG_ZEROCOPY notification mechanism based on msg_control zijianzhang
2024-04-21 15:45 ` Willem de Bruijn
2024-04-23 19:51 ` [External] " Zijian Zhang
2024-04-23 3:16 ` kernel test robot
2024-04-19 21:48 ` [PATCH net-next v2 3/3] selftests: add MSG_ZEROCOPY msg_control notification test zijianzhang
2024-04-20 3:47 ` [PATCH net-next v2 0/3] net: A lightweight zero-copy notification Jakub Kicinski
2024-04-23 19:29 ` [External] " Zijian Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=66252de247122_1dff992949f@willemb.c.googlers.com.notmuch \
--to=willemdebruijn.kernel@gmail.com \
--cc=cong.wang@bytedance.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=xiaochun.lu@bytedance.com \
--cc=zijianzhang@bytedance.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox