linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] mm: vmstat: add cma statistics
@ 2021-03-02 18:33 Minchan Kim
  2021-03-02 23:09 ` John Hubbard
  0 siblings, 1 reply; 2+ messages in thread
From: Minchan Kim @ 2021-03-02 18:33 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, LKML, joaodias, surenb, jhubbard, Minchan Kim

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.

Signed-off-by: Minchan Kim <minchan@kernel.org>
---
* from v1 - https://lore.kernel.org/linux-mm/20210217170025.512704-1-minchan@kernel.org/
  * change alloc_attempt with alloc_success - jhubbard
  * item per line for vm_event_item - jhubbard

 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 18e75974d4e3..21d7c7f72f1c 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 23d4a97c834a..04ca863d1807 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -435,13 +435,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);
@@ -449,7 +449,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);
@@ -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;
 }
 
diff --git a/mm/vmstat.c b/mm/vmstat.c
index 97fc32a53320..d8c32a33208d 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -1305,6 +1305,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",
-- 
2.30.1.766.gb4fecdf3b7-goog


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] mm: vmstat: add cma statistics
  2021-03-02 18:33 [PATCH v2] mm: vmstat: add cma statistics Minchan Kim
@ 2021-03-02 23:09 ` John Hubbard
  0 siblings, 0 replies; 2+ messages in thread
From: John Hubbard @ 2021-03-02 23:09 UTC (permalink / raw)
  To: Minchan Kim, Andrew Morton; +Cc: linux-mm, LKML, joaodias, surenb

On 3/2/21 10:33, Minchan Kim wrote:
> 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.
> 
> Signed-off-by: Minchan Kim <minchan@kernel.org>
> ---
> * from v1 - https://lore.kernel.org/linux-mm/20210217170025.512704-1-minchan@kernel.org/
>    * change alloc_attempt with alloc_success - jhubbard
>    * item per line for vm_event_item - jhubbard
> 
>   include/linux/vm_event_item.h |  4 ++++
>   mm/cma.c                      | 12 +++++++++---
>   mm/vmstat.c                   |  4 ++++
>   3 files changed, 17 insertions(+), 3 deletions(-)
> 

Seems reasonable, and the diffs look good.

Reviewed-by: John Hubbard <jhubbard@nvidia.com>


thanks,
-- 
John Hubbard
NVIDIA

> diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h
> index 18e75974d4e3..21d7c7f72f1c 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 23d4a97c834a..04ca863d1807 100644
> --- a/mm/cma.c
> +++ b/mm/cma.c
> @@ -435,13 +435,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);
> @@ -449,7 +449,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);
> @@ -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;
>   }
>   
> diff --git a/mm/vmstat.c b/mm/vmstat.c
> index 97fc32a53320..d8c32a33208d 100644
> --- a/mm/vmstat.c
> +++ b/mm/vmstat.c
> @@ -1305,6 +1305,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",
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-03-03 10:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-02 18:33 [PATCH v2] mm: vmstat: add cma statistics Minchan Kim
2021-03-02 23:09 ` John Hubbard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).