mm: cma: add CmaAllocated/CmaReleased info for meminfo node

Show the CMA pages used by cma_alloc in meminfo node.

Tested on RV1126 EVB DDR3:
CmaTotal:         270336 kB
CmaAllocated:      44408 kB
CmaReleased:      225928 kB
CmaFree:               0 kB

The CmaTotal = CmaAllocated + CmaReleased, and the CmaFree is pages
under cma area unused by system.

The CmaAllocated can be calculated by CMA_DEBUGFS.
Tested on RV1126 EVB DDR3:
cat /sys/kernel/debug/cma/*/used
10756
346

The results from cma used is in page count, 1 page = 4kByte
CmaAllocated = 44408kB = 10756 + 346 pages

Change-Id: Ib79001367562c968e6432816b158cba551978173
Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
This commit is contained in:
Jianqun Xu
2020-06-24 14:12:46 +08:00
committed by Tao Huang
parent adb17e773c
commit 7a669a6418
3 changed files with 21 additions and 0 deletions

View File

@@ -144,6 +144,8 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
#ifdef CONFIG_CMA
show_val_kb(m, "CmaTotal: ", totalcma_pages);
show_val_kb(m, "CmaAllocated: ", cma_used_pages());
show_val_kb(m, "CmaReleased: ", totalcma_pages - cma_used_pages());
show_val_kb(m, "CmaFree: ",
global_zone_page_state(NR_FREE_CMA_PAGES));
#endif

View File

@@ -35,6 +35,7 @@ extern int cma_init_reserved_mem(phys_addr_t base, phys_addr_t size,
extern struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align,
bool no_warn);
extern bool cma_release(struct cma *cma, const struct page *pages, unsigned int count);
extern unsigned long cma_used_pages(void);
extern int cma_for_each_area(int (*it)(struct cma *cma, void *data), void *data);

View File

@@ -555,6 +555,24 @@ bool cma_release(struct cma *cma, const struct page *pages, unsigned int count)
}
EXPORT_SYMBOL_GPL(cma_release);
unsigned long cma_used_pages(void)
{
struct cma *cma;
unsigned long used;
unsigned long val = 0;
int i;
for (i = 0; i < cma_area_count; i++) {
cma = &cma_areas[i];
mutex_lock(&cma->lock);
used = bitmap_weight(cma->bitmap, (int)cma_bitmap_maxno(cma));
mutex_unlock(&cma->lock);
val += used << cma->order_per_bit;
}
return val;
}
EXPORT_SYMBOL_GPL(cma_used_pages);
int cma_for_each_area(int (*it)(struct cma *cma, void *data), void *data)
{
int i;