While trying to understand and optimize a nuance in Redis/Valkey,

Arpit Bhayani

Arpit Bhayani

Jun 24, 2025 • 2 min read


While trying to understand and optimize a nuance in Redis/Valkey, I stumbled upon something super interesting - Transparent Hugepages. I had no idea what they were, but here’s a summary of what I have learned so far.

Transparent Hugepages (THP) is a Linux kernel feature that promotes standard 4KB memory pages to larger 2MB pages. The core idea is to improve performance by reducing the overhead of memory management. But how exactly does it help?

It minimizes Translation Lookaside Buffer (TLB) misses. Let me explain, and yes, these are the same things we studied in our OS course.

The TLB is a small, fast cache in your CPU that plays a critical role in virtual memory translation, which means converting virtual memory addresses to physical ones.

Without a TLB, the CPU would need to walk the page tables every time it accesses memory for every load or store instruction involving a virtual address.

The TLB acts as a shortcut. If the requested address is cached in the TLB, the CPU skips all page table steps and goes straight from virtual to physical address in a single cycle.

So what does this have to do with THP?

If we increase the page size to 2MB, the number of memory pages decreases. This means there are fewer, larger pages to track. As a result, both the kernel and CPU spend less time on address translation because most requests will result in a TLB hit. This gives a significant performance boost to memory-heavy applications.

THP is one of the key optimizations you can use when dealing with large memory footprints, such as in databases, big data systems, and JVM-based applications :)

But the grass isn’t always greener, and there are trade-offs. Enabling THP can cause latency spikes if memory compaction is triggered when a 2MB block is not available. It can also lead to internal fragmentation within a page if many allocations and deallocations happen within a page.

By the way, to enable it, you just need to run a couple of simple shell commands. And as always, you’re one Gemini lookup away from the details.

Hope this helps!

Arpit Bhayani

Principal Engineer II at Razorpay - building Agent Studio, Ex-staff engg at GCP Memorystore & Dataproc, Creator of DiceDB, ex-Amazon Fast Data, ex-Director of Engg. SRE and Data Engineering at Unacademy. I spark engineering curiosity through my no-fluff engineering videos on YouTube and my courses