From 421b1f0a4126f4bc4dace3a892c9e59d6c54e590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 14 May 2021 17:31:26 +0200 Subject: [PATCH] resolved: optimize layout of DnsPacket MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We obviously have lots of those, so even small savings add up. Bitfields are dropped because they don't give any memory savings due to alignment requirements (but would still require more complex to access). /* size: 184, cachelines: 3, members: 28 */ /* sum members: 172, holes: 1, sum holes: 4 */ /* sum bitfield members: 4 bits (0 bytes) */ /* padding: 7 */ /* bit_padding: 4 bits */ ↓ /* size: 176, cachelines: 3, members: 28 */ --- src/resolve/resolved-dns-packet.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/resolve/resolved-dns-packet.h b/src/resolve/resolved-dns-packet.h index e9820795c0..6e7175c754 100644 --- a/src/resolve/resolved-dns-packet.h +++ b/src/resolve/resolved-dns-packet.h @@ -71,21 +71,23 @@ struct DnsPacket { DnsAnswer *answer; DnsResourceRecord *opt; + /* For support of truncated packets */ + DnsPacket *more; + /* Packet reception metadata */ + usec_t timestamp; /* CLOCK_BOOTTIME (or CLOCK_MONOTONIC if the former doesn't exist) */ int ifindex; int family, ipproto; union in_addr_union sender, destination; uint16_t sender_port, destination_port; uint32_t ttl; - usec_t timestamp; /* CLOCK_BOOTTIME (or CLOCK_MONOTONIC if the former doesn't exist) */ - /* For support of truncated packets */ - DnsPacket *more; + bool on_stack; + bool extracted; + bool refuse_compression; + bool canonical_form; - bool on_stack:1; - bool extracted:1; - bool refuse_compression:1; - bool canonical_form:1; + /* Note: fields should be ordered to minimize alignment gaps. Use pahole! */ }; static inline uint8_t* DNS_PACKET_DATA(const DnsPacket *p) {