Skip to content

Instantly share code, notes, and snippets.

Last active April 13, 2024 09:12
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:

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
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

Copy link

For reference: on my newly arrived Raspberry Pi 5 with 8GB RAM the hashing rate is about 330 H/s with a single thread running XMRIG

Copy link

Thank you for taking the time to put this together

Copy link

Since the 3/12/24 update, this doesn't seem to work.

Copy link

At time of writing, the kernel was 6.1.x, since some weeks this is now based on 6.6.x as default. I have recompile the kernel, and for me it is still working @Pi-novice , no other changes were required.

Copy link

Pi-novice commented Mar 24, 2024

Finally working.
Are you sure that :
echo "kernel=kernel8-huge.img" | tee -a /boot/config.txt
shouldn't be :
echo "kernel=kernel8-huge.img" | tee -a /boot/firmware/config.txt

I do not know if the last update is when they stopped using /boot/config.txt and started using /boot/firmware/config.txt.
But once I did the above change, it all worked.

need to change from /boot/cmdline.txt to /boot/firmware/cmdline.txt also.

Copy link

@Pi-novice interesting ... it is working for me, so I am a bit confused. Maybe it is something with my local installation, Initially I had an older RaspberryPiOS image, maybe it has something to do with the way how they are having their files stored now. Glad you found your way ;)

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