更新:我将默认的大页面大小切换为 2MB 并重新启动以确认它始终是失败的非默认大小,现在我可以从两个池中分配。我很困惑,但可能正在取得进展。
我一直试图让 shmget 和 mmap 从非默认的大页面池中分配,但在内核 4.13.0-32-generic 上没有成功。我已经配置了 2M 和 1G 的大页面。使用 1G 页面作为默认大小,此调用将成功:
addr = mmap(0, byteAmount, PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_HUGETLB|MAP_ANONYMOUS|MAP_HUGE_1GB, -1, 0);
但这将失败Cannot allocate memory
:
addr = mmap(0, byteAmount, PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_HUGETLB|MAP_ANONYMOUS|MAP_HUGE_2MB, -1, 0);
hugeadm --解释输出:
Total System Memory: 32004 MB
Mount Point Options
/dev/hugepages rw,relatime,pagesize=1024M
/dev/hugepages2MB rw,relatime,pagesize=2M
Huge page pools:
Size Minimum Current Maximum Default
2097152 1024 1024 1024
1073741824 1 1 1 *
Huge page sizes with configured pools:
2097152
1073741824
The /proc/sys/vm/min_free_kbytes of 67584 is too small. To maximiuse efficiency
of fragmentation avoidance, there should be at least one huge page free per zone
in the system which minimally requires a min_free_kbytes value of 57671680
A /proc/sys/kernel/shmmax value of 6442450944 bytes may be sub-optimal. To maximise
shared memory usage, this should be set to the size of the largest shared memory
segment size you want to be able to use. Alternatively, set it to a size matching
the maximum possible allocation size of all huge pages. This can be done
automatically, using the --set-recommended-shmmax option.
The recommended shmmax for your currently allocated huge pages is 3221225472 bytes.
To make shmmax settings persistent, add the following line to /etc/sysctl.conf:
kernel.shmmax = 3221225472
hugeadm:WARNING: There is no swap space configured, resizing hugepage pool may fail
hugeadm:WARNING: Use --add-temp-swap option to temporarily add swap during the resize
To make your hugetlb_shm_group settings persistent, add the following line to /etc/sysctl.conf:
vm.hugetlb_shm_group = 0
Note: Permanent swap space should be preferred when dynamic huge page pools are used.
目标是能够使用 2MB 和 1GB 页面的组合来最大化 TLB 命中率。非常感谢任何帮助!