From 61350951095522c425510739a96aec105922f37e Mon Sep 17 00:00:00 2001 From: Prakash Gupta Date: Wed, 2 Aug 2017 12:30:55 +0530 Subject: [PATCH] mm: cma: Register with show_mem notification framework Register with the show_mem notification framework to let cma dump out data for debugging. This is an example output with this patch. cma: cma-0 pages: => 0 used of 2048 total pages cma: cma-1 pages: => 0 used of 23552 total pages cma: cma-2 pages: => 1696 used of 3072 total pages cma: cma-3 pages: => 8277 used of 9216 total pages cma: cma-4 pages: => 186 used of 5120 total pages cma: cma-5 pages: => 3792 used of 8192 total pages. Change-Id: I80d9291444fd9361f5586bdf60373ed8b5b41705 Signed-off-by: Prakash Gupta [ [isaacm@codeaurora.org: Fix trivial merge conflicts] Signed-off-by: Isaac J. Manjarres --- mm/cma.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/mm/cma.c b/mm/cma.c index e7a6f4e511eb..6fdd2fd00bb8 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include "cma.h" @@ -96,6 +97,29 @@ static void cma_clear_bitmap(struct cma *cma, unsigned long pfn, mutex_unlock(&cma->lock); } +static int cma_showmem_notifier(struct notifier_block *nb, + unsigned long action, void *data) +{ + int i; + unsigned long used; + struct cma *cma; + + for (i = 0; i < cma_area_count; i++) { + cma = &cma_areas[i]; + used = bitmap_weight(cma->bitmap, + (int)cma_bitmap_maxno(cma)); + used <<= cma->order_per_bit; + pr_info("cma-%d pages: => %lu used of %lu total pages\n", + i, used, cma->count); + } + + return 0; +} + +static struct notifier_block cma_nb = { + .notifier_call = cma_showmem_notifier, +}; + static int __init cma_activate_area(struct cma *cma) { int bitmap_size = BITS_TO_LONGS(cma_bitmap_maxno(cma)) * sizeof(long); @@ -158,6 +182,8 @@ static int __init cma_init_reserved_areas(void) return ret; } + show_mem_notifier_register(&cma_nb); + return 0; } core_initcall(cma_init_reserved_areas);