• Home
  • Disclaimer
  • Contact
  • Archives
  • About
  • Subscribe
  • Support
  • Advertise

Kernel Talks

Unix, Linux, & Cloud!

  • How-to guides
    • Howto
    • Disk management
    • Configurations
    • Troubleshooting
  • OS
    • HPUX
    • Linux
  • Miscellaneous
    • Software & Tools
    • Cloud Services
    • System services
    • Virtualization
  • Certification Preparations
    • AWS Certified Solutions Architect – Associate
    • AWS Certified Solutions Architect – Professional
    • AWS Certified SysOps Administrator – Associate
    • AWS Certified Cloud Practitioner
    • Certified Kubernetes Administrator
    • Hashicorp Certified Terraform Associate
    • Oracle Cloud Infrastructure Foundations 2020 – Associate
  • Tips & Tricks
  • Linux commands
You are here: Home / System services

What are the huge pages in Linux?

Published: November 2, 2017 | Modified: June 25, 2020



Learn about huge pages in Linux. Understand what is huge pages, how to configure it, how to check the current state, and how to disable it.

HugePages in Linux

In this article, we will walk you through details about huge pages so that you will be able to answer: what are huge pages in Linux? How to enable/disable huge pages? How to determine huge page value? in Linux like RHEL6, RHEL7, Ubuntu, etc.

Lets start with Huge pages basics.

What is Huge page in Linux?

Huge pages are helpful in virtual memory management in the Linux system. As the name suggests, they help is managing huge size pages in memory in addition to standard 4KB page size. You can define as huge as 1GB page size using huge pages.

During system boot, you reserve your memory portion with huge pages for your application. This memory portion i.e. these memory occupied by huge pages is never swapped out of memory. It will stick there until you change your configuration. This increases application performance to a great extent like Oracle database with pretty large memory requirements.

Why use huge page?

In virtual memory management, the kernel maintains a table in which it has a mapping of the virtual memory address to a physical address. For every page transaction, the kernel needs to load related mapping. If you have small size pages then you need to load more numbers of pages resulting kernel to load more mapping tables. This decreases performance.

Using huge pages means you will need fewer pages. This decreases the number of mapping tables to load by the kernel to a great extent. This increases your kernel-level performance which ultimately benefits your application.

In short, by enabling huge pages, the system has fewer page tables to deal with and hence less overhead to access/maintain them!

How to configure huge pages?

Run below command to check current huge pages details.

root@kerneltalks # grep Huge /proc/meminfo
AnonHugePages:         0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB

In the above output, you can see the one-page size is 2MB Hugepagesize and a total of 0 pages on the system HugePages_Total. This huge page size can be increased from 2MB to max 1GB.

Run below script to get how much huge pages your system needs currently. The script is from Oracle and can be found.

#!/bin/bash
#
# hugepages_settings.sh
#
# Linux bash script to compute values for the
# recommended HugePages/HugeTLB configuration
#
# Note: This script does calculation for all shared memory
# segments available when the script is run, no matter it
# is an Oracle RDBMS shared memory segment or not.
# Check for the kernel version
KERN=`uname -r | awk -F. '{ printf("%d.%d\n",$1,$2); }'`
# Find out the HugePage size
HPG_SZ=`grep Hugepagesize /proc/meminfo | awk {'print $2'}`
# Start from 1 pages to be on the safe side and guarantee 1 free HugePage
NUM_PG=1
# Cumulative number of pages required to handle the running shared memory segments
for SEG_BYTES in `ipcs -m | awk {'print $5'} | grep "[0-9][0-9]*"`
do
   MIN_PG=`echo "$SEG_BYTES/($HPG_SZ*1024)" | bc -q`
   if [ $MIN_PG -gt 0 ]; then
      NUM_PG=`echo "$NUM_PG+$MIN_PG+1" | bc -q`
   fi
done
# Finish with results
case $KERN in
   '2.4') HUGETLB_POOL=`echo "$NUM_PG*$HPG_SZ/1024" | bc -q`;
          echo "Recommended setting: vm.hugetlb_pool = $HUGETLB_POOL" ;;
   '2.6' | '3.8' | '3.10' | '4.1' ) echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
    *) echo "Unrecognized kernel version $KERN. Exiting." ;;
esac
# End

You can save it in /tmp as hugepages_settings.sh and then run it like below :

root@kerneltalks # sh /tmp/hugepages_settings.sh
Recommended setting: vm.nr_hugepages = 124

Output will be similar to some number as shown in above sample output.

This means your system needs 124 huge pages of 2MB each! If you have set 4MB as page size then the output would have been 62. You got the point, right?

Configure hugepages in kernel

Now last part is to configure the above-stated kernel parameter and reload it. Add below value in /etc/sysctl.conf and reload configuration by issuing sysctl -p command.

