From 983784bc4136b2ca3206691fe03520b3f29577a2 Mon Sep 17 00:00:00 2001 From: Nate Brown Date: Thu, 23 Jul 2026 15:25:27 -0500 Subject: [PATCH] Group the HostInfo fields the packet paths touch --- hostmap.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/hostmap.go b/hostmap.go index 22780fb9..b6ee31b3 100644 --- a/hostmap.go +++ b/hostmap.go @@ -238,18 +238,30 @@ const ( ) type HostInfo struct { + // The first cache line is everything the packet paths touch. Grouping them here means a send or receive + // pulls in one line instead of two, which is what the layout looked like when state lived at the end. + remote atomic.Pointer[netip.AddrPort] - remotes *RemoteList - promoteCounter atomic.Uint32 ConnectionState *ConnectionState - remoteIndexId uint32 - localIndexId uint32 + + // state holds everything the hot paths need to touch per packet, in one word: whether we have seen traffic + // each way since the connection manager last looked, whether it has given up on us, and the + // Interface.rebindEpoch this tunnel last sent under. Keeping the epoch here means it survives the traffic + // bits being cleared, so a tunnel that has not sent since a rebind still notices when it does. + state atomic.Uint32 + + promoteCounter atomic.Uint32 + remoteIndexId uint32 + localIndexId uint32 + remotes *RemoteList // vpnAddrs is a list of vpn addresses assigned to this host that are within our own vpn networks // The host may have other vpn addresses that are outside our // vpn networks but were removed because they are not usable vpnAddrs []netip.Addr + // Everything below is off the packet path: handshakes, relays, roaming and the connection manager. + // networks is a combination of specific vpn addresses (not prefixes!) and full unsafe networks assigned to this host. networks *bart.Table[NetworkType] relayState RelayState @@ -270,12 +282,6 @@ type HostInfo struct { lastRoam time.Time lastRoamRemote netip.AddrPort - // state holds everything the hot paths need to touch per packet, in one word: whether we have seen traffic - // each way since the connection manager last looked, whether it has given up on us, and the - // Interface.rebindEpoch this tunnel last sent under. Keeping the epoch here means it survives the traffic - // bits being cleared, so a tunnel that has not sent since a rebind still notices when it does. - state atomic.Uint32 - // lastUsed tracks the last time ConnectionManager checked the tunnel and it was in use. // This value will be behind against actual tunnel utilization in the hot path. // This should only be used by the ConnectionManagers ticker routine.