Here is something interesting about memory management in Linux: most systems use 4KB pages by default. But, there is something called Transparent Huge Pages (THP) that configures your system to use 2MB pages instead. Here's why it matters...
Every time the CPU needs to translate a virtual address to a physical one, it looks up the page table. This lookup is expensive, so there is a small cache called the Translation Lookaside Buffer that stores recent translations (yes, the one we studied in operating systems).
The problem? TLB is tiny - it can only hold a few hundred entries. So if each page is just 4KB, the TLB can only cache translations for a small slice of memory (128KB to 512KB).
But if each page is 2MB, suddenly the same number of TLB entries can cover 64MB to 256MB, which is 500x more memory accesses cached. Fewer TLB misses mean faster memory access.
When this setting is changed, the applications need not do anything; it is a pure OS setting change.
But here is the catch - THP can hurt database performance. To create these 2MB contiguous pages, the kernel sometimes needs to "compact" memory by shuffling pages around. This can stall your application for hundreds of milliseconds, sometimes even seconds.
Databases like MongoDB, Redis, and MySQL have sparse, random memory access patterns. They do not benefit from huge pages, and the compaction overhead just adds unpredictable latency.
Not only that, but if your application only needs 100KB, a 2MB page still gets allocated. That is 1.9MB wasted. For applications with lots of small, sparse allocations, this adds up quickly.
Also, when the system needs to swap out a huge page, it first has to split it back into 4KB pages. This splitting operation takes time and adds latency during memory pressure.
Even when a process forks, pages are shared until one process writes to them. With huge pages, a single byte write triggers a 2MB copy instead of a 4KB copy.
This is why most databases recommend disabling THP entirely. If you want to check your THP status, you can just fire the command
```
cat /sys/kernel/mm/transparent_hugepage/enabled
```
When I benchmarked it, I saw tremendous results for Spark workloads and Redis with large KV data. But the penalty when data is sparse is actually much worse.
THP is a classic trade-off. So, know your memory access patterns before you decide to turn it on.
here you gooo
MintCraft is a decentralized marketplace where AI generates content (art, music, text, code) that's instantly minted as NFTs on Solana, with built-in ownership tracking and monetization. Users can also register their own AI models and earn from usage fees.
here you gooo
MintCraft is a decentralized marketplace where AI generates content (art, music, text, code) that's instantly minted as NFTs on Solana, with built-in ownership tracking and monetization. Users can also register their own AI models and earn from usage fees.
1K Followers 403 Following4x Grad @solanaturbine.
Rust | Aya eBPF🐝 | Fullstack Dev on @solana @Superteamng | Pod @the_anchor_fndr | fnd @gildore_arena | CTO @importapay_ng
26 Followers 356 FollowingSenior Software engineer with 8.5+ exp.
🛠️ I build scalable apps using Go
🎯 Clean architecture • Microservices
System design . Data structures and Algorithms.
38 Followers 77 FollowingSWE https://t.co/wWMjuS44L5 | Building @s7t_saas, prev @LookAroundPG, @Indiametdept | Software Developer | Know more about me in your terminal using ` npx adix `
5K Followers 282 Followingshoot my shot im still w the demons
ex mit, stanfordnlp, harvard | ex smallest ai, METR |
ex nationals badminton |
founder in residence @join_ef
11K Followers 110 FollowingCo-founder & CEO @Growthx_Club - Global community of AI builders • Prev built growth teams @Razorpay, @Merkle • Music, food & fitness is therapy