mm: vmstat: add cma statistics
authorMinchan Kim <minchan@kernel.org>
Wed, 21 Apr 2021 04:44:11 +0000 (14:44 +1000)
committerHoegeun Kwon <hoegeun.kwon@samsung.com>
Mon, 7 Feb 2022 08:01:41 +0000 (17:01 +0900)
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 <minchan@kernel.org>
Reviewed-by: John Hubbard <jhubbard@nvidia.com>
Cc: John Dias <joaodias@google.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Origin: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=bbb269206f3c914d4f23e023de4ec020abea6d1b
Signed-off-by: Ɓukasz Stelmach <l.stelmach@samsung.com>
Change-Id: Iadf5fef76fe6dfa41177cfccf022ea39ae1cb19e

include/linux/vm_event_item.h
mm/cma.c
mm/vmstat.c

index 18e7597..21d7c7f 100644 (file)
@@ -71,6 +71,10 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
 #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 */
                UNEVICTABLE_PGRESCUED,  /* rescued from noreclaim list */
index ebcf221..9749e95 100644 (file)
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -420,13 +420,13 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align,
        int ret = -ENOMEM;
 
        if (!cma || !cma->count || !cma->bitmap)
-               return NULL;
+               goto out;
 
        pr_debug("%s(cma %p, count %zu, align %d)\n", __func__, (void *)cma,
                 count, align);
 
        if (!count)
-               return NULL;
+               goto out;
 
        mask = cma_bitmap_aligned_mask(cma, align);
        offset = cma_bitmap_aligned_offset(cma, align);
@@ -434,7 +434,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);
@@ -492,6 +492,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;
 }
 
index 698bc0b..2cf6681 100644 (file)
@@ -1298,6 +1298,10 @@ const char * const vmstat_text[] = {
        "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",
        "unevictable_pgs_rescued",