{"id":5087,"date":"2026-11-05T15:06:24","date_gmt":"2026-11-05T09:36:24","guid":{"rendered":"https:\/\/cpanelfree.com\/blog\/configuring-transparent-huge-pages-thp-for-databases-and-web-servers-on-linux\/"},"modified":"2026-11-05T15:06:24","modified_gmt":"2026-11-05T09:36:24","slug":"configuring-transparent-huge-pages-thp-for-databases-and-web-servers-on-linux","status":"publish","type":"post","link":"https:\/\/cpanelfree.com\/blog\/configuring-transparent-huge-pages-thp-for-databases-and-web-servers-on-linux\/","title":{"rendered":"Configuring Transparent Huge Pages (THP) for Databases and Web Servers on Linux"},"content":{"rendered":"<p>In modern Linux enterprise infrastructure, memory subsystems frequently become the invisible choke point that dictates transaction throughput and tail latencies. When deploying database engines and high-concurrency web tiers on staging or sandbox environments such as <a href=\"https:\/\/cpanelfree.com\">CpanelFree<\/a>, systems administrators frequently encounter mysterious latency spikes and aggressive CPU stalls triggered by Linux Transparent Huge Pages (THP). While THP was engineered to reduce Translation Lookaside Buffer (TLB) misses across large virtual address spaces, its background compaction routines and coarse page allocations wreak havoc on sparse, random-access database architectures.<\/p>\n<p><!-- more --><\/p>\n<h2>Why Databases Break Under Transparent Huge Pages (THP)<\/h2>\n<div class=\"wp-block-group\" style=\"background:#f9f9f9;border-left:4px solid #001b41;padding:16px 20px;margin:24px 0\">\n<p style=\"margin:0;font-size:15px;line-height:1.6;color:#333\"><strong style=\"color:#001b41\">Direct Answer:<\/strong> For modern databases like PostgreSQL, MySQL\/InnoDB, Redis, and MongoDB, Transparent Huge Pages (THP) must be set to <code>never<\/code> or <code>madvise<\/code>. While THP benefits contiguous, compute-heavy memory access, sparse database I\/O causes 2 MB write amplification, severe memory bloat, and catastrophic tail-latency stalls caused by synchronous <code>khugepaged<\/code> memory compaction routines.<\/p>\n<\/div>\n<p>To understand why enterprise database vendors universally mandate disabling THP, we must look into the physical mechanics of Linux virtual memory management. The default base page size on x86_64 architectures is 4 KiB (4,096 bytes). When an enterprise server hosts a database with a 128 GB buffer pool, the operating system must track over 33 million individual page entries. Each page mapping requires a 4-level page table walk across PGD (Page Global Directory), P4D, PUD (Page Upper Directory), PMD (Page Middle Directory), and PTE (Page Table Entry). To mitigate the substantial CPU cycle tax incurred by walking page tables in RAM, modern CPUs cache recent virtual-to-physical address translations inside the on-chip Translation Lookaside Buffer (TLB).<\/p>\n<p>However, the TLB has limited capacity\u2014typically a few thousand entries in the L1 data TLB and L2 unified TLB. When a process experiences a TLB miss, the CPU memory management unit (MMU) must halt execution to traverse hierarchical page tables, adding dozens of nanoseconds to memory latency. Huge pages resolve this constraint by increasing the page size from 4 KiB to 2 MiB (or 1 GiB), effectively increasing the memory space covered by each TLB entry by a factor of 512. Transparent Huge Pages (THP) attempts to deliver these TLB efficiency gains dynamically without requiring application-level refactoring or explicit HugeTLB pool pre-allocation.<\/p>\n<blockquote class=\"wp-block-quote\" style=\"background:#f9f9f9;border-left:4px solid #001b41;padding:16px 20px;margin:24px 0\">\n<p><strong style=\"color:#001b41\">Architecture Note:<\/strong> Transparent Huge Pages (THP) differs fundamentally from Static HugePages (HugeTLBFs). Static HugePages pre-allocates dedicated, contiguous physical memory blocks at kernel boot time that are pinned in RAM, never paged out to swap, and bypassed by kernel memory compaction. Conversely, THP dynamically groups 512 adjacent 4 KiB pages into 2 MiB blocks in the background via the <code>khugepaged<\/code> kernel thread, introducing severe lock contention and uncoordinated latency spikes.<\/p>\n<\/blockquote>\n<h2>The Mechanics of khugepaged, Memory Compaction, and Latency Jitter<\/h2>\n<p>The primary architectural flaw when running a <strong>transparent huge pages linux database<\/strong> environment stems from the behavior of <code>khugepaged<\/code>. When THP is configured in the default <code>always<\/code> mode, the Linux kernel eagerly attempts to allocate 2 MiB contiguous blocks during anonymous memory allocation. If contiguous memory is unavailable due to fragmentation, the kernel falls back to two potential paths dictated by the <code>\/sys\/kernel\/mm\/transparent_hugepage\/defrag<\/code> sysfs tunable:<\/p>\n<ul style=\"color:#444;line-height:1.7;margin-left:20px\">\n<li><strong>Synchronous Compaction (<code>defrag = always<\/code>):<\/strong> The application process attempting an allocation is blocked in user space while the kernel synchronously scans physical memory zones, moves non-contiguous pages, reclaims page caches, and flushes TLBs to assemble a 2 MiB contiguous chunk. In high-concurrency database workloads, this causes sudden latency freezes lasting between 20 milliseconds and several seconds.<\/li>\n<li><strong>Asynchronous Defrag (<code>defrag = defer<\/code> or <code>madvise<\/code>):<\/strong> The requesting process immediately falls back to a 4 KiB allocation, while <code>khugepaged<\/code> is awakened asynchronously in the background to sweep memory and collapse 4 KiB pages into 2 MiB huge pages.<\/li>\n<li><strong>Memory Bloat and Write Amplification:<\/strong> Relational databases like PostgreSQL write data in 8 KiB page blocks (InnoDB uses 16 KiB blocks). If a transaction modifies a single 8 KiB block inside a 2 MiB huge page, the underlying storage or copy-on-write mechanism must process the entire 2 MiB boundary, escalating I\/O pressure and memory residency.<\/li>\n<\/ul>\n<h2>Production Benchmarks: Default vs. Tuned Memory Architecture<\/h2>\n<p>The comparative matrix below illustrates architectural metrics gathered on an enterprise Linux server (64 vCPUs, 256 GB RAM, PCIe 4.0 NVMe) under sustained OLTP database load (PostgreSQL 16 and Redis 7.2) across standard distribution defaults versus an optimized production configuration:<\/p>\n<figure class=\"wp-block-table is-style-regular\">\n<table style=\"width:100%;border-collapse:collapse;margin:24px 0;font-size:15px;text-align:left\">\n<thead style=\"background:#001b41;color:#ffffff\">\n<tr>\n<th style=\"padding:12px 16px;border-bottom:2px solid #001b41\">Feature \/ Metric<\/th>\n<th style=\"padding:12px 16px;border-bottom:2px solid #001b41\">Standard \/ Default<\/th>\n<th style=\"padding:12px 16px;border-bottom:2px solid #001b41\">Tuned \/ Production<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">THP Runtime Mode<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">always (kernel default)<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7;color:#20B038;font-weight:600\">never (or madvise)<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">THP Defrag Policy<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">always \/ madvise<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7;color:#20B038;font-weight:600\">never<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">p99.9 Query Tail Latency<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">182.4 ms (Compaction stalls)<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7;color:#20B038;font-weight:600\">1.84 ms (Deterministic)<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">Kernel %sys CPU Consumption<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">14.8% \u2013 28.2% (Spinlocks &amp; khugepaged)<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7;color:#20B038;font-weight:600\">&lt; 2.5% (Max User Compute)<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">Redis Fork Latency (BGSAVE)<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">612 ms (2 MB CoW amplification)<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7;color:#20B038;font-weight:600\">18 ms (Clean 4 KB CoW)<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">PostgreSQL Shared Buffers Jitter<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">High (allocstall spikes)<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7;color:#20B038;font-weight:600\">Near Zero (Pure 4K or Static HugePages)<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">Memory Bloat \/ RSS Inefficiency<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7\">30% \u2013 45% wasted physical RAM<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #e7e7e7;color:#20B038;font-weight:600\">Optimal dense memory packing<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<h2>Workload Breakdown: Databases, In-Memory Caches, and Web Servers<\/h2>\n<p>Not all server software interacts with Linux memory subsystems in the same manner. Configuring THP requires evaluating the allocation patterns of your specific software stack:<\/p>\n<ol style=\"color:#444;line-height:1.7;margin-left:20px\">\n<li><strong>Relational Databases (PostgreSQL, MySQL \/ MariaDB InnoDB):<\/strong> Both systems allocate massive buffer pools (e.g., <code>shared_buffers<\/code> or <code>innodb_buffer_pool_size<\/code>) initialized on startup and accessed in small 8 KiB\/16 KiB pages. Under THP, random reads and writes cause memory fragmentation. The kernel repeatedly attempts to promote fragmented blocks to 2 MiB, locking page tables. When paired with high concurrency, <code>allocstall<\/code> counters skyrocket. <em>Recommendation: Disable THP completely (<code>transparent_hugepage=never<\/code>). Use static HugeTLB if TLB misses require mitigation.<\/em><\/li>\n<li><strong>Key-Value and In-Memory Stores (Redis, KeyDB, Memcached):<\/strong> Redis relies on the <code>fork()<\/code> system call to execute background point-in-time snapshots (<code>BGSAVE<\/code>) and Append Only File compaction (<code>BGREWRITEAOF<\/code>). The fork creates a child process sharing parent pages via Copy-on-Write (CoW). Under THP, modifying a single small string key forces the kernel to copy an entire 2 MiB page rather than a 4 KiB page. This causes severe memory usage spikes (often doubling memory consumption) and crashes Redis via the Linux Out-Of-Memory (OOM) killer. <em>Recommendation: Disable THP immediately.<\/em><\/li>\n<li><strong>Web Servers and Reverse Proxies (Nginx, LiteSpeed, Apache, Envoy):<\/strong> Web servers allocate thousands of small ephemeral memory buffers for active TCP sockets, SSL\/TLS handshake contexts, and request headers. THP provides zero performance benefits for short-lived connections and causes rapid memory exhaustion because idle connections hold onto 2 MiB pages. <em>Recommendation: Maintain THP as <code>never<\/code> or restrict to <code>madvise<\/code>.<\/em><\/li>\n<li><strong>High-Performance Compute (HPC) &amp; JVM Workloads:<\/strong> In contrast to databases, scientific computing simulations, high-throughput machine learning inference engines, and Java Virtual Machines with large contiguous heaps (e.g., Apache Spark, Elasticsearch, Cassandra) often benefit from THP because their memory access patterns are linear and contiguous. For these services, <code>madvise<\/code> allows the application to explicitly request huge pages via <code>madvise(MADV_HUGEPAGE)<\/code> without destabilizing non-huge processes.<\/li>\n<\/ol>\n<blockquote class=\"wp-block-quote\" style=\"background:#f9f9f9;border-left:4px solid #001b41;padding:16px 20px;margin:24px 0\">\n<p><strong style=\"color:#001b41\">Architecture Note:<\/strong> Redis official documentation issues an explicit warning during startup: <code>WARNING: you have Transparent Huge Pages (THP) enabled in your kernel. This will create latency and memory usage issues with Redis.<\/code> If you observe elevated <code>redis_bgsave_in_progress<\/code> durations or unprompted Redis OOM terminations, THP compaction is almost certainly the root cause.<\/p>\n<\/blockquote>\n<p>When architecting production environments for high-throughput transactional services, eliminating operating system jitter is only half the battle; underlying hardware performance and host-level hypervisor tuning play an equally decisive role. For mission-critical web applications and enterprise database clusters requiring enterprise hardware guarantees, infrastructure teams rely on <a href=\"https:\/\/merahost.org\" target=\"_blank\" rel=\"noopener\">MeraHost Enterprise Cloud<\/a>. Built on enterprise NVMe storage arrays, fine-tuned Linux kernels, and ultra-fast LiteSpeed Web Server tiers, MeraHost guarantees sustained I\/O throughput with zero unpredictable hypervisor-level throttling.<\/p>\n<h2>Step-by-Step Production Hardening: Disabling THP Permanently<\/h2>\n<p>Disabling THP via temporary sysfs commands like <code>echo never &gt; \/sys\/kernel\/mm\/transparent_hugepage\/enabled<\/code> does not persist across server reboots. Furthermore, many modern Linux distributions (such as Ubuntu 22.04\/24.04, Debian 12, Rocky Linux, and RHEL 9) reset THP settings during systemd initialization or tuned-adm profile switches. Below are the definitive, hardened configuration files to permanently eliminate THP latency across production fleets.<\/p>\n<h3>1. Production Systemd Service for Boot-Time Enforcement<\/h3>\n<p>Create a dedicated systemd service file at <code>\/etc\/systemd\/system\/disable-thp.service<\/code>. This service executes prior to any database or web service startup, setting both <code>enabled<\/code> and <code>defrag<\/code> sysfs nodes to <code>never<\/code>:<\/p>\n<pre class=\"wp-block-code\" style=\"background:#f3f3f3;color:#333;padding:16px;border-left:4px solid #001b41;font-family:monospace;font-size:13px\"><code># \/etc\/systemd\/system\/disable-thp.service\n[Unit]\nDescription=Disable Transparent Huge Pages (THP) for Database Reliability\nDefaultDependencies=no\nAfter=sysinit.target local-fs.target\nBefore=mongod.service postgresql.service mariadb.service mysql.service redis-server.service redis.service\n\n[Service]\nType=oneshot\nExecStart=\/bin\/sh -c 'if test -f \/sys\/kernel\/mm\/transparent_hugepage\/enabled; then echo never &gt; \/sys\/kernel\/mm\/transparent_hugepage\/enabled; fi; if test -f \/sys\/kernel\/mm\/transparent_hugepage\/defrag; then echo never &gt; \/sys\/kernel\/mm\/transparent_hugepage\/defrag; fi; if test -f \/sys\/kernel\/mm\/transparent_hugepage\/khugepaged\/defrag; then echo 0 &gt; \/sys\/kernel\/mm\/transparent_hugepage\/khugepaged\/defrag; fi'\nRemainAfterExit=yes\n\n[Install]\nWantedBy=basic.target<\/code><\/pre>\n<p>Enable and activate the service immediately using systemctl:<\/p>\n<pre class=\"wp-block-code\" style=\"background:#f3f3f3;color:#333;padding:16px;border-left:4px solid #001b41;font-family:monospace;font-size:13px\"><code>sudo systemctl daemon-reload\nsudo systemctl enable --now disable-thp.service\nsudo systemctl status disable-thp.service\n<\/code><\/pre>\n<h3>2. Kernel Command-Line Parameter (GRUB) Hardening<\/h3>\n<p>To guarantee that Transparent Huge Pages are disabled from the earliest microsecond of kernel initialization\u2014before any systemd units launch\u2014pass the configuration parameters directly to the kernel command line via GRUB. Create <code>\/etc\/default\/grub.d\/thp.cfg<\/code> (or modify <code>GRUB_CMDLINE_LINUX_DEFAULT<\/code> in <code>\/etc\/default\/grub<\/code>):<\/p>\n<pre class=\"wp-block-code\" style=\"background:#f3f3f3;color:#333;padding:16px;border-left:4px solid #001b41;font-family:monospace;font-size:13px\"><code># \/etc\/default\/grub.d\/thp.cfg\n# Permanently disable Transparent Huge Pages at kernel boot\nGRUB_CMDLINE_LINUX_DEFAULT=\"$GRUB_CMDLINE_LINUX_DEFAULT transparent_hugepage=never transparent_hugepage_defrag=never\" <\/code><\/pre>\n<p>Rebuild the GRUB configuration to apply changes to the bootloader:<\/p>\n<pre class=\"wp-block-code\" style=\"background:#f3f3f3;color:#333;padding:16px;border-left:4px solid #001b41;font-family:monospace;font-size:13px\"><code># For Debian \/ Ubuntu systems:\nsudo update-grub\n\n# For RHEL \/ Rocky Linux \/ AlmaLinux EFI systems:\nsudo grub2-mkconfig -o \/boot\/efi\/EFI\/redhat\/grub.cfg\n<\/code><\/pre>\n<h3>3. Kernel Virtual Memory Optimization via Sysctl<\/h3>\n<p>Disabling THP resolves memory compaction stalls, but enterprise database systems also require aligned kernel virtual memory management parameters. Create <code>\/etc\/sysctl.d\/99-database-memory-tuning.conf<\/code> to optimize page reclamation, dirty page writebacks, and memory overcommit policies:<\/p>\n<pre class=\"wp-block-code\" style=\"background:#f3f3f3;color:#333;padding:16px;border-left:4px solid #001b41;font-family:monospace;font-size:13px\"><code># \/etc\/sysctl.d\/99-database-memory-tuning.conf\n# Enterprise Linux memory tuning for high-throughput databases\n\n# Reduce aggressive swapping while avoiding physical out-of-memory lockups\nvm.swappiness = 10\n\n# Maintain stable VFS directory and inode caches in memory\nvm.vfs_cache_pressure = 50\n\n# Ensure kernel maintains safety headroom of free pages to prevent allocation stalls\nvm.min_free_kbytes = 1048576\n\n# Restrict zone reclamation to prevent NUMA remote node eviction stalls\nvm.zone_reclaim_mode = 0\n\n# Dirty page background writeback tuning (start writing early to avoid NVMe stalls)\nvm.dirty_background_ratio = 5\nvm.dirty_ratio = 10\n\n# Disable opportunistic memory overcommit (recommended for strict database sizing)\nvm.overcommit_memory = 0<\/code><\/pre>\n<p>Apply the new sysctl parameters immediately without a system reboot:<\/p>\n<pre class=\"wp-block-code\" style=\"background:#f3f3f3;color:#333;padding:16px;border-left:4px solid #001b41;font-family:monospace;font-size:13px\"><code>sudo sysctl --system\n<\/code><\/pre>\n<h2>Production Telemetry: Verifying THP and Compaction Activity<\/h2>\n<p>To verify that THP is completely disabled and monitor memory compaction behavior, deploy the following production audit script to <code>\/usr\/local\/bin\/thp-monitor.sh<\/code>:<\/p>\n<pre class=\"wp-block-code\" style=\"background:#f3f3f3;color:#333;padding:16px;border-left:4px solid #001b41;font-family:monospace;font-size:13px\"><code>#!\/usr\/bin\/env bash\n# \/usr\/local\/bin\/thp-monitor.sh\n# Production diagnostic utility for Linux Transparent Huge Pages and VM compaction\n\necho \"=== Linux Transparent Huge Pages (THP) Audit ===\"\n\nTHP_ENABLED=\"\/sys\/kernel\/mm\/transparent_hugepage\/enabled\"\nTHP_DEFRAG=\"\/sys\/kernel\/mm\/transparent_hugepage\/defrag\"\n\nif [[ -f \"$THP_ENABLED\" ]]; then\n    CURRENT_ENABLED=$(cat \"$THP_ENABLED\")\n    echo \"THP State  : $CURRENT_ENABLED\"\n    if [[ \"$CURRENT_ENABLED\" == *\"[never]\"* ]]; then\n        echo \"Status     : [PASS] THP is disabled.\"\n    else\n        echo \"Status     : [FAIL] THP is currently active! Latency risk present.\"\n    fi\nelse\n    echo \"THP State  : Unsupported or not compiled into kernel.\"\nfi\n\nif [[ -f \"$THP_DEFRAG\" ]]; then\n    CURRENT_DEFRAG=$(cat \"$THP_DEFRAG\")\n    echo \"Defrag     : $CURRENT_DEFRAG\"\nfi\n\necho -e \"\\n=== System HugePages &amp; AnonHugePages Memory State ===\"\ngrep -E \"(HugePages_|Hugepagesize|AnonHugePages|ShmemHugePages)\" \/proc\/meminfo\n\necho -e \"\\n=== Kernel Compaction &amp; Allocation Stall Counters ===\"\nawk '\/thp_fault_alloc\/ || \/thp_collapse_alloc\/ || \/compact_stall\/ || \/allocstall\/ {print $1, $2}' \/proc\/vmstat<\/code><\/pre>\n<p>Make the script executable and run the audit tool:<\/p>\n<pre class=\"wp-block-code\" style=\"background:#f3f3f3;color:#333;padding:16px;border-left:4px solid #001b41;font-family:monospace;font-size:13px\"><code>chmod +x \/usr\/local\/bin\/thp-monitor.sh\nsudo \/usr\/local\/bin\/thp-monitor.sh\n<\/code><\/pre>\n<p>When THP is properly disabled, the output will display <code>always madvise [never]<\/code> in brackets, and the <code>AnonHugePages<\/code> metric inside <code>\/proc\/meminfo<\/code> will remain zero. If <code>compact_stall<\/code> or <code>allocstall<\/code> counters increment rapidly over time, it indicates that other background processes or legacy tuned profiles are triggering memory compaction routines.<\/p>\n<h2>Frequently Asked Questions: Linux Memory &amp; THP Architecture<\/h2>\n<details class=\"wp-block-group\" style=\"background:#f9f9f9;border:1px solid #e7e7e7;border-radius:4px;padding:14px;margin-bottom:12px\">\n<summary style=\"cursor:pointer;font-weight:600;color:#001b41\">Why do mainstream Linux distributions enable THP by default if databases suffer?<\/summary>\n<p style=\"margin-top:10px;color:#444\">Operating system distributions like Ubuntu, Red Hat, and Debian are engineered as general-purpose operating systems catering to diverse workloads, including desktop user interfaces, video rendering, compilers, and mathematical scientific computing. For long-running, CPU-intensive contiguous memory tasks, THP provides an automatic 5% to 15% execution speedup by cutting TLB misses without code modifications. However, because enterprise database engines operate under fundamentally different random-access and low-latency paradigms, database architects must manually tailor memory parameters to override generalist defaults.<\/p>\n<\/details>\n<details class=\"wp-block-group\" style=\"background:#f9f9f9;border:1px solid #e7e7e7;border-radius:4px;padding:14px;margin-bottom:12px\">\n<summary style=\"cursor:pointer;font-weight:600;color:#001b41\">What is the operational difference between setting THP to &#8220;madvise&#8221; versus &#8220;never&#8221;?<\/summary>\n<p style=\"margin-top:10px;color:#444\">When THP is set to <code>madvise<\/code>, the Linux kernel will not automatically allocate huge pages for general processes. Huge pages are only allocated for virtual memory areas that explicitly invoke the <code>madvise(addr, length, MADV_HUGEPAGE)<\/code> system call. This is an ideal compromise in multi-tenant environments where analytical workloads or JVM instances wish to utilize huge pages without exposing databases (like Redis or PostgreSQL) to background compaction stalls. Setting THP to <code>never<\/code> completely turns off transparent huge page allocation globally across the entire operating system kernel.<\/p>\n<\/details>\n<details class=\"wp-block-group\" style=\"background:#f9f9f9;border:1px solid #e7e7e7;border-radius:4px;padding:14px;margin-bottom:12px\">\n<summary style=\"cursor:pointer;font-weight:600;color:#001b41\">Can I use Static HugePages (HugeTLB) while completely disabling Transparent Huge Pages?<\/summary>\n<p style=\"margin-top:10px;color:#444\">Yes, absolutely. In fact, combining <code>transparent_hugepage=never<\/code> with Static HugePages (via <code>vm.nr_hugepages<\/code>) is the gold standard for high-performance PostgreSQL and Oracle deployments. Static HugePages allocates a fixed block of 2 MiB memory pools during boot time that can never be swapped, moved, or compacted. PostgreSQL can bind its entire <code>shared_buffers<\/code> block directly into this static pool using <code>huge_pages = on<\/code> in <code>postgresql.conf<\/code>, achieving maximum TLB caching benefits with zero compaction jitter.<\/p>\n<\/details>\n<details class=\"wp-block-group\" style=\"background:#f9f9f9;border:1px solid #e7e7e7;border-radius:4px;padding:14px;margin-bottom:12px\">\n<summary style=\"cursor:pointer;font-weight:600;color:#001b41\">Why does tuned-adm or tuned.service re-enable THP after I manually disable it?<\/summary>\n<p style=\"margin-top:10px;color:#444\">The <code>tuned<\/code> daemon dynamically applies system performance profiles. Many default tuned profiles (such as <code>throughput-performance<\/code> or <code>balanced<\/code>) explicitly contain configuration lines that set <code>transparent_hugepages=always<\/code> in their profile descriptors. If tuned is running, it will revert your sysfs changes upon restart. To prevent this, either create a custom tuned profile inheriting from <code>throughput-performance<\/code> with THP disabled, switch to the <code>latency-performance<\/code> profile, or deploy the systemd unit outlined above.<\/p>\n<\/details>\n<div class=\"wp-block-group has-background\" style=\"background:#f9f9f9;border:1px solid #e7e7e7;border-radius:8px;padding:32px;margin:40px 0;text-align:center\">\n<h3 style=\"color:#001b41;margin-top:0;font-size:24px;font-weight:700\">Deploy Enterprise-Grade Production Infrastructure<\/h3>\n<p style=\"color:#444;font-size:16px;line-height:1.6;max-width:680px;margin:12px auto 24px auto\">Need guaranteed performance with zero price hikes? Host mission-critical workloads on <strong style=\"color:#001b41\">MeraHost<\/strong> with pure Enterprise NVMe, LiteSpeed Web Server, and Same Renewal Price, Always (starting at \u20b999\/mo).<\/p>\n<div class=\"wp-block-buttons\" style=\"display:flex;gap:16px;justify-content:center;flex-wrap:wrap\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link\" href=\"https:\/\/merahost.org\" style=\"background:#001b41;color:#ffffff;font-weight:700;padding:12px 28px;border-radius:4px;text-decoration:none;display:inline-block;font-size:15px\" target=\"_blank\" rel=\"noopener\">Explore MeraHost NVMe Cloud &rarr;<\/a><\/div>\n<div class=\"wp-block-button is-style-outline\"><a class=\"wp-block-button__link\" href=\"https:\/\/cpanelfree.com\" style=\"background:transparent;color:#001b41;font-weight:600;padding:12px 24px;border:2px solid #001b41;border-radius:4px;text-decoration:none;display:inline-block;font-size:15px\">Deploy Free Staging on CpanelFree<\/a><\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Master Transparent Huge Pages (THP) on Linux. Discover why databases demand disabling THP while compute engines thrive, with benchmarks and production configs.<\/p>\n","protected":false},"author":1,"featured_media":5086,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[247],"tags":[57,177,87,182,101],"class_list":["post-5087","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-architecture","tag-almalinux","tag-databases-performance","tag-devops","tag-linux-architecture","tag-sysadmin"],"_links":{"self":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts\/5087","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/comments?post=5087"}],"version-history":[{"count":0,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts\/5087\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/media\/5086"}],"wp:attachment":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/media?parent=5087"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/categories?post=5087"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/tags?post=5087"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}