我已经配置了 Huge Pages 供 Java 使用,它似乎运行良好,尽管我对 /proc/meminfo 中的记账有疑问。为了说明
# grep HugePages /proc/meminfo
AnonHugePages: 274432 kB
HugePages_Total: 1008
HugePages_Free: 596
HugePages_Rsvd: 594
HugePages_Surp: 0
我的问题是关于“免费”和“已保留”的数字——为什么它们加起来不等于“总数”1008?它们实际上加起来是1190。我不明白这里什么地方?
答案1
这是因为 HugePages_rsvd 本质上是从 HugePages_Free 读取的。也就是说,在 596 个空闲的大页面中,594 个已经被某个应用程序保留以供使用。也就是说,内核已承诺这 594 个大页面可供应用程序使用。
如果现在请求 3 个大页面,那么请求将会失败,因为只有 2 个可供保留。可以将其视为 malloc() 调用,当您保留内存虚拟页面以考虑进程的 VSZ 时,但当进程实际使用它们时,它们将成为进程的 RSZ(运行集)。
由于大页面始终驻留在主内存中,因此当应用程序请求它们时,内核会从空闲池中减少它的数量并增加 Rsvd 计数器。
这是来自内核源代码。https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt
where:
HugePages_Total is the size of the pool of huge pages.
HugePages_Free is the number of huge pages in the pool that are not yet
allocated.
HugePages_Rsvd is short for "reserved," and is the number of huge pages for
which a commitment to allocate from the pool has been made,
but no allocation has yet been made. Reserved huge pages
guarantee that an application will be able to allocate a
huge page from the pool of huge pages at fault time.
HugePages_Surp is short for "surplus," and is the number of huge pages in
the pool above the value in /proc/sys/vm/nr_hugepages. The
maximum number of surplus huge pages is controlled by
/proc/sys/vm/nr_overcommit_hugepages.