HUGEPAGES is diabled by default in the Raspberry Pi Linux kernel. To enable HUGEPAGES the kernel must be recompiled.
Tested and works as expected on Raspberry Pi 4B, 400, CM4, and 5.
sudo apt update
sudo apt install -y git build-essential bc bison kmod cpio flex libncurses5-dev libelf-dev libssl-dev
git clone --depth=1 https://github.com/raspberrypi/linux
cd linux
cp .config .config.backup
The .config file is not present until the following command is ran which generates a fresh basic .config file.
KERNEL=kernel_2712
make bcm2712_defconfig
sed -i 's/# CONFIG_HUGETLBFS.*/CONFIG_HUGETLBFS=y/' .config
sed -i 's/# CONFIG_TRANSPARENT_HUGEPAGE.*/CONFIG_TRANSPARENT_HUGEPAGE=y/' .config
sed -i 's/# CONFIG_HUGETLB_PAGE.*/CONFIG_HUGETLB_PAGE=y/' .config
sed -i 's/# CONFIG_ARCH_HAS_HUGEPD.*/CONFIG_ARCH_HAS_HUGEPD=y/' .config
sed -i 's/# CONFIG_HUGETLB_PAGE_SIZE_VARIABLE.*/CONFIG_HUGETLB_PAGE_SIZE_VARIABLE=y/' .config
sed -i 's/# CONFIG_ARCH_WANT_GENERAL_HUGETLB.*/CONFIG_ARCH_WANT_GENERAL_HUGETLB=y/' .config
sed -i 's/# CONFIG_SYSFS.*/CONFIG_SYSFS=y/' .config
sed -i 's/# CONFIG_CHECKPOINT_RESTORE.*/CONFIG_CHECKPOINT_RESTORE=y/' .config
sed -i 's/# CONFIG_HIGH_RES_TIMERS.*/CONFIG_HIGH_RES_TIMERS=y/' .configmake -j4 Image.gz modules dtbs
sudo make modules_install
sudo cp arch/arm64/boot/dts/broadcom/*.dtb /boot/firmware/
sudo cp arch/arm64/boot/dts/overlays/*.dtb* /boot/firmware/overlays/
sudo cp arch/arm64/boot/dts/overlays/README /boot/firmware/overlays/
sudo cp arch/arm64/boot/Image.gz /boot/firmware/$KERNEL.imgsudo cp arch/arm64/boot/Image.gz /boot/firmware/kernel8hp.img
Edit the config.txt file and specify the new kernel:
sudo nano /boot/firmware/config.txt
Add the following line and comment out and other kernel= lines if present.
kernel=kernel8hp.img
Check current HUGEPAGES:
Display HUGEPAGE information
grep -i huge /proc/meminfo
Displays the number of HUGEPAGES currently allocated
grep HugePages_Total /proc/meminfo