Not covered here, see https://www.kernel.org/doc/Documentation/vm/transhuge.txt
See https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt
Huge pages cannot be swapped out under memory pressure.
Verify that kernel supports Huge pages
cat /proc/meminfo
:
HugePages_Total: uuu
HugePages_Free: vvv
HugePages_Rsvd: www
HugePages_Surp: xxx
Hugepagesize: yyy kB
Hugetlb: zzz kB
Hugepagesize
is most probably 2MB.
Set up size of kernel huge pages pool (512 pages * 2MB = 1GB)
sudo sysctl -w vm.nr_hugepages=512
It's better be done early at the startup. This could fail due to memory fragmentation.
Add this to /etc/sysctl.conf
:
vm.nr_hugepages = 512
macOS has no superpages support (aka Huge Pages (Linux), aka Large Pages (Windows)) on Apple silicon.
Theoretically you could use VM_FLAGS_SUPERPAGE_SIZE_2MB
or VM_FLAGS_SUPERPAGE_SIZE_ANY
flags, which are defined in <mach/mach_vm.h>
You could profive those flags to mac_vm_allocate()
directly, or pass them in the highest bits of file desciptor of mmap()
:
mmap(0, superpage_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, VM_FLAGS_SUPERPAGE_SIZE_2MB, 0);
Example from tests/superpages/testsp.c
Unfortunately that doesn't work on M1/M2. The only platform that has superpages support is x86_64. It supports 2MB pages. None of the other platforms seems to support it.