finally managed to configure 4x 1GB #HugePages on my #Debian.
`/etc/default/grub`:
```
GRUB_CMDLINE_LINUX_DEFAULT="hugepagesz=1GB default_hugepagesz=1GB hu
gepages=4"
```
`/etc/group`:
```
hugetlb:x:1003:claude
```
`/etc/fstab`:
```
hugetlbfs /dev/hugepages hugetlbfs mode=1770,gid=1003,pagesize=1GB 0 0
```
`/etc/sysctl.conf`:
```
vm.nr_hugepages = 4
vm.hugetlb_shm_group = 1003
```
reboot
`my-code.c++`:
```
#define MAP_HUGE_1GB (30 << MAP_HUGE_SHIFT)
data = (unsigned char *) mmap(nullptr, bytes, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_HUGETLB | MAP_HUGE_1GB | MAP_ANONYMOUS, -1, 0);
if (data != MMAP_FAILED)
size_t read_bytes = 0;
do
{
ssize_t result = read(fd, data + read_bytes, bytes - read_bytes);
if (result <= 0)
{
break;
}
read_bytes += result;
} while (read_bytes < bytes);
if (read_bytes == bytes)
/* :-) */;
}
```
in particular, MAP_ANONYMOUS seems to be required for MAP_HUGETLB, which means specifying -1 instead of the fd directly, and reading the data later (which needs PROT_WRITE). the loop is because read won't more than 0x7ffff000 bytes at once.
don't know if all of this is necessary, but it works now (I may have missed some steps, tried a few different things before success).
ref: https://wiki.debian.org/Hugepages
ref: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/tools/testing/selftests/vm/map_hugetlb.c?h=v5.2.14