vm.nr_hugepages=126

Notice that we added 2 extra pages in the kernel since we want to keep a couple of pages spare than the actual required number.

Now, huge pages have been configured in the kernel but to allow your application to use them you need to increase memory limits as well. The new memory limit should be 126 pages x 2 MB each = 252 MB i.e. 258048 KB.

You need to edit below settings in /etc/security/limits.conf

soft memlock 258048 
hard memlock 258048

Sometimes these settings are configured in app-specific files like for Oracle DB its in  /etc/security/limits.d/99-grid-oracle-limits.conf

That’s it! You might want to restart your application to make use of these new huge pages.

How to disable hugepages?

HugePages are generally enabled by default. Use the below command to check the current state of huge pages.

root@kerneltalks # cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never

[always] flag in output shows that hugepages are enabled on system.

For RedHat based systems file path is /sys/kernel/mm/redhat_transparent_hugepage/enabled

If you want to disable huge pages then add transparent_hugepage=never at the end of kernel line in /etc/grub.conf and reboot the system.

⇠ Previous article
check_mk error Cannot fetch deployment URL via curl error
Next article ⇢
Install Python 3 on Linux (Redhat, CentOS, Ubuntu)

Related stuff:

  • What is umask value? How to set it up?
  • How to restart NFS in HPUX
  • How to configure JBOSS EAP 7 as a service in SUSE Linux
  • How to restart service in Linux
  • How to change your shell prompt to fancy one instantly
  • 4 steps guide for SMTP configuration in HPUX
  • 5 steps guide for SMTP configuration in Linux
  • Linux scheduler: Cron, At jobs
  • Build Syslog server in Linux for centralized log management
  • How to do safe and graceful Measureware service restart in HPUX
  • 6 ways to manage service startups using chkconfig in Linux

Filed Under: System services Tagged With: hugepage in rhel6, hugepage in rhel7, hugepage in ubuntu, hugepage settings

If you like my tutorials and if they helped you in any way, then

  • Consider buying me a cup of coffee via paypal!
  • Subscribe to our newsletter here!
  • Like KernelTalks Facebook page.
  • Follow us on Twitter.
  • Add our RSS feed to your feed reader.

Comments

  1. Joel says

    November 3, 2017 at 5:49 pm

    Hugepages and transparent hugepages are two distincts features.

    Hugepage is not enabled by default in RHEL while transparent hugepage is.

    It is recommended to have the SGA in hugepages (known as large page from Oracle) and have transparent hugepage disabled as this last one is not supported by Oracle.

    Reply
  2. LLL says

    November 3, 2017 at 7:08 pm

    The article seems to imply that this is a feature with no downsides. However, it is not enabled by default. Why?

    Reply
    • ROGER DELOY PACK says

      May 8, 2019 at 9:51 pm

      It says it’s typically enabled by default, FWIW…

      Reply
  3. P says

    November 5, 2017 at 4:11 pm

    “less number of”? Oh, you mean fewer?

    That’s not the only grammatical atrocity here.

    Reply
    • Shrikant Lavhate says

      November 5, 2017 at 4:50 pm

      !! Fewer seems appropriate! Edited.
      Thanks.

      Reply
  4. p says

    April 1, 2018 at 9:45 am

    Why would you be worried about grammatical atrocities in a page that talks about huge pages?

    Reply
  5. Hannibal says

    September 13, 2018 at 10:55 am

    In the script you are checking the following kernel version:

    ‘2.6’ | ‘3.8’ | ‘3.10’ | ‘4.1’

    My version is 4.15, I included it in the script and got an output. Just wanted to confirm if the script supports this kernel version and will provide a correct output for it ?

    Reply
  6. Rajesh says

    September 24, 2020 at 10:52 am

    Hello there, Transparent HugePages and HugePages are two different things! Once you enable HugePages, you must disable TransparentHugePages. RHEL calls it as redhat_transparent_hugepage & oracle has it as transparent_hugepages. Once HugePages are configured for Oracle/other, the transparent hugepages must be disabled, using one of the methods.
    Grammar? definitely 🙂 There are far more stuffs worry about.

    Reply
  7. TheDiveO says

    April 24, 2023 at 4:39 pm

    Somehow, saving a script to be run as root in /tmp always looks like a great idea to tell the world about.

    Reply

Share Your Comments & Feedback: Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get fresh content from KernelTalks

  • Email
  • Facebook
  • RSS
  • Twitter

Get Linux & Unix stuff right into your mailbox. Subscribe now!

* indicates required

This work is licensed under a CC-BY-NC license · Privacy Policy
© Copyright 2016-2023 KernelTalks · All Rights Reserved.
The content is copyrighted to Shrikant Lavhate & can not be reproduced either online or offline without prior permission.