Skip to content

Commit d002858

Browse files
Wanpeng Litorvalds
Wanpeng Li
authored andcommitted
mm/hugetlb: fix total hugetlbfs pages count when using memory overcommit accouting
hugetlb_total_pages is used for overcommit calculations but the current implementation considers only the default hugetlb page size (which is either the first defined hugepage size or the one specified by default_hugepagesz kernel boot parameter). If the system is configured for more than one hugepage size, which is possible since commit a137e1c ("hugetlbfs: per mount huge page sizes") then the overcommit estimation done by __vm_enough_memory() (resp. shown by meminfo_proc_show) is not precise - there is an impression of more available/allowed memory. This can lead to an unexpected ENOMEM/EFAULT resp. SIGSEGV when memory is accounted. Testcase: boot: hugepagesz=1G hugepages=1 the default overcommit ratio is 50 before patch: egrep 'CommitLimit' /proc/meminfo CommitLimit: 55434168 kB after patch: egrep 'CommitLimit' /proc/meminfo CommitLimit: 54909880 kB [[email protected]: coding-style tweak] Signed-off-by: Wanpeng Li <[email protected]> Acked-by: Michal Hocko <[email protected]> Cc: "Aneesh Kumar K.V" <[email protected]> Cc: Hillf Danton <[email protected]> Cc: KAMEZAWA Hiroyuki <[email protected]> Cc: <[email protected]> [3.0+] Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent dc72c32 commit d002858

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

mm/hugetlb.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -2124,8 +2124,12 @@ int hugetlb_report_node_meminfo(int nid, char *buf)
21242124
/* Return the number pages of memory we physically have, in PAGE_SIZE units. */
21252125
unsigned long hugetlb_total_pages(void)
21262126
{
2127-
struct hstate *h = &default_hstate;
2128-
return h->nr_huge_pages * pages_per_huge_page(h);
2127+
struct hstate *h;
2128+
unsigned long nr_total_pages = 0;
2129+
2130+
for_each_hstate(h)
2131+
nr_total_pages += h->nr_huge_pages * pages_per_huge_page(h);
2132+
return nr_total_pages;
21292133
}
21302134

21312135
static int hugetlb_acct_memory(struct hstate *h, long delta)

0 commit comments

Comments
 (0)