When should I use the TransparentHugePages setting "madvise" on RHEL?
Environment
- Red Hat Enterprise Linux (RHEL) 6 and later
- Transparent Huge Pages
Issue
- When should I use the TransparentHugePages setting
madviseon RHEL?
Resolution
The madvise() syscall
From man madvise:
The madvise() system call advises the kernel about how to handle paging input/output in
the address range beginning at address addr and with size length bytes. It allows an
application to tell the kernel how it expects to use some mapped or shared memory areas, so
that the kernel can choose appropriate read-ahead and caching techniques. This call
does not influence the semantics of the application (except in the case of MADV_DONTNEED),
but may influence its performance. The kernel is free to ignore the advice.
The "madvise TransparentHugePages" mode
From kernel-docs transhuge.txt: With normal TransparentHugePages activated on a system, the following can occur: an application may end up allocating more memory resources. An application may mmap a large region but only touch 1 byte of it, in that case a 2M page might be allocated instead of a 4k page for no good. This is why it's possible to disable hugepages system-wide and to only have them inside MADV_HUGEPAGE madvise regions: this is done in setting
echo madvise > /sys/kernel/mm/redhat_transparent_hugepage/enabled
When this is configured, TransparentHugePages are only used when applications explicitly use madvise(MADV_HUGEPAGE) to inform the kernel that they are reasonably sure to really use the memory they are allocating. In madvise-mode, for other applications, no TransparentHugePages are used.
When should I use the "madvise TransparentHugePages" mode?
The mode should be used when the application provider/vendor advises to use the "madvise TransparentHugePages" mode.
The kernelsources have more informations and documentations around this topic, i.e. /usr/share/doc/kernel-doc*/Documentation/vm/transhuge.txt.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
