public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: passt-dev@passt.top
Subject: [PATCH v2 1/3] udp: Don't pre-initialize msghdr array
Date: Tue, 13 Sep 2022 16:37:43 +1000	[thread overview]
Message-ID: <20220913063745.3657546-2-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20220913063745.3657546-1-david@gibson.dropbear.id.au>

[-- Attachment #1: Type: text/plain, Size: 1327 bytes --]

In udp_tap_handler() the array of msghdr structures, mm[], is initialized
to zero.  Since UIO_MAXIOV is 1024, this can be quite a large zero, which
is expensive if we only end up using a few of its entries.  It also makes
it less obvious how we're setting all the control fields at the point we
actually invoke sendmmsg().

Rather than pre-initializing it, just initialize each element as we use it.

Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au>
---
 udp.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/udp.c b/udp.c
index c4ebecc..864e7b2 100644
--- a/udp.c
+++ b/udp.c
@@ -968,7 +968,7 @@ void udp_sock_handler(const struct ctx *c, union epoll_ref ref, uint32_t events,
 int udp_tap_handler(struct ctx *c, int af, const void *addr,
 		    const struct pool *p, const struct timespec *now)
 {
-	struct mmsghdr mm[UIO_MAXIOV] = { 0 };
+	struct mmsghdr mm[UIO_MAXIOV];
 	struct iovec m[UIO_MAXIOV];
 	struct sockaddr_in6 s_in6;
 	struct sockaddr_in s_in;
@@ -1087,6 +1087,10 @@ int udp_tap_handler(struct ctx *c, int af, const void *addr,
 		mm[i].msg_hdr.msg_iov = m + i;
 		mm[i].msg_hdr.msg_iovlen = 1;
 
+		mm[i].msg_hdr.msg_control = NULL;
+		mm[i].msg_hdr.msg_controllen = 0;
+		mm[i].msg_hdr.msg_flags = 0;
+
 		count++;
 	}
 
-- 
@@ -968,7 +968,7 @@ void udp_sock_handler(const struct ctx *c, union epoll_ref ref, uint32_t events,
 int udp_tap_handler(struct ctx *c, int af, const void *addr,
 		    const struct pool *p, const struct timespec *now)
 {
-	struct mmsghdr mm[UIO_MAXIOV] = { 0 };
+	struct mmsghdr mm[UIO_MAXIOV];
 	struct iovec m[UIO_MAXIOV];
 	struct sockaddr_in6 s_in6;
 	struct sockaddr_in s_in;
@@ -1087,6 +1087,10 @@ int udp_tap_handler(struct ctx *c, int af, const void *addr,
 		mm[i].msg_hdr.msg_iov = m + i;
 		mm[i].msg_hdr.msg_iovlen = 1;
 
+		mm[i].msg_hdr.msg_control = NULL;
+		mm[i].msg_hdr.msg_controllen = 0;
+		mm[i].msg_hdr.msg_flags = 0;
+
 		count++;
 	}
 
-- 
2.37.3


  reply	other threads:[~2022-09-13  6:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-13  6:37 [PATCH v2 0/3] Don't drop outbound zero-length UDP packets over tap David Gibson
2022-09-13  6:37 ` David Gibson [this message]
2022-09-13  6:37 ` [PATCH v2 2/3] udp: Don't drop zero-length outbound UDP packets David Gibson
2022-09-13  6:37 ` [PATCH v2 3/3] test: Simpler termination handling for UDP tests David Gibson

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=20220913063745.3657546-2-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    /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.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).