RC RANDOM CHAOS

Cloudflare Cuts 100TB of RAM From 1.1.1.1's DNS Cache — and Made It Faster

· via Hacker News

Original source

Saving 100 terabytes of memory by optimizing 1.1.1.1's DNS cache

Hacker News →

Cloudflare’s DNS platform, internally called Big Pineapple, holds more than 250 billion cache entries at any moment across services like 1.1.1.1, Gateway DNS, and DNS Firewall. At that scale, every wasted byte per entry costs over 250GB fleet-wide, so the team reworked how each cache entry is laid out in memory. Five successive changes to the Rust data structures cut the per-entry footprint by more than half, freeing roughly 100 terabytes of RAM — equivalent to 130 of Cloudflare’s Gen 13 servers.

The wins came from squeezing structural overhead out of the entry types rather than dropping data. Swapping growable Vec and String fields for fixed Box<[T]> and Box dropped the unused capacity field and over-reserved heap space, saving 64 bytes per entry and 15+ TB alone. Collapsing the separate answer, authority, and additional record lists into a single buffer with 2-byte u16 section offsets removed redundant pointers and lengths, while packing booleans into bitflags trimmed struct padding. The team also stopped storing each record’s owner name when it matches the queried domain — the common case — reconstructing it from the cache key at read time and avoiding a heap allocation entirely. A final pass addressed Rust enum sizing, where a record-data enum is forced to the size of its largest variant (NAPTR, at 136 bytes).

Notably, the leaner layout also ran faster: insert throughput rose 43% and lookup latency fell 19%, because fewer allocations and tighter memory locality meant space and speed improved together rather than trading off. The work is a practical case study in low-level Rust memory optimization at hyperscale, where structural details like capacity fields, padding, and enum tags translate directly into hardware saved.

Read the full article

Continue reading at Hacker News →

This is an AI-generated summary. Read the original for the full story.