From 0fb3917d8a354d6d309fabfa1989e1caa71d3897 Mon Sep 17 00:00:00 2001 From: Minchan Kim Date: Thu, 4 Mar 2021 12:30:30 -0800 Subject: [PATCH] BACKPORT: FROMGIT: mm: vmstat: add cma statistics Since CMA is used more widely, it's worth to have CMA allocation statistics into vmstat. With it, we could know how agressively system uses cma allocation and how often it fails. Link: https://lkml.kernel.org/r/20210302183346.3707237-1-minchan@kernel.org Signed-off-by: Minchan Kim Reviewed-by: John Hubbard Cc: John Dias Cc: Suren Baghdasaryan Signed-off-by: Andrew Morton Bug: 181887812 Signed-off-by: Minchan Kim (cherry picked from https://lore.kernel.org/mm-commits/20210302232736.Dy5dxmWpK%25akpm@linux-foundation.org/) [minchan: Resolved minor bailout path in mm/cma.c ] Change-Id: Ib5a8cfd0944689e84c8bbf136d215981e956b82f --- include/linux/vm_event_item.h | 4 ++++ mm/cma.c | 12 +++++++++--- mm/vmstat.c | 4 ++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h index 919e8ee0f078..0e73f8a955a8 100644 --- a/include/linux/vm_event_item.h +++ b/include/linux/vm_event_item.h @@ -70,6 +70,10 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT, #endif #ifdef CONFIG_HUGETLB_PAGE HTLB_BUDDY_PGALLOC, HTLB_BUDDY_PGALLOC_FAIL, +#endif +#ifdef CONFIG_CMA + CMA_ALLOC_SUCCESS, + CMA_ALLOC_FAIL, #endif UNEVICTABLE_PGCULLED, /* culled to noreclaim list */ UNEVICTABLE_PGSCANNED, /* scanned for reclaimability */ diff --git a/mm/cma.c b/mm/cma.c index 1433718e24e3..41bb349ad4fe 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -441,13 +441,13 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align, int max_retries = 5; if (!cma || !cma->count || !cma->bitmap) - return NULL; + goto out; pr_debug("%s(cma %p, count %zu, align %d gfp_mask 0x%x)\n", __func__, (void *)cma, count, align, gfp_mask); if (!count) - return NULL; + goto out; mask = cma_bitmap_aligned_mask(cma, align); offset = cma_bitmap_aligned_offset(cma, align); @@ -455,7 +455,7 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align, bitmap_count = cma_bitmap_pages_to_bits(cma, count); if (bitmap_count > bitmap_maxno) - return NULL; + goto out; for (;;) { mutex_lock(&cma->lock); @@ -530,6 +530,12 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align, } pr_debug("%s(): returned %p\n", __func__, page); +out: + if (page) + count_vm_event(CMA_ALLOC_SUCCESS); + else + count_vm_event(CMA_ALLOC_FAIL); + return page; } EXPORT_SYMBOL_GPL(cma_alloc); diff --git a/mm/vmstat.c b/mm/vmstat.c index ceb66e960376..932928653b21 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1295,6 +1295,10 @@ const char * const vmstat_text[] = { #ifdef CONFIG_HUGETLB_PAGE "htlb_buddy_alloc_success", "htlb_buddy_alloc_fail", +#endif +#ifdef CONFIG_CMA + "cma_alloc_success", + "cma_alloc_fail", #endif "unevictable_pgs_culled", "unevictable_pgs_scanned",