Provide basic hugetlb usage as seen in /proc/meminfo for example:
crash> kmem -i
PAGES TOTAL PERCENTAGE
TOTAL MEM 1931928 7.4 GB ----
FREE 210771 823.3 MB 10% of TOTAL MEM
USED 1721157 6.6 GB 89% of TOTAL MEM
SHARED 338699 1.3 GB 17% of TOTAL MEM
BUFFERS 61676 240.9 MB 3% of TOTAL MEM
CACHED 0 0 0% of TOTAL MEM
SLAB 34280 133.9 MB 1% of TOTAL MEM
TOTAL HUGE 524288 2 GB ----
HUGE FREE 524288 2 GB 100% of TOTAL HUGE
TOTAL SWAP 1970175 7.5 GB ----
SWAP USED 30 120 KB 0% of TOTAL SWAP
SWAP FREE 1970145 7.5 GB 99% of TOTAL SWAP
COMMIT LIMIT 2673995 10.2 GB ----
COMMITTED 2068155 7.9 GB 77% of TOTAL LIMIT
Signed-off-by: Aaron Tomlin <atomlin(a)redhat.com>
---
help.c | 3 +++
memory.c | 41 +++++++++++++++++++++++++++++++++++------
2 files changed, 38 insertions(+), 6 deletions(-)
diff --git a/help.c b/help.c
index 4ce2e0a..3be7dc4 100644
--- a/help.c
+++ b/help.c
@@ -5981,6 +5981,9 @@ char *help_kmem[] = {
" CACHED 1276196 4.9 GB 64% of TOTAL MEM",
" SLAB 120410 470.4 MB 6% of TOTAL MEM",
" ",
+" TOTAL HUGE 524288 2 GB ----",
+" HUGE FREE 524288 2 GB 100% of TOTAL HUGE",
+" ",
" TOTAL SWAP 2498559 9.5 GB ----",
" SWAP USED 81978 320.2 MB 3% of TOTAL SWAP",
" SWAP FREE 2416581 9.2 GB 96% of TOTAL SWAP",
diff --git a/memory.c b/memory.c
index 99ea8be..08b5794 100644
--- a/memory.c
+++ b/memory.c
@@ -237,7 +237,7 @@ static int vm_area_page_dump(ulong, ulong, ulong, ulong,
ulong,
struct reference *);
static void rss_page_types_init(void);
static int dump_swap_info(ulong, ulong *, ulong *);
-static int get_hugetlb_total_pages(ulong *);
+static int get_hugetlb_total_pages(ulong *, ulong *);
static void swap_info_init(void);
static char *get_swapdev(ulong, char *);
static void fill_swap_info(ulong);
@@ -8111,7 +8111,8 @@ dump_kmeminfo(void)
long committed;
ulong overcommit_kbytes = 0;
int overcommit_ratio;
- ulong hugetlb_total_pages;
+ ulong hugetlb_total_pages, hugetlb_total_free_pages = 0;
+ int done_hugetlb_calc = 0;
long nr_file_pages, nr_slab;
ulong swapper_space_nrpages;
ulong pct;
@@ -8319,6 +8320,22 @@ dump_kmeminfo(void)
pages_to_size(freelowmem_pages, buf), pct);
}
+ if (get_hugetlb_total_pages(&hugetlb_total_pages,
+ &hugetlb_total_free_pages)) {
+ done_hugetlb_calc = 1;
+
+ fprintf(fp, "\n%13s %7ld %11s ----\n",
+ "TOTAL HUGE", hugetlb_total_pages,
+ pages_to_size(hugetlb_total_pages, buf));
+ pct = hugetlb_total_free_pages ?
+ (hugetlb_total_free_pages * 100) /
+ hugetlb_total_pages : 0;
+ fprintf(fp, "%13s %7ld %11s %3ld%% of TOTAL HUGE\n",
+ "HUGE FREE",
+ hugetlb_total_free_pages,
+ pages_to_size(hugetlb_total_free_pages, buf), pct);
+ }
+
/*
* get swap data from dump_swap_info().
*/
@@ -8347,6 +8364,7 @@ dump_kmeminfo(void)
"swap_info[%ld].swap_map at %lx is inaccessible\n",
totalused_pages, totalswap_pages);
}
+
/*
* Show committed memory
*/
@@ -8364,7 +8382,7 @@ dump_kmeminfo(void)
get_symbol_data("sysctl_overcommit_ratio",
sizeof(int), &overcommit_ratio);
- if (!get_hugetlb_total_pages(&hugetlb_total_pages))
+ if (!done_hugetlb_calc)
goto bailout;
allowed = ((totalram_pages - hugetlb_total_pages)
@@ -15293,19 +15311,21 @@ next_physpage(ulonglong paddr, ulonglong
*nextpaddr)
}
static int
-get_hugetlb_total_pages(ulong *nr_total_pages)
+get_hugetlb_total_pages(ulong *nr_total_pages, ulong *nr_total_free_pages)
{
ulong hstate_p, vaddr;
int i, len;
ulong nr_huge_pages;
+ ulong free_huge_pages;
uint horder;
- *nr_total_pages = 0;
+ *nr_total_pages = *nr_total_free_pages = 0;
if (kernel_symbol_exists("hstates")) {
if (INVALID_SIZE(hstate) ||
INVALID_MEMBER(hstate_order) ||
- INVALID_MEMBER(hstate_nr_huge_pages))
+ INVALID_MEMBER(hstate_nr_huge_pages) ||
+ INVALID_MEMBER(hstate_free_huge_pages))
return FALSE;
len = get_array_length("hstates", NULL, 0);
@@ -15325,7 +15345,12 @@ get_hugetlb_total_pages(ulong *nr_total_pages)
KVADDR, &nr_huge_pages, sizeof(ulong),
"hstate_nr_huge_pages", FAULT_ON_ERROR);
+ readmem(vaddr + OFFSET(hstate_free_huge_pages),
+ KVADDR, &free_huge_pages, sizeof(ulong),
+ "hstate_free_huge_pages", FAULT_ON_ERROR);
+
*nr_total_pages += nr_huge_pages * (1 << horder);
+ *nr_total_free_pages += free_huge_pages * (1 << horder);
}
} else if (kernel_symbol_exists("nr_huge_pages")) {
unsigned long hpage_shift = 21;
@@ -15334,8 +15359,12 @@ get_hugetlb_total_pages(ulong *nr_total_pages)
hpage_shift = 22;
get_symbol_data("nr_huge_pages",
sizeof(ulong), &nr_huge_pages);
+ get_symbol_data("free_huge_pages",
+ sizeof(ulong), &free_huge_pages);
*nr_total_pages = nr_huge_pages * ((1 << hpage_shift) /
machdep->pagesize);
+ *nr_total_free_pages = free_huge_pages *
+ ((1 << hpage_shift) / machdep->pagesize);
}
return TRUE;
}
--
2.9.3
--
Crash-utility mailing list
Crash-utility(a)redhat.com
https://www.redhat.com/mailman/listinfo/crash-utility