public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
* [PATCH] treewide: no L2 buffer in splice-only mode
@ 2026-12-03 17:56 Stuart McLaren
  2026-12-04  0:26 ` Jon Maloy
  2026-12-04 22:31 ` Stefano Brivio
  0 siblings, 2 replies; 4+ messages in thread
From: Stuart McLaren @ 2026-12-03 17:56 UTC (permalink / raw)
  To: passt-dev; +Cc: Stuart McLaren

Save memory by not initializing L2 memory buffers when
running in --splice-only mode.

This reduces pasta memory use when running splice only.
For example, on one measured system, VmRSS went from
~12 MB to ~3 MB.

Signed-off-by: Stuart McLaren <stuart.mclaren@hpe.com>
---
 passt.c |  3 ++-
 tap.c   |  2 +-
 tcp.c   |  3 ++-
 udp.c   | 15 ++++++++++-----
 4 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/passt.c b/passt.c
index 1c4f594..65a8419 100644
--- a/passt.c
+++ b/passt.c
@@ -415,7 +415,8 @@ int main(int argc, char **argv)
 	if (fwd_listen_init(c))
 		passt_exit(EXIT_FAILURE);
 
-	proto_update_l2_buf(c->guest_mac);
+	if (!c->splice_only)
+		proto_update_l2_buf(c->guest_mac);
 
 	if (c->ifi4 && !c->no_dhcp)
 		dhcp_init();
diff --git a/tap.c b/tap.c
index 5071837..235b2f5 100644
--- a/tap.c
+++ b/tap.c
@@ -1641,7 +1641,7 @@ void tap_backend_init(struct ctx *c)
 	if (c->mode == MODE_VU) {
 		vu_init(c);
 		tap_sock_update_pool(&c->vdev->memory, 0);
-	} else {
+	} else if (!c->splice_only) {
 		tap_sock_update_pool(pkt_buf, sizeof(pkt_buf));
 	}
 
diff --git a/tcp.c b/tcp.c
index f55cf26..60d133b 100644
--- a/tcp.c
+++ b/tcp.c
@@ -2966,7 +2966,8 @@ int tcp_init(struct ctx *c)
 
 	tcp_get_rto_params(c);
 
-	tcp_sock_iov_init(c);
+	if (!c->splice_only)
+		tcp_sock_iov_init(c);
 
 	memset(init_sock_pool4,		0xff,	sizeof(init_sock_pool4));
 	memset(init_sock_pool6,		0xff,	sizeof(init_sock_pool6));
diff --git a/udp.c b/udp.c
index 7966079..3c6ae69 100644
--- a/udp.c
+++ b/udp.c
@@ -224,20 +224,25 @@ static void udp_iov_init_one(const struct ctx *c, size_t i)
 	struct iovec *siov = &udp_iov_recv[i];
 	struct iovec *tiov = udp_l2_iov[i];
 
+	*siov = IOV_OF_LVALUE(payload->data);
+	mh->msg_iov	= siov;
+	mh->msg_iovlen	= 1;
+
+	/* The L2 buffers are only used by the tap datapath: skip them in
+	 * --splice-only mode so that their pages are never faulted in.
+	 */
+	if (c->splice_only)
+		return;
+
 	*meta = (struct udp_meta_t) {
 		.ip4h = L2_BUF_IP4_INIT(IPPROTO_UDP),
 		.ip6h = L2_BUF_IP6_INIT(IPPROTO_UDP),
 	};
 
-	*siov = IOV_OF_LVALUE(payload->data);
-
 	tiov[UDP_IOV_ETH] = IOV_OF_LVALUE(udp_eth_hdr[i]);
 	tiov[UDP_IOV_TAP] = tap_hdr_iov(c, &meta->taph);
 	tiov[UDP_IOV_PAYLOAD].iov_base = payload;
 	tiov[UDP_IOV_ETH_PAD].iov_base = eth_pad;
