Requesting HugeTLB Pages Using NUMA Node Specific Parameters Early in the Boot Process

The precise way to request huge pages at boot time depends upon the system's requirements. The following procedure provides some guidance but isn't exclusive of other approaches to configuring boot options.

Huge Pages requested by using the kernel boot-time parameters, as shown in the previous example, are divided equally between the NUMA nodes.

However, you might need to request a different number of huge pages for specific nodes by setting the configuration values in a node specific file path. The file path is defined as follows:.

/sys/devices/system/node/node{0,1,2…n}/hugepages/hugepages-<SIZE>kB/

The following procedure describes how to reserve 299 pages of 2 MB size on node 0, and 300 pages of 2 MB size on node 1 on a NUMA system. This approach uses a custom systemd service to run a shell script after boot, to set the sysfs parameters required.

Before beginning the following procedure, ensure that you have the administrative privileges required for all the steps.

For more information about using systemd units, see see Oracle Linux 8: Managing the System With systemd.

  1. Create a script 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
    
    #######################################################
    #                                                     #
    #     FUNCTION                                        #
    #           reserve_pages <number_of_pages> <node_id> #
    #                                                     #
    ####################################################### 
    
    reserve_pages()
    {
        echo $1 > $nodes_path/$2/hugepages/hugepages-2048kB/nr_hugepages
    }
    
    reserve_pages 299 node0    
    reserve_pages 300 node1 
    
  2. Make the script executable:
    sudo chmod +x /usr/lib/systemd/hugetlb-reserve-pages.sh
  3. Create a service file called hugetlb-gigantic-pages.service in the /usr/lib/systemd/system/ directory and add the following content to it.
    [Unit]
    Description=HugeTLB Gigantic Pages Reservation
    DefaultDependencies=no
    Before=dev-hugepages.mount
    ConditionPathExists=/sys/devices/system/node
    
    [Service]
    Type=oneshot
    RemainAfterExit=yes
    ExecStart=/usr/lib/systemd/hugetlb-reserve-pages.sh
    
    [Install]
    WantedBy=sysinit.target
  4. Enable the service file.
    sudo systemctl enable hugetlb-gigantic-pages