Skip to content

Commit

Permalink
mm: vmstat: add cma statistics
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
minchank authored and torvalds committed May 5, 2021
1 parent 7ee820e commit bbb2692
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 4 additions & 0 deletions include/linux/vm_event_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
12 changes: 9 additions & 3 deletions mm/cma.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,21 +435,21 @@ 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);
bitmap_maxno = cma_bitmap_maxno(cma);
bitmap_count = cma_bitmap_pages_to_bits(cma, count);

if (bitmap_count > bitmap_maxno)
return NULL;
goto out;

for (;;) {
spin_lock_irq(&cma->lock);
Expand Down Expand Up @@ -506,6 +506,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;
}

Expand Down
4 changes: 4 additions & 0 deletions mm/vmstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,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",
Expand Down

0 comments on commit bbb2692

Please sign in to comment.