-
-	mh->msg_iov	= siov;
-	mh->msg_iovlen	= 1;
 }
 
 /**
-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] treewide: no L2 buffer in splice-only mode
  2026-12-03 17:56 [PATCH] treewide: no L2 buffer in splice-only mode Stuart McLaren
@ 2026-12-04  0:26 ` Jon Maloy
  2026-12-04  6:56   ` Stefano Brivio
  2026-12-04 22:31 ` Stefano Brivio
  1 sibling, 1 reply; 4+ messages in thread
From: Jon Maloy @ 2026-12-04  0:26 UTC (permalink / raw)
  To: Stuart McLaren, passt-dev

On 2026-12-03 12:56, Stuart McLaren wrote:
> Save memory by not initializing L2 memory buffers when
> running in --splice-only mode.

Nice. This looks correct to me: in --splice-only mode we never create
a tap interface, and fwd_nat_from_host() doesn't let us create flows
towards it, so none of those buffers is reachable, and keeping the
receive iovecs in udp_iov_init_one() covers the socket-to-socket path.

But I see a corner case: on master, nothing prevents --splice-only together
with --fd (documented as passt-only), and in that case we actually forward
traffic from the given file descriptor as usual. I checked this with a pipe
as fake tap device, and a UDP datagram from it was forwarded to the
host. With this patch, that traffic is silently dropped instead, as
the packet pools aren't initialised.

In my view, the new behaviour matches better what --splice-only means,
and I doubt anybody uses this combination. If we want to keep the
previous behaviour anyway, the alternative would be to still initialise
the L2 buffers if --fd is given. Something like this:

         !c->splice_only || c->fd_tap != -1

instead of just !c->splice_only, in all the places this patch touches:
not just for the packet pools, but also for the TCP and UDP frames, as
we would need those to send replies back.

I leave the decision about that to Stefano.
///jon

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] treewide: no L2 buffer in splice-only mode
  2026-12-04  0:26 ` Jon Maloy
@ 2026-12-04  6:56   ` Stefano Brivio
  0 siblings, 0 replies; 4+ messages in thread
From: Stefano Brivio @ 2026-12-04  6:56 UTC (permalink / raw)
  To: Jon Maloy, Stuart McLaren; +Cc: passt-dev

On Thu, 3 Dec 2026 19:26:36 -0500
Jon Maloy <jmaloy@redhat.com> wrote:

> On 2026-12-03 12:56, Stuart McLaren wrote:
> > Save memory by not initializing L2 memory buffers when
> > running in --splice-only mode.  
> 
> Nice.

Definitely, thanks Stuart for the patch!

> This looks correct to me: in --splice-only mode we never create
> a tap interface, and fwd_nat_from_host() doesn't let us create flows
> towards it, so none of those buffers is reachable, and keeping the
> receive iovecs in udp_iov_init_one() covers the socket-to-socket path.

This last sentence made me think: could we save some memory there as
well?  In pasta mode, udp_sock_to_sock() transfers one frame at a time,
not UDP_MAX_FRAMES, so we could *probably* initialise a single one in
udp_iov_init(), using some kind of macro expression that yields 1 for
mode == MODE_PASTA and 32 otherwise, for the loop termination.

Note that I haven't tested this though.

> But I see a corner case: on master, nothing prevents --splice-only together
> with --fd (documented as passt-only)

I think this is a small pre-existing bug, because in theory one could
also use it for pasta's tap device (but not for --splice-only), and...

> and in that case we actually forward
> traffic from the given file descriptor as usual. I checked this with a pipe
> as fake tap device, and a UDP datagram from it was forwarded to the
> host. With this patch, that traffic is silently dropped instead, as
> the packet pools aren't initialised.

...this one as well.  We should simply make --splice-only mutually
exclusive with --fd, I think.  If the tap device isn't usable, there's
no point in passing one using a file descriptor.

> In my view, the new behaviour matches better what --splice-only means,
> and I doubt anybody uses this combination. If we want to keep the
> previous behaviour anyway, the alternative would be to still initialise
> the L2 buffers if --fd is given. Something like this:
> 
>          !c->splice_only || c->fd_tap != -1
> 
> instead of just !c->splice_only, in all the places this patch touches:
> not just for the packet pools, but also for the TCP and UDP frames, as
> we would need those to send replies back.
> 
> I leave the decision about that to Stefano.

I agree, I would rather merge this patch as it is, and propose / accept
another patch or two fixing the --splice-only / --fd combination and
documentation of --fd.

-- 
Stefano

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] treewide: no L2 buffer in splice-only mode
  2026-12-03 17:56 [PATCH] treewide: no L2 buffer in splice-only mode Stuart McLaren
  2026-12-04  0:26 ` Jon Maloy
@ 2026-12-04 22:31 ` Stefano Brivio
  1 sibling, 0 replies; 4+ messages in thread
From: Stefano Brivio @ 2026-12-04 22:31 UTC (permalink / raw)
  To: Stuart McLaren; +Cc: passt-dev, Jon Maloy

On Thu,  3 Dec 2026 17:56:24 +0000
Stuart McLaren <stuart.mclaren@hpe.com> wrote:

> Save memory by not initializing L2 memory buffers when
> running in --splice-only mode.
> 
> This reduces pasta memory use when running splice only.
> For example, on one measured system, VmRSS went from
> ~12 MB to ~3 MB.
> 
> Signed-off-by: Stuart McLaren <stuart.mclaren@hpe.com>

Applied, thanks for the patch, and welcome to the git log!

-- 
Stefano

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-04 22:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-03 17:56 [PATCH] treewide: no L2 buffer in splice-only mode Stuart McLaren
2026-12-04  0:26 ` Jon Maloy
2026-12-04  6:56   ` Stefano Brivio
2026-12-04 22:31 ` Stefano Brivio

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).