尝试执行此示例:
https://github.com/torvalds/linux/blob/master/tools/testing/selftests/vm/hugepage-shm.c
但得到:
shmget: Cannot allocate memory
shmget(0x2, 268435456, IPC_CREAT|SHM_HUGETLB|0600) = -1 ENOMEM (Cannot allocate memory)
这是一台8GB RAM和Ubuntu 16.04,内核4.4.0 ia64的机器
free -m
total used free shared buff/cache available
Mem: 7170 1452 4604 77 1112 5361
Swap: 7623 0 7623
cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never
grep -i huge /proc/meminfo
AnonHugePages: 413696 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
cat /proc/sys/vm/hugetlb_shm_group
0
cat /proc/sys/kernel/shmmax
18446744073692774399
cat /proc/sys/kernel/shmall
18446744073692774399
为什么它不起作用?
答案 0 :(得分:1)
从meminfo,你没有可用的巨页,
您可sysctl vm.hugepages=20
为此启用40M。
对于x86_64 arch,默认情况下启用2Mi大小,如果要使用1Gi大小,则必须添加一些参数作为内核引导参数。
参考: https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt