From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202504 header.b=pSNQqkwp; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 4DB9B5A026F for ; Tue, 08 Apr 2025 08:39:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202504; t=1744094394; bh=g3tth/5wYJJ7EFCyyzIXIr6wwIkVK8U74Eo/j5GpuUI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=pSNQqkwpWm+jMM4T4qv/OHYkiJp4E8JLVAVM7KUN97qyVvSb6vsZSOSW9SX43bj00 +/wSXDTgU5Fsna2auBBOiZFsTPVwwDSreZfWjB0Ridn8dbA/GARc9XMIuykNChKjI+ YqrOt1xQcYpZEvRzP6Wvs839BBbXD10wnQQznC8JZRRLBWXq0+rOOZ9HrPZU7nTC3Y UegtTGTLeVxqpA9N1mgH3aeigpeaD240Iuvzba9QaD3+fXw7vfMFFuxanmXrGTLJgf AZJMuxQy2EHpMU3Qt/tNKQFensEPv3JEmIIExYCMT+DHMvr5A1c+BpAX84ixBwD1kb Pi/qd/oVNpIKw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4ZWxJp3NKQz4x04; Tue, 8 Apr 2025 16:39:54 +1000 (AEST) Date: Tue, 8 Apr 2025 16:39:34 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH] udp_flow: Save 8 bytes in struct udp_flow on 64-bit architectures Message-ID: References: <20250408055624.583827-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="Bx7Ekn4Mr0bt6Y5S" Content-Disposition: inline In-Reply-To: <20250408055624.583827-1-sbrivio@redhat.com> Message-ID-Hash: 2UCI4S5UEM6ZYLZQK2TZYHY5LN2L2J7P X-Message-ID-Hash: 2UCI4S5UEM6ZYLZQK2TZYHY5LN2L2J7P X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top, Jon Maloy X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --Bx7Ekn4Mr0bt6Y5S Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Apr 08, 2025 at 07:56:24AM +0200, Stefano Brivio wrote: > Shuffle the fields just added by commits a7775e9550fa ("udp: support > traceroute in direction tap-socket") and 9725e7988837 ("udp_flow: > Don't discard packets that arrive between bind() and connect()"). >=20 > On x86_64, as reported by pahole(1), before: >=20 > struct udp_flow { > struct flow_common f; /* 0 76 */ > /* --- cacheline 1 boundary (64 bytes) was 12 bytes ago --- */ > _Bool closed:1; /* 76: 0 1 */ >=20 > /* XXX 7 bits hole, try to pack */ >=20 > _Bool flush0; /* 77 1 */ > _Bool flush1:1; /* 78: 0 1 */ >=20 > /* XXX 7 bits hole, try to pack */ > /* XXX 1 byte hole, try to pack */ >=20 > time_t ts; /* 80 8 */ > int s[2]; /* 88 8 */ > uint8_t ttl[2]; /* 96 2 */ >=20 > /* size: 104, cachelines: 2, members: 7 */ > /* sum members: 95, holes: 1, sum holes: 1 */ > /* sum bitfield members: 2 bits, bit holes: 2, sum bit holes: 14 = bits */ > /* padding: 6 */ > /* last cacheline: 40 bytes */ > }; >=20 > and after: >=20 > struct udp_flow { > struct flow_common f; /* 0 76 */ > /* --- cacheline 1 boundary (64 bytes) was 12 bytes ago --- */ > uint8_t ttl[2]; /* 76 2 */ > _Bool closed:1; /* 78: 0 1 */ > _Bool flush0:1; /* 78: 1 1 */ > _Bool flush1:1; /* 78: 2 1 */ >=20 > /* XXX 5 bits hole, try to pack */ > /* XXX 1 byte hole, try to pack */ >=20 > time_t ts; /* 80 8 */ > int s[2]; /* 88 8 */ >=20 > /* size: 96, cachelines: 2, members: 7 */ > /* sum members: 94, holes: 1, sum holes: 1 */ > /* sum bitfield members: 3 bits, bit holes: 1, sum bit holes: 5 b= its */ > /* last cacheline: 32 bytes */ > }; >=20 > It doesn't matter much because anyway the typical storage for struct > udp_flow is given by union flow: >=20 > union flow { > struct flow_common f; /* 0 76 */ > struct flow_free_cluster free; /* 0 84 */ > struct tcp_tap_conn tcp; /* 0 120 */ > struct tcp_splice_conn tcp_splice; /* 0 120 */ > struct icmp_ping_flow ping; /* 0 96 */ > struct udp_flow udp; /* 0 96 */ > }; >=20 > but it still improves data locality somewhat, so let me fix this up > now that commits are fresh. >=20 > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson > --- > udp_flow.h | 11 +++++++---- > 1 file changed, 7 insertions(+), 4 deletions(-) >=20 > diff --git a/udp_flow.h b/udp_flow.h > index 90d3b29..e289122 100644 > --- a/udp_flow.h > +++ b/udp_flow.h > @@ -10,22 +10,25 @@ > /** > * struct udp_flow - Descriptor for a flow of UDP packets > * @f: Generic flow information > + * @ttl: TTL or hop_limit for both sides > * @closed: Flow is already closed > * @flush0: @s[0] may have datagrams queued for other flows > * @flush1: @s[1] may have datagrams queued for other flows > * @ts: Activity timestamp > * @s: Socket fd (or -1) for each side of the flow > - * @ttl: TTL or hop_limit for both sides > */ > struct udp_flow { > /* Must be first element */ > struct flow_common f; > =20 > - bool closed :1; > - bool flush0, flush1 :1; > + uint8_t ttl[SIDES]; > + > + bool closed :1, > + flush0 :1, > + flush1 :1; > + > time_t ts; > int s[SIDES]; > - uint8_t ttl[SIDES]; > }; > =20 > struct udp_flow *udp_at_sidx(flow_sidx_t sidx); --=20 David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson --Bx7Ekn4Mr0bt6Y5S Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmf0xKUACgkQzQJF27ox 2GfkTA/7B7haCABHRa6SXHj7F/rZZ8VB1ULlsZ6wwfp7ZIQtWEQiF2nKmL2TswC/ jzGI90HyFwK1uTl0CmTpk5RrymD+u4gKlErFzK4OZGJYjO8oS548IDocr+7TZ5pK gJrEgWko1ol4wrEgjWZ3arKeDTWjmA2O9ZSERY0LA7k0qIvCL/Ljdgfcvnnqw1xZ QbWoHbMC7eRfoxp5niiJJtbBCsQOCAZMwlc86VHCzjcUXE4RpGuUASC3oQnlEHRi /DLcrc1CuZ3Lf0lrLifqcABmDVpUDljAoJOQHHNesSL2UjRvvjxmPST2SjP8/4yS rzEOVuWoxsgtTYvkdGIeGdoZQUUl3cK6DrAei6+420snELwVe2tNL5DzN1rssXkU CrobUgh2qjKuF+FnWkyHkV65WpYqxI5uk26cCxj9vxCzJmAtYGhDVaG6iI3hk3Jh A10WCBqMv0/qRT66LRaNnxHZAS5KripFy4J7KHD+aIhD79PS/jzqWDCaly8cOhkR 0mjQalY5FZLQ5xdq0B0gkxUaeSpFcWOeItLIpbvX9cY/wLhTUTjHvhykMwiRBinb 0HnNVHvfQBb0XqmB9+HWO+h79CTlQguB+Tv8sHDId/4WweJ2Wv9Wd4dz5GJLefe7 VwsmX2MXEjd2CKDPfcUCGBIZxdND6n8xUapJy/bvCFiLwzNpC2w= =x+sS -----END PGP SIGNATURE----- --Bx7Ekn4Mr0bt6Y5S--