43 Huge pages #
When a process uses RAM, the CPU marks the exact portion utilized by that process. To achieve efficiency, the CPU allocates RAM in blocks known as pages; the default page size on many platforms is 4 KB. Pages can be swapped to disk (among other operations).
Since the process address space is virtual, the CPU and the operating system must keep track of which pages belong to each process and where each one is stored. The greater the number of pages, the longer it takes to look up memory mappings. For example, a process using 1 GB of memory involves 262,144 entries to check (1 GB / 4 KB). If each page table entry occupies 8 bytes, this results in a total of 2 MB (262,144 * 8) of data to be consulted.
Most current CPU architectures allow for the definition of blocks of pages each with a size larger than the default 4 KB value (with 1 GB and 2 MB being typical supported values) known as huge pages, which reduces the number of entries the CPU/Operating System must consult.
Kernel parameters
To enable huge pages, we must add the following kernel parameters. In this example, we configure 40 pages of 1 GB size each and 0 pages of 2 MB size each, though the huge page sizes to support and the exact amount of pages for each should be adjusted according to your application’s memory requirements:
| parameter | value | description |
|---|---|---|
hugepagesz | 1G | This option allows to set the size of "huge pages" to 1 GB |
hugepages | 40 | This is the number of "huge pages" requested to allocate at boot for the size defined just before (1 GB) |
hugepagesz | 2M | This option allows to set the size of "huge pages" to 2 MB |
hugepages | 0 | This is the number of "huge pages" requested to allocate at boot for the size defined just before (2 MB) |
default_hugepagesz | 1G | This is the default value for the "huge pages" size |
Modify the GRUB file /etc/default/grub to add these parameters in GRUB_CMDLINE_LINUX:
default_hugepagesz=1G hugepagesz=1G hugepages=40 hugepagesz=2M hugepages=0Update the GRUB configuration and reboot the system to apply the changes:
$ transactional-update grub.cfg
$ rebootTo validate that the parameters are applied after the reboot, you can check the command line:
$ cat /proc/cmdlineUsing huge pages
To use the huge pages, we need to mount them:
$ mkdir -p /hugepages
$ mount -t hugetlbfs nodev /hugepagesDeploy a Kubernetes workload, creating the resources and the volumes:
...
resources:
requests:
memory: "24Gi"
hugepages-1Gi: 16Gi
intel.com/intel_sriov_oru: '4'
limits:
memory: "24Gi"
hugepages-1Gi: 16Gi
intel.com/intel_sriov_oru: '4'
......
volumeMounts:
- name: hugepage
mountPath: /hugepages
...
volumes:
- name: hugepage
emptyDir:
medium: HugePages
...