Skip to content

Instantly share code, notes, and snippets.

@FibreFoX
Last active December 23, 2024 07:42
Show Gist options
  • Save FibreFoX/760d70cf63ff7c86582b21c5b7a9bdbe to your computer and use it in GitHub Desktop.
Save FibreFoX/760d70cf63ff7c86582b21c5b7a9bdbe to your computer and use it in GitHub Desktop.
Compile Linux Kernel Raspberry Pi 5 with Huge Pages support

Out of the box the Linux Kernel from Raspberry Pi OS does not come with activated support for Huge Pages, but it can be activated while compiling your own Linux Kernel.

Instructions on how to compile the Linux Kernel for Raspberry Pi can be mostly found on this website:
https://www.raspberrypi.com/documentation/computers/linux_kernel.html

Huge Pages can improve the speed of crypto mining (like Monero) hashes by about 50% compared to the stock Kernel.

First install some reqirements for building and download the Kernel sources:

sudo su
apt update
apt install -y git bc bison flex libssl-dev make libncurses5-dev
cd /opt
git clone --depth=1 https://github.com/raspberrypi/linux
cd linux

After that you need to configure the Kernel for Raspberry Pi 5:

make bcm2712_defconfig

Now you need to activate Huge Pages supprt:

make menuconfig

First change the kernel name by navigating to General Setup and look for Local Version. Change it to something like v8-16k-huge. Then press ESC two times to go back.
At last go to File systems, then to Pseudo filesystems (at the bottom of the list) and there activate HugeTLB file system support- Then press ESC two times to go back.

Then save the configuration.

From here, the normal compile steps have to be executed, which should take about an hour:

make -j4 Image.gz modules dtbs
make modules_install
cp arch/arm64/boot/dts/broadcom/*.dtb /boot/firmware/
cp arch/arm64/boot/dts/overlays/*.dtb* /boot/firmware/overlays/
cp arch/arm64/boot/dts/overlays/README /boot/firmware/overlays/
cp arch/arm64/boot/Image.gz /boot/firmware/kernel8-huge.img

Now activate the new Kernel:

echo "kernel=kernel8-huge.img" | tee -a /boot/firmware/config.txt

To have a specific Huge Page configuration, you have to edit the file /boot/firmware/cmdline.txt in order for the Kernel to reserve the memory. Add something like this at the end of the line:

default_hugepagesz=2M hugepages=1280 hugepagesz=1G hugepages=3

Then reboot

At time of writing, the Rasperry Kernel was 6.1.x, later rechecked for 6.6.22 (still works for me).

EDIT: updated some file locations, thanks to @Pi-novice for pointing out, I probably mixed things up with my Pi 4 setup

@Botspot
Copy link

Botspot commented Aug 3, 2024

Pi5 8GB at default clockspeed, and I used your default_hugepagesz=2M hugepages=1280 hugepagesz=1G hugepages=3.
I see no value in playing with the values here. More would go unused and less would mean XMRig cannot reach 100% utilization. Furthermore, all the issues on the xmrig repo I checked were saying to have 3 1gb hugepages for this one algo and 1280 2M hugepages for the other algos.
Why exactly do you feel that adding more hugepages would be of value, when xmrig already reports that it has what it can use?

@Botspot
Copy link

Botspot commented Aug 4, 2024

@FibreFoX If you are expecting higher values, try the same test yourself.
Compile and install xmrig with the same script I'm using (pi-apps), and then allow it to complete its benchmarks uninhibited. Then look at xmrig's config file to see what the benchmarked values were.

@FibreFoX
Copy link
Author

FibreFoX commented Aug 4, 2024

If was asking just for the sake of clarity. I've heared that Pi5 with 4GB performs somewhat different than the 8GB versions. In addition, due to the hugepages hogging the RAM, it might influence the running system at a whole. I was more looking into enabling the feature, not getting the best performance :)

@Maikeleg
Copy link

Still working on rpi4 8GB, thanks a lot, I used hugepages=6 and get 6GB addressed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment