How Cloudflare saved 100 TB of memory in the 1.1.1.1 DNS cache
Cloudflare's Big Pineapple platform, which runs 1.1.1.1 and several other DNS services, stores over 250 billion DNS cache entries at any given time. Each entry holds a DNS response plus metadata such as the Time-to-Live (TTL)[1]. Five successive changes to how entries are stored in memory cut the memory per entry by over 50%, freeing roughly 100 terabytes across the fleet, equal to the RAM in 130 of Cloudflare's Gen 13 servers. The cache also got faster: insert throughput rose 43% and lookup latency dropped 19%.
One change replaced Vec fields with Box<[T]> and Box<str>. Because cached responses are never modified, the capacity field and the unused space reserved on the heap[2] were unnecessary, and this change alone saves over 15 terabytes. Another change stores the answer, authority and additional sections in a single list with 2-byte offsets instead of separate lists. The owner name is no longer stored when it matches the queried domain, but it is kept when a CNAME[3] makes it differ.
The team measured memory with a benchmark that fills the cache with random entries matching production traffic: 56% A records, 25% AAAA and 19% TXT. Memory was tracked with a custom allocator[4] that wraps Rust's System allocator. Because the benchmark only approximates production, the team also measured resident memory across production instances during the rollout.
Read the original blog.cloudflare.comDiscussion
Sources
-
Cloudflare Blog
How we saved 100 terabytes of memory by optimizing 1.1.1.1’s DNS cache



