Linux 大頁使用統計

Linux 大頁使用統計

我已經配置了大頁面以與 Java 一起使用,儘管我對 /proc/meminfo 中的記帳有疑問,但它似乎運作良好。為了顯示

# grep HugePages /proc/meminfo 
AnonHugePages:    274432 kB
HugePages_Total:    1008
HugePages_Free:      596
HugePages_Rsvd:      594
HugePages_Surp:        0

我的問題涉及“免費”和“Rsvd”數字 - 為什麼它們加起來不等於“總計”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.

相關內容