]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: optimize layout of DnsPacket
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 14 May 2021 15:31:26 +0000 (17:31 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 14 May 2021 15:34:38 +0000 (17:34 +0200)
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

index e9820795c0593a8385137a5f64cdacfaec69cf18..6e7175c754769d0d327bac4964d5f9831817a09d 100644 (file)
@@ -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) {