* [PATCH v2 1/2] mm/cma: Inline cma_sysfs counter hooks
@ 2025-11-17 10:56 Jean Delvare
2025-11-17 11:15 ` [PATCH RFC 2/2] mm/cma: Consolidate accounting in dedicated functions Jean Delvare
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Jean Delvare @ 2025-11-17 10:56 UTC (permalink / raw)
To: linux-mm; +Cc: LKML, David Hildenbrand, Oscar Salvador, SeongJae Park
Move cma_sysfs counter hooks from cma_sysfs.c to cma.c. These
one-liner functions are only used once each, but the compiler
currently can't inline them because they are defined in one object and
used in another. Letting the compiler inline these functions lowers
the footprint and runtime cost of the sysfs interface to CMA stats
even more.
Signed-off-by: Jean Delvare <jdelvare@suse.de>
---
Changes in v2:
* Move the functions to cma.c as this is the only place where they
are used.
mm/cma.c | 27 +++++++++++++++++++++++++++
mm/cma.h | 12 ------------
mm/cma_sysfs.c | 15 ---------------
3 files changed, 27 insertions(+), 27 deletions(-)
--- linux-6.17.orig/mm/cma.h
+++ linux-6.17/mm/cma.h
@@ -80,16 +80,4 @@ static inline unsigned long cma_bitmap_m
return cmr->count >> cma->order_per_bit;
}
-#ifdef CONFIG_SYSFS
-void cma_sysfs_account_success_pages(struct cma *cma, unsigned long nr_pages);
-void cma_sysfs_account_fail_pages(struct cma *cma, unsigned long nr_pages);
-void cma_sysfs_account_release_pages(struct cma *cma, unsigned long nr_pages);
-#else
-static inline void cma_sysfs_account_success_pages(struct cma *cma,
- unsigned long nr_pages) {};
-static inline void cma_sysfs_account_fail_pages(struct cma *cma,
- unsigned long nr_pages) {};
-static inline void cma_sysfs_account_release_pages(struct cma *cma,
- unsigned long nr_pages) {};
-#endif
#endif
--- linux-6.17.orig/mm/cma_sysfs.c
+++ linux-6.17/mm/cma_sysfs.c
@@ -14,21 +14,6 @@
#define CMA_ATTR_RO(_name) \
static struct kobj_attribute _name##_attr = __ATTR_RO(_name)
-void cma_sysfs_account_success_pages(struct cma *cma, unsigned long nr_pages)
-{
- atomic64_add(nr_pages, &cma->nr_pages_succeeded);
-}
-
-void cma_sysfs_account_fail_pages(struct cma *cma, unsigned long nr_pages)
-{
- atomic64_add(nr_pages, &cma->nr_pages_failed);
-}
-
-void cma_sysfs_account_release_pages(struct cma *cma, unsigned long nr_pages)
-{
- atomic64_add(nr_pages, &cma->nr_pages_released);
-}
-
static inline struct cma *cma_from_kobj(struct kobject *kobj)
{
return container_of(kobj, struct cma_kobject, kobj)->cma;
--- linux-6.17.orig/mm/cma.c
+++ linux-6.17/mm/cma.c
@@ -36,6 +36,33 @@
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)
+{
+ atomic64_add(nr_pages, &cma->nr_pages_succeeded);
+}
+
+static void cma_sysfs_account_fail_pages(struct cma *cma,
+ unsigned long nr_pages)
+{
+ atomic64_add(nr_pages, &cma->nr_pages_failed);
+}
+
+static void cma_sysfs_account_release_pages(struct cma *cma,
+ unsigned long nr_pages)
+{
+ atomic64_add(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)
{
WARN_ON_ONCE(cma->nranges != 1);
--
Jean Delvare
SUSE L3 Support
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH RFC 2/2] mm/cma: Consolidate accounting in dedicated functions 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 2025-11-18 1:40 ` 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 2 siblings, 1 reply; 5+ messages in thread From: Jean Delvare @ 2025-11-17 11:15 UTC (permalink / raw) To: linux-mm; +Cc: LKML, David Hildenbrand, Oscar Salvador, SeongJae Park 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH RFC 2/2] mm/cma: Consolidate accounting in dedicated functions 2025-11-17 11:15 ` [PATCH RFC 2/2] mm/cma: Consolidate accounting in dedicated functions Jean Delvare @ 2025-11-18 1:40 ` SeongJae Park 0 siblings, 0 replies; 5+ messages in thread From: SeongJae Park @ 2025-11-18 1:40 UTC (permalink / raw) To: Jean Delvare Cc: SeongJae Park, linux-mm, LKML, David Hildenbrand, Oscar Salvador On Mon, 17 Nov 2025 12:15:02 +0100 Jean Delvare <jdelvare@suse.de> wrote: > Move all accounting to dedicated functions and rename them > accordingly. > > Signed-off-by: Jean Delvare <jdelvare@suse.de> Reviewed-by: SeongJae Park <sj@kernel.org> > --- > 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 [...] > @@ -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); I was thinking we could further move trace_*() function calls to the new functions, but this version also looks good to me. Thanks, SJ [...] ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] mm/cma: Inline cma_sysfs counter hooks 2025-11-17 10:56 [PATCH v2 1/2] mm/cma: Inline cma_sysfs counter hooks Jean Delvare 2025-11-17 11:15 ` [PATCH RFC 2/2] mm/cma: Consolidate accounting in dedicated functions Jean Delvare @ 2025-11-17 11:22 ` David Hildenbrand (Red Hat) 2025-11-18 1:34 ` SeongJae Park 2 siblings, 0 replies; 5+ messages in thread From: David Hildenbrand (Red Hat) @ 2025-11-17 11:22 UTC (permalink / raw) To: Jean Delvare, linux-mm; +Cc: LKML, Oscar Salvador, SeongJae Park On 17.11.25 11:56, Jean Delvare wrote: > Move cma_sysfs counter hooks from cma_sysfs.c to cma.c. These > one-liner functions are only used once each, but the compiler > currently can't inline them because they are defined in one object and > used in another. Letting the compiler inline these functions lowers > the footprint and runtime cost of the sysfs interface to CMA stats > even more. > > Signed-off-by: Jean Delvare <jdelvare@suse.de> > --- I would have moved them to the header, but no strong opinion Acked-by: David Hildenbrand (Red Hat) <david@kernel.org> -- Cheers David ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] mm/cma: Inline cma_sysfs counter hooks 2025-11-17 10:56 [PATCH v2 1/2] mm/cma: Inline cma_sysfs counter hooks Jean Delvare 2025-11-17 11:15 ` [PATCH RFC 2/2] mm/cma: Consolidate accounting in dedicated functions Jean Delvare 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 2 siblings, 0 replies; 5+ messages in thread From: SeongJae Park @ 2025-11-18 1:34 UTC (permalink / raw) To: Jean Delvare Cc: SeongJae Park, linux-mm, LKML, David Hildenbrand, Oscar Salvador On Mon, 17 Nov 2025 11:56:02 +0100 Jean Delvare <jdelvare@suse.de> wrote: > Move cma_sysfs counter hooks from cma_sysfs.c to cma.c. These > one-liner functions are only used once each, but the compiler > currently can't inline them because they are defined in one object and > used in another. Letting the compiler inline these functions lowers > the footprint and runtime cost of the sysfs interface to CMA stats > even more. > > Signed-off-by: Jean Delvare <jdelvare@suse.de> Reviewed-by: SeongJae Park <sj@kernel.org> Thanks, SJ [...] ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-11-18 1:40 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2025-11-17 10:56 [PATCH v2 1/2] mm/cma: Inline cma_sysfs counter hooks Jean Delvare 2025-11-17 11:15 ` [PATCH RFC 2/2] mm/cma: Consolidate accounting in dedicated functions Jean Delvare 2025-11-18 1:40 ` 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
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox