大网数据广告活动
服务器运维问答

Configuring Transparent Hugepages; [always], [madvise], or [never]

· 52CE 我爱测

We have a bunch of general purpose Centos 7 LAMP stack servers that run apache with underlying MariaDB databases. From the RedHat Performance Tuning docs for RHEL 6 : Trasparent Hugepages (THP) hides much of the complexity in usi…

问题原文

原帖链接 · Arth · CC BY-SA 3.0

We have a bunch of general purpose Centos 7 LAMP stack servers that run apache with underlying MariaDB databases.

From the RedHat Performance Tuning docs for RHEL 6:

Trasparent Hugepages (THP) hides much of the complexity in using huge pages from system administrators and developers. As the goal of THP is improving performance, its developers (both from the community and Red Hat) have tested and optimized THP across a wide range of systems, configurations, applications, and workloads. This allows the default settings of THP to improve the performance of most system configurations. However, THP is not recommended for database workloads.

Which sounds great, up until the database section. In fact, some of the MariaDB options such as the TokuDB engine actually require THP to be disabled.

A lot of the guides I found for disabling THP instruct changing the default configuration from transparent_hugepages= always to never.

However, from the RedHat Performance Tuning docs for RHEL 7:

To prevent applications from allocating more memory resources than necessary, you can disable huge pages system-wide and only enable them inside MADV_HUGEPAGE madvise regions

If I have read this right, transparent_hugepages= madvise seems like a much better option, allowing processes that benefit from THP to use them and those that don't to not.

I did find one article suggesting this approach.

Why is this not the default option?

Are there any situations where using transparent_hugepages= never is wiser than madvise?

已采纳解答

原帖链接 · Andrew Domaszek · CC BY-SA 4.0

It's the difference between opt-in (madvise) and opt-out (always). Applications that are sensitive to THP can opt-out even under transparent_hugepages=always. For example, jemalloc-using applications are notably sensitive to it (redis, go rt, rust rt) and jemalloc offers the option at compile time as part of the allocator configuration to use MADV_NOHUGEPAGE. Starting with kernel 3.15 (RHEL7 ships with 3.10), they can opt out on a per-process basis using prctl(PR_SET_THP_DISABLE).

The default always should usually be fine because data locality is a very common property for applications making large allocations. Databases are the notable exception where they suffer for accessing small chunks across a high number of large allocations (and they can disable THP).

The kernel documentation for transparent hugepages suggests that transparent_hugepage=never is more of a debugging option than a recommended solution. It is only preferable to transparent_hugepage=madvise when the software is buggy; ie. when the developer is using MADV_HUGEPAGE incorrectly.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-02-07)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。