11.3. Configuring HugeTLB at boot time


The HugeTLB enables the use of huge pages by reserving them at boot time, thereby minimizing memory fragmentation and ensuring that sufficient resources are available for workloads that can benefit from larger memory pages.

11.3.1. Configuring HugeTLB by using kernel command line parameters

You can reserve Huge Translation Lookaside Buffer (HugeTLB) pages at the earliest stage of boot process by using kernel command-line parameters. This method provides the highest chance of successfully reserving the required number and size of huge pages, because memory is allocated during the kernel boot.

Prefer reserving HugeTLB pages by using kernel boot parameters, as this method ensures allocation of larger contiguous memory regions compared to using a systemd unit.

注記

The examples in the procedure demonstrate how to use the command-line options for configuring HugeTLB pages. These examples do not necessarily apply to your system configuration. Review your system requirements and objectives before applying these settings in your environment.

Prerequisites

  • You must have root privileges on your system.

Procedure

  • Update the kernel command line to include HugeLTB options.

    • To reserve HugeTLB pages of the default size for your architecture, enter:

      # grubby --update-kernel=ALL --args="hugepages=10"

      This command reserves 10 HugeTLB pages of the default pool size. For example, on x86_64, the default pool size is 2 MB. On systems with Non-Uniform Memory Access (NUMA), the allocation is distributed evenly across NUMA nodes. If the system has two NUMA nodes, each node reserves five pages.

    • To reserve different sizes of HugeTLB pages, specify the hugepagesz and hugepages options in the kernel command line, enter:

      # grubby --update-kernel=ALL --args="hugepagesz=2M hugepages=10 hugepagesz=1G hugepages=1"

      This command reserves 10 pages of 2 MB each and 1 page of 1 GB.

      The system reserves the specified number and size of HugeTLB pages at boot time, ensuring that memory is allocated before the operating system begins normal operation.

      重要

      The order of the options is significant. Each hugepagesz= option must be immediately followed by its corresponding hugepages= option.

11.3.2. Configuring HugeTLB by using systemd service unit

You can configure Huge Translation Lookaside Buffer (HugeTLB) pages during the user-space booting process by using a systemd service unit. This method reserves large memory pages after the kernel has initialized but before starting of most of user-space services. Although this approach is not as early as kernel command-line configuration, it can still be effective for ensuring that applications have access to the required huge pages during system operation.

Prerequisites

  • You must have root privileges on your system.

Procedure

  1. Create a new file called hugetlb-gigantic-pages.service in the /usr/lib/systemd/system/ directory and add the following content:

    [Unit]
    Description=HugeTLB Gigantic Pages Reservation
    DefaultDependencies=no
    Before=dev-hugepages.mount
    ConditionPathExists=/sys/devices/system/node
    ConditionKernelCommandLine=hugepagesz=1G
    
    [Service]
    Type=oneshot
    RemainAfterExit=yes
    ExecStart=/usr/lib/systemd/hugetlb-reserve-pages.sh
    
    [Install]
    WantedBy=sysinit.target
  2. Create a new file called hugetlb-reserve-pages.sh in the /usr/lib/systemd/ directory and add the following content:

    #!/bin/sh
    
    nodes_path=/sys/devices/system/node/
    if [ ! -d $nodes_path ]; then
        echo "ERROR: $nodes_path does not exist"
        exit 1
    fi
    
    reserve_pages()
    {
        echo $1 > $nodes_path/$2/hugepages/hugepages-1048576kB/nr_hugepages
    }
    
    reserve_pages <number_of_pages> <node>

    Replace <number_of_pages> with the number of 1GB pages you want to reserve, and <node> with the node name on which to reserve these pages. For example, to reserve two 1 GB pages on node0 and one 1GB page on node1, replace <number_of_pages> with 2 for node0 and 1 for node1.

  3. Create an executable script:

    # chmod +x /usr/lib/systemd/hugetlb-reserve-pages.sh
  4. Enable early boot reservation:

    # systemctl enable hugetlb-gigantic-pages.service
    注記
    • You can try reserving more 1 GB pages at runtime by writing to the nr_hugepages attribute at any time. However, to prevent failures due to memory fragmentation, reserve 1 GB pages early during the boot process.
    • Reserving static huge pages can effectively reduce the amount of memory available to the system, and prevent it from using its full memory capacity. Although a properly sized pool of reserved huge pages can be beneficial to applications that use it, an oversized or unused pool of reserved huge pages will eventually be detrimental to the overall system performance. When setting a reserved huge page pool, ensure that the system can properly use its full memory capacity.
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

Theme

© 2026 Red Hat
トップに戻る