Skip to content

Commit fcb2b0c

Browse files
rgushchintorvalds
authored andcommitted
mm: show total hugetlb memory consumption in /proc/meminfo
Currently we display some hugepage statistics (total, free, etc) in /proc/meminfo, but only for default hugepage size (e.g. 2Mb). If hugepages of different sizes are used (like 2Mb and 1Gb on x86-64), /proc/meminfo output can be confusing, as non-default sized hugepages are not reflected at all, and there are no signs that they are existing and consuming system memory. To solve this problem, let's display the total amount of memory, consumed by hugetlb pages of all sized (both free and used). Let's call it "Hugetlb", and display size in kB to match generic /proc/meminfo style. For example, (1024 2Mb pages and 2 1Gb pages are pre-allocated): $ cat /proc/meminfo MemTotal: 8168984 kB MemFree: 3789276 kB <...> CmaFree: 0 kB HugePages_Total: 1024 HugePages_Free: 1024 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB Hugetlb: 4194304 kB DirectMap4k: 32632 kB DirectMap2M: 4161536 kB DirectMap1G: 6291456 kB Also, this patch updates corresponding docs to reflect Hugetlb entry meaning and difference between Hugetlb and HugePages_Total * Hugepagesize. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Roman Gushchin <[email protected]> Acked-by: Michal Hocko <[email protected]> Acked-by: Johannes Weiner <[email protected]> Acked-by: David Rientjes <[email protected]> Cc: Mike Kravetz <[email protected]> Cc: "Aneesh Kumar K.V" <[email protected]> Cc: Andrea Arcangeli <[email protected]> Cc: Dave Hansen <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 9852a72 commit fcb2b0c

File tree

2 files changed

+42
-21
lines changed

2 files changed

+42
-21
lines changed

Documentation/vm/hugetlbpage.txt

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,20 @@ options.
2020

2121
The /proc/meminfo file provides information about the total number of
2222
persistent hugetlb pages in the kernel's huge page pool. It also displays
23-
information about the number of free, reserved and surplus huge pages and the
24-
default huge page size. The huge page size is needed for generating the
25-
proper alignment and size of the arguments to system calls that map huge page
26-
regions.
23+
default huge page size and information about the number of free, reserved
24+
and surplus huge pages in the pool of huge pages of default size.
25+
The huge page size is needed for generating the proper alignment and
26+
size of the arguments to system calls that map huge page regions.
2727

2828
The output of "cat /proc/meminfo" will include lines like:
2929

3030
.....
31-
HugePages_Total: vvv
32-
HugePages_Free: www
33-
HugePages_Rsvd: xxx
34-
HugePages_Surp: yyy
35-
Hugepagesize: zzz kB
31+
HugePages_Total: uuu
32+
HugePages_Free: vvv
33+
HugePages_Rsvd: www
34+
HugePages_Surp: xxx
35+
Hugepagesize: yyy kB
36+
Hugetlb: zzz kB
3637

3738
where:
3839
HugePages_Total is the size of the pool of huge pages.
@@ -47,6 +48,14 @@ HugePages_Surp is short for "surplus," and is the number of huge pages in
4748
the pool above the value in /proc/sys/vm/nr_hugepages. The
4849
maximum number of surplus huge pages is controlled by
4950
/proc/sys/vm/nr_overcommit_hugepages.
51+
Hugepagesize is the default hugepage size (in Kb).
52+
Hugetlb is the total amount of memory (in kB), consumed by huge
53+
pages of all sizes.
54+
If huge pages of different sizes are in use, this number
55+
will exceed HugePages_Total * Hugepagesize. To get more
56+
detailed information, please, refer to
57+
/sys/kernel/mm/hugepages (described below).
58+
5059

5160
/proc/filesystems should also show a filesystem of type "hugetlbfs" configured
5261
in the kernel.

mm/hugetlb.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2975,20 +2975,32 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
29752975

29762976
void hugetlb_report_meminfo(struct seq_file *m)
29772977
{
2978-
struct hstate *h = &default_hstate;
2978+
struct hstate *h;
2979+
unsigned long total = 0;
2980+
29792981
if (!hugepages_supported())
29802982
return;
2981-
seq_printf(m,
2982-
"HugePages_Total: %5lu\n"
2983-
"HugePages_Free: %5lu\n"
2984-
"HugePages_Rsvd: %5lu\n"
2985-
"HugePages_Surp: %5lu\n"
2986-
"Hugepagesize: %8lu kB\n",
2987-
h->nr_huge_pages,
2988-
h->free_huge_pages,
2989-
h->resv_huge_pages,
2990-
h->surplus_huge_pages,
2991-
1UL << (huge_page_order(h) + PAGE_SHIFT - 10));
2983+
2984+
for_each_hstate(h) {
2985+
unsigned long count = h->nr_huge_pages;
2986+
2987+
total += (PAGE_SIZE << huge_page_order(h)) * count;
2988+
2989+
if (h == &default_hstate)
2990+
seq_printf(m,
2991+
"HugePages_Total: %5lu\n"
2992+
"HugePages_Free: %5lu\n"
2993+
"HugePages_Rsvd: %5lu\n"
2994+
"HugePages_Surp: %5lu\n"
2995+
"Hugepagesize: %8lu kB\n",
2996+
count,
2997+
h->free_huge_pages,
2998+
h->resv_huge_pages,
2999+
h->surplus_huge_pages,
3000+
(PAGE_SIZE << huge_page_order(h)) / 1024);
3001+
}
3002+
3003+
seq_printf(m, "Hugetlb: %8lu kB\n", total / 1024);
29923004
}
29933005

29943006
int hugetlb_report_node_meminfo(int nid, char *buf)

0 commit comments

Comments
 (0)