All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jean Delvare <jdelvare@suse.de>
To: linux-mm@kvack.org
Cc: LKML <linux-kernel@vger.kernel.org>,
	David Hildenbrand <david@redhat.com>,
	Oscar Salvador <osalvador@suse.de>, SeongJae Park <sj@kernel.org>
Subject: [PATCH RFC 2/2] mm/cma: Consolidate accounting in dedicated functions
Date: Mon, 17 Nov 2025 12:15:02 +0100	[thread overview]
Message-ID: <20251117121502.6db0fd7a@endymion> (raw)
In-Reply-To: <20251117115602.7b9c7ccd@endymion>

Move all accounting to dedicated functions and rename them
accordingly.

Signed-off-by: Jean Delvare <jdelvare@suse.de>
---
This is based on a suggestion by SeongJae Park. Comments welcome.

 mm/cma.c |   43 ++++++++++++++++++-------------------------
 1 file changed, 18 insertions(+), 25 deletions(-)

--- linux-6.17.orig/mm/cma.c
+++ linux-6.17/mm/cma.c
@@ -37,31 +37,27 @@ struct cma cma_areas[MAX_CMA_AREAS];
 unsigned int cma_area_count;
 
 #ifdef CONFIG_SYSFS
-static void cma_sysfs_account_success_pages(struct cma *cma,
-					    unsigned long nr_pages)
+#define cma_inc_page_counter(n, a)	atomic64_add((n), (a))
+#else
+#define cma_inc_page_counter(n, a)	do {} while (0)
+#endif
+
+static void cma_account_success(struct cma *cma, unsigned long nr_pages)
 {
-	atomic64_add(nr_pages, &cma->nr_pages_succeeded);
+	count_vm_event(CMA_ALLOC_SUCCESS);
+	cma_inc_page_counter(nr_pages, &cma->nr_pages_succeeded);
 }
 
-static void cma_sysfs_account_fail_pages(struct cma *cma,
-					 unsigned long nr_pages)
+static void cma_account_fail(struct cma *cma, unsigned long nr_pages)
 {
-	atomic64_add(nr_pages, &cma->nr_pages_failed);
+	count_vm_event(CMA_ALLOC_FAIL);
+	cma_inc_page_counter(nr_pages, &cma->nr_pages_failed);
 }
 
-static void cma_sysfs_account_release_pages(struct cma *cma,
-					    unsigned long nr_pages)
+static void cma_account_release(struct cma *cma, unsigned long nr_pages)
 {
-	atomic64_add(nr_pages, &cma->nr_pages_released);
+	cma_inc_page_counter(nr_pages, &cma->nr_pages_released);
 }
-#else
-static void cma_sysfs_account_success_pages(struct cma *cma,
-					    unsigned long nr_pages) {};
-static void cma_sysfs_account_fail_pages(struct cma *cma,
-					 unsigned long nr_pages) {};
-static void cma_sysfs_account_release_pages(struct cma *cma,
-					    unsigned long nr_pages) {};
-#endif
 
 phys_addr_t cma_get_base(const struct cma *cma)
 {
@@ -921,13 +917,10 @@ static struct page *__cma_alloc(struct c
 	pr_debug("%s(): returned %p\n", __func__, page);
 	trace_cma_alloc_finish(name, page ? page_to_pfn(page) : 0,
 			       page, count, align, ret);
-	if (page) {
-		count_vm_event(CMA_ALLOC_SUCCESS);
-		cma_sysfs_account_success_pages(cma, count);
-	} else {
-		count_vm_event(CMA_ALLOC_FAIL);
-		cma_sysfs_account_fail_pages(cma, count);
-	}
+	if (page)
+		cma_account_success(cma, count);
+	else
+		cma_account_fail(cma, count);
 
 	return page;
 }
@@ -1029,7 +1022,7 @@ bool cma_release(struct cma *cma, const
 
 	free_contig_range(pfn, count);
 	cma_clear_bitmap(cma, cmr, pfn, count);
-	cma_sysfs_account_release_pages(cma, count);
+	cma_account_release(cma, count);
 	trace_cma_release(cma->name, pfn, pages, count);
 
 	return true;

-- 
Jean Delvare
SUSE L3 Support


  reply	other threads:[~2025-11-17 11:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-17 10:56 [PATCH v2 1/2] mm/cma: Inline cma_sysfs counter hooks Jean Delvare
2025-11-17 11:15 ` Jean Delvare [this message]
2025-11-18  1:40   ` [PATCH RFC 2/2] mm/cma: Consolidate accounting in dedicated functions SeongJae Park
2025-11-17 11:22 ` [PATCH v2 1/2] mm/cma: Inline cma_sysfs counter hooks David Hildenbrand (Red Hat)
2025-11-18  1:34 ` SeongJae Park

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251117121502.6db0fd7a@endymion \
    --to=jdelvare@suse.de \
    --cc=david@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=osalvador@suse.de \
    --cc=sj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.