8000 vivarium: a router guest for multi-node runs, and the uplink after passt (plan) · Issue #1404 · nixidae/nixidae · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

vivarium: a router guest for multi-node runs, and the uplink after passt (plan) #1404

Open

Description

@Lillecarl

A plan for vivarium's network: a slim router guest for multi-node runs, and what carries a guest's traffic to the internet. Each node of the graph is a measurement, and its result picks the next branch. This body is longer than 20 lines because the graph and the measurement table are the decision.

Where things are today

The idea

A router guest that every guest of a multi-node run connects to:

  • mode uplink: each guest's vec0 is a point-to-point link to the router. The router alone has passt. A forward becomes DNAT on the router.
  • mode all: also every segment becomes a star of point-to-point links to the router, which bridges them. Failure labs then get netem, tc and nftables on a real kernel, on every backend, for guests whose kernel vivarium does not build too (RouterOS, SONiC).

Both modes are a topology rewrite in Nix. Every link to the router has two members, so each is a direct socketpair. The runner does not change. If mode all is fast enough, the runner hub can shrink to capture only.

Graph

flowchart TD
  M1["M1: router guest cost<br/>host RSS + boot s, UML and container"] --> D1{"cheap enough<br/>to require?"}
  M2["M2: throughput<br/>direct / runner hub / via router"] --> D1
  D1 -- yes --> R["router mode uplink + all<br/>(needs #858 on a UML router)"]
  D1 -- no --> H["keep runner hub<br/>add loss/delay in Lan (#858 comment)"]
  R --> B1344["#1344 block/unblock: via router"]
  H --> B1344b["#1344 block/unblock: hub per blocked vlan"]
  M3["M3: what passt per guest costs<br/>RSS, processes, Gbit/s vs gvproxy"] --> D2{"worth replacing?"}
  D2 -- yes --> M4["M4: TSI on krun<br/>port libkrunfw patches to NixOS kernel"]
  D2 -- yes --> M5["M5: UML host-socket family<br/>(research)"]
  D2 -- no --> K["keep passt; router mode<br/>already cuts it to one"]
  R --> D2
Loading

Measurements

node how decides
M1 smallest forwarding guest: UML with busybox and a static agent (the Python agent needs about 192M), and a container guest. host_memory_kib() and boot seconds, for 1 and 8 ports a threshold (proposal: under 64 MiB and 2 s) makes the router a requirement
M2 iperf3, MTU 1500 and 65000, back to back under unshare -rn: direct pair, runner hub, UML router bridge, container router bridge whether mode all can replace the runner hub
M3 checks.uplink-iperf, plus RSS and process count of passt for 8 guests whether N/S needs a new path at all
M4 size of libkrunfw's TSI patch set against our kernel version; a krun guest with TSI krun-only option. No ICMP, no raw sockets, no netlink
M5 read arch/um/os-Linux and how hostfs and the vector driver use SIGIO: can a socket family call host socket()/connect() directly? guess today; not started before D2 says yes

Constraints

  • Every test runs in the Nix sandbox and on every backend. A requirement must work on UML and container with no KVM. A krun-only path (TSI) is an option, never the requirement.
  • macOS has no UML: a router there is a krun guest (vivarium on macOS: the krun backend #1163).
  • A forward through the router changes access.json and ssh_config.

Related: #958 (out-of-band segment), #858 (UML tc), #505 (UML memory), #1163 (krun on macOS, gvproxy), #1179 (krun vec0 MTU), #1344 (block/unblock), #1327 (hub, capture).


Assisted-By: Claude Opus 5.5

Activity

  1. added
    source: vivarium
    on Nov 16, 2026
  2. Lillecarl commented on Nov 16, 2026

    @Lillecarl
    ContributorAuthor

    How the user-space proxies carry ICMP, read in source (gvproxy from /etc/nixpkgs's gvproxy.src, passt 2026_07_16):

    • gvproxy: gVisor's netstack terminates the guest's IP. For an ICMPv4 echo request it opens an unprivileged ping socket (socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP), netIcmp.ListenPacket("udp4", ...)), sends the echo, waits up to 5 s for one reply and writes that reply back into netstack (pkg/services/forwarder/icmp*.go). One socket per request. Every other ICMP type is dropped, and there is no ICMPv6. Windows uses a raw socket instead.
    • passt: the same ping sockets, for ICMPv4 and ICMPv6 (icmp.c, util.c:79-86). It also sets the guest's TTL on outgoing UDP (udp.c:1115) and turns the host's IP_RECVERR errors back into ICMP for the guest (udp.c:597), so a UDP traceroute works.
    • Why it works on both systems: macOS allows ping sockets for every user. Linux allows them for the groups in net.ipv4.ping_group_range (0 2147483647 on this host; NixOS sets it through systemd). A new network namespace starts with 1 0, which is off.
    • Raw sockets: neither proxy has them unprivileged. ICMP beyond echo and errors on UDP, such as a raw-socket tool in the guest, cannot leave through any of these paths.

    What this means for socket passthrough (M4, M5): a ping socket is only one more datagram socket. A passthrough that forwards SOCK_DGRAM/IPPROTO_ICMP and passes IP_TTL and IP_RECVERR through carries what passt carries, with no TCP/IP stack on the host. libkrun's TSI today forwards TCP and UDP only (docs/networking.md: "ICMP ping sockets ... are not supported").

    A trap for the router plan: passthrough proxies the guest's own sockets. Packets the router guest forwards or NATs for other guests are not its sockets, so they never reach the passthrough. A router on a passthrough uplink needs a transparent proxy inside it (TPROXY to local sockets), or it keeps a virtio-net or vec uplink.


    Assisted-By: Claude Opus 5.5

  3. Lillecarl commented on Nov 16, 2026

    @Lillecarl
    ContributorAuthor

    E2: the same router path with a libkrun router (KVM, 2 vCPUs, stock NixOS 6.18 kernel, libkrun's own vsock device). MTU 65000, iperf3 10 s, host load 4-7, runs back to back:

    path guest to host host to guest
    krun router 16.2-16.7 Gbit/s 10.0-10.3 Gbit/s
    krun guest, own passt 4.8-8.3 Gbit/s 13.2-18.1 Gbit/s
    UML router (E4) 5-6 Gbit/s 1.4-5 Gbit/s
    • On krun the router path is in passt's range. On UML it is not.
    • libkrun reads multi-descriptor vsock packets, so it needs no kernel patch or vhost-user backend.
    • Guest to host scales with router vCPUs (1: 11.9, 4: 19.4). Host to guest stays near 10, limited by libkrun's single vsock muxer and virtio-net threads.
    • The router boots in 1.2-1.5 s and uses 0.02 s CPU per 10 s when idle.

    Details: vivarium/docs/design/router-lab.md on the local bookmark explore/router (not pushed).


    Assisted-By: Claude Opus 5.5

  4. Lillecarl commented on Nov 16, 2026

    @Lillecarl
    ContributorAuthor

    E5: UDP and ICMP echo through the krun router work.

    • UDP: nftables tproxy plus a fwmark and a local route. This is not NAT, so the relay keeps its own flow table (30 s idle) instead of conntrack.
    • ICMP echo: the same mark and route deliver the request to a raw socket in the relay. No NFQUEUE. The host sends it through an unprivileged ping socket, and the relay puts the guest's echo id back on the reply.
    • Ping to the host answers in 0.5 ms. TEST-NET gets no reply, and without the mark a ping to an outside address fails (the negative control).
    • iperf3 -u: 600 Mbit/s at 1400 B with 0.1-0.8% loss. 2-5 Gbit/s at 8-32 KB datagrams. The limit is about 70-80 thousand datagrams per second.

    Also measured since E2:

    • A UML client behind the krun router: 14.7 Gbit/s out, 10.4 in, at MTU 65000.
    • The host shows the router's vCPU threads near 100%, but that is KVM halt polling. Inside the guest, the router is 41-82% busy.

    Open decision: without /dev/kvm the router is UML, and at MTU 65000 that is 3-12 times slower than passt (E4).


    Assisted-By: Claude Opus 5.5

  5. Lillecarl commented on Nov 16, 2026

    @Lillecarl
    ContributorAuthor

    E6 and the default case.

    • Forwards (E6, krun): the egress listens on a host port and connects to a unix socket that libkrun listens on. The relay then connects to the guest. 9.2 Gbit/s into the guest, 14.7 out.
    • Default case, back to back, MTU 65000:
    path guest to host host to guest
    UML guest, own passt (today) 20.3 Gbit/s 20.4-20.6 Gbit/s
    UML guest, krun router 14.0-15.4 Gbit/s 9.0-10.2 Gbit/s
    UML guest, UML router 5.0 Gbit/s (8 flows: 12.3) 4.8 Gbit/s (8 flows: 3.8)
    • Nothing measured beats today's passt. Every router path meets the "some Gbit/s" bar.
    • Into the guest, libkrun's single vsock muxer thread is the krun limit. The UML router's own single processor is the UML limit.
    • The UML router's numbers need a lab-only kernel patch and an unreleased vhost-device-vsock.
    • UDP, ICMP and forwards are verified on krun only.

    Assisted-By: Claude Opus 5.5

  6. Lillecarl commented on Nov 16, 2026

    @Lillecarl
    ContributorAuthor

    E7: our own vhost-user vsock device, inside the egress process (lab/router/egress/src/vsock.rs, bookmark explore/router, local).

    It reads a packet from any descriptor chain. A UML router therefore runs the stock kernel, with no vsock-linear-tx.patch and no vhost-device-vsock. MTU 65000, one flow, runs back to back:

    path guest to host host to guest
    UML router, own device, stock kernel 13.2-15.3 Gbit/s 10.9-12.7 Gbit/s
    UML router, vhost-device-vsock, patched kernel 5.0 4.8
    krun router 16.2-16.7 9.8-10.3
    • 80% of TX chains had more than two descriptors, and every byte arrived. The negative control (stock kernel with vhost-device-vsock) delivers 0 bytes.
    • E6 (forward) now runs on UML too: 12.3 Gbit/s into the guest, 15.3 out.
    • Open: several flows into a UML router's guest collapse to 1.2-5.5 Gbit/s, with the router at full CPU. vhost-device-vsock showed the same (3.8). Not explained yet.

    Assisted-By: Claude Opus 5.5

  7. Lillecarl commented on Nov 16, 2026

    @Lillecarl
    ContributorAuthor

    E7 correction and two checks.

    • Correction: with eight flows into the guest, vhost-device-vsock on the patched kernel gave 3.8 Gbit/s; our own device gives 1.2-1.6. My last comment called that "the same". It is worse.
    • Content: e7.py sends 169 MB of seq output each way through the device and compares MD5s. Both match. With the host receiver stalled 5 s, the device spilled 219 KB and both still match.
    • Multi-flow: the guest sends a credit update for almost every 4 KiB packet it gets (409k for 504k), against one per 43 with one flow.
      • Ruled out: the device's interleaving (128 KiB bursts per flow) and its refill (a flow joins the send queue only with half the window free). Both leave the ratio and the rate unchanged.
      • Also ruled out: max_dgram_qlen and dropped frames.
      • Still open.

    Assisted-By: Claude Opus 5.5

  8. Lillecarl commented on Nov 16, 2026

    @Lillecarl
    ContributorAuthor

    E8 (router lab notebook, local bookmark explore/router): what limits the leg into the guest. MTU 65000, one flow unless noted, pairs back to back at host load about 10.

    • libkrun's vsock muxer is not the limit. It uses 4.0 s of a 10 s run, and four router vCPUs do not help (9.0 against 10.0 Gbit/s).
    • The guest's vsock receive window is a limit. Linux gives a vsock socket 256 KiB. With the relay at 4 MiB:
      • krun, host to guest: 7.7-9.6 → 10.9-12.1 Gbit/s.
      • krun, guest to host: 13.8-14.3 → 18.1-18.6.
      • UML, host to guest: 9.7 → 13.1.
    • The UML eight-flow collapse comes from the guest's scheduler. The UML router has one CPU, and each woken relay thread preempts the vsock RX kworker. It reads one packet, and the guest then sends a credit update for that packet. With the relay under SCHED_BATCH, eight flows into the guest go from 1.2-1.3 to 10.1-10.7 Gbit/s. One flow out of the guest loses about 12%, so it stays opt-in. Its latency is not measured yet.

    Assisted-By: Claude Opus 5.5

  9. Lillecarl commented on Nov 16, 2026

    @Lillecarl
    ContributorAuthor

    E8, continued: UML eight-flow collapse fixed in the relay.

    SCHED_BATCH turned out unreliable. Under host load one run collapsed anyway, with 41 ms average and 264 ms maximum pings, so the relay no longer offers it. Instead, the relay now calls sched_yield() before a read when its last read was under 64 KiB. The vsock kworker then finishes queuing its batch, so one read takes many packets. Pairs back to back, host load 7-12:

    UML router no yield yield after a short read
    eight flows into the guest 1.30, 1.15 Gbit/s 7.6, 9.1
    one flow into the guest 13.0, 14.8 13.4, 14.8
    one flow out 16.6, 15.0 15.5, 16.4
    busy ping avg, eight flows in 4.6, 6.7 ms 2.2, 1.5 ms

    The krun router shows no regression. A yield before every read cost one flow into the guest 15-30%, so the yield only follows a short read.


    Assisted-By: Claude Opus 5.5

  10. 56 remaining items

  11. Lillecarl commented on Nov 17, 2026

    @Lillecarl
    ContributorAuthor

    Decision (User, 2026-11-17): vsock is where the uplink goes.

    • Now: vivarium.uplink.proxy defaults to vsock for a NixOS guest on QEMU or krun. The guest runs the router's relay and ruleset in a network namespace behind a veth vec0, and has its own egress on the host. UML, containers and non-NixOS guests keep passt. An uplink.segment takes precedence.
    • Later: once vsock is verified on macOS (vivarium on macOS: the krun backend #1163), passt is deprecated entirely. A guest then runs straight vsock, or vsock through a router guest.
    • Why: the guest has the real Linux network stack, so a test can do anything the kernel allows. That serves n BD0 etwork labs and kernel development as well as tests.

    Landed so far (main at the 735c1dc lock):

    • the router on UML, QEMU and krun;
    • QEMU's vec0 takes vivarium.mtu;
    • the vsock uplink, with checks.lan-vsock and checks.forward-vsock in CI.

    Out of a guest, vsock gives 35-39 Gbit/s on QEMU and krun, against passt's 4-20 (docs/design/router-lab.md).


    Assisted-By: Claude Opus 5.5

  12. Lillecarl commented on Nov 17, 2026

    @Lillecarl
    ContributorAuthor

    Addendum (User, 2026-11-17): gvproxy goes as well. Once vsock and the router are verified on macOS (#1163), both passt and gvproxy are removed. vsock and the router are the only uplinks after that.


    Assisted-By: Claude Opus 5.5

  13. Lillecarl commented on Nov 17, 2026

    @Lillecarl
    ContributorAuthor

    To investigate (User, 2026-11-17): give container guests the same data path, so pasta, the last passt user, can go.

    A container has no vsock, but it needs none. The vsock uplink already runs the relay in a network namespace behind a veth pair. For a container, the relay would reach the egress over a unix socket bind-mounted into the container, which the egress already serves for krun (path mode). The work is one transport switch in the relay, vsock or unix socket, plus the container launcher's mount.

    Why the uplink design carries little of passt's risk: the guest's kernel terminates TCP in the namespace and the host's kernel terminates it at the egress. The egress only splices sockets. What vivarium owns is stream shutdown over vsock, the UDP flow table and the ICMP echo relay, not a TCP stack.


    Assisted-By: Claude Opus 5.5

  14. Lillecarl commented on Nov 17, 2026

    @Lillecarl
    ContributorAuthor

    Router and vsock on macOS are on main; numbers and the libkrun fixes are in #1163. ports = "all" is gone: a forward lists its ports, and runtime forwards are #1414.

    Linux krun with the new libkrun, median of 3 rounds in CI, old / new (Gbit/s): vsock host to guest 7.72 / 7.94, guest to host 12.00 / 11.52; behind the router 4.13 / 6.11 and 5.73 / 7.44. The router path got faster; plain vsock held.

    A krun or QEMU run now puts its router on the same backend by default, so a Mac never needs UML for it.


    Assisted-By: Claude Opus 5.5

  15. Lillecarl commented on Nov 17, 2026

    @Lillecarl
    ContributorAuthor

    macOS AF_UNIX stream sockets get 8 KiB of buffer each way (net.local.stream.sendspace), and the sender's buffer limits the flow. libkrun (nixidae/libkrun 5751da95) and the egress now set 1 MiB on their AF_UNIX sockets, on macOS only.

    One flow, MTU 65000, iperf3 on the host through a forward, median of 3 (host → guest / guest → host):

    uplink before after
    gvproxy 5.2 / 25.7 Gbit/s same
    vsock 7.9 / 8.5 Gbit/s 33.3 / 56.2 Gbit/s
    vsock + router 6.8 / 8.0 Gbit/s 26.3 / 31.4 Gbit/s

    vsock is now faster than gvproxy in both directions. lan-vsock, forward-vsock, router, lan-router and forward-router pass on krun.


    Assisted-By: Claude Opus 5.5

  16. Lillecarl commented on Nov 18, 2026

    @Lillecarl
    ContributorAuthor

    Status 2026-11-18: the router follow-ups are closed. #1521 (the automatic router for every guest), #1522 (container vsock) and #1523 (the router as management switch, and a VRF, relay and DHCP per data network) are done. RouterOS, VyOS and SONiC ask for the router (checks.routeros-router, checks.vyos-router, checks.sonic-router). What stays open here: macOS (#1163; vsock and router networks unmeasured on a Mac) and the uplink subnet (#379).


    Assisted-By: Claude Opus 5.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    source: vivarium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0