* [RFC PATCH] mm/cma: Inline cma_sysfs counter hooks
@ 2025-11-14 10:03 Jean Delvare
2025-11-15 1:48 ` SeongJae Park
0 siblings, 1 reply; 3+ messages in thread
From: Jean Delvare @ 2025-11-14 10:03 UTC (permalink / raw)
To: linux-mm; +Cc: LKML, David Hildenbrand, Oscar Salvador
Move cma_sysfs counter hooks from cma_sysfs.c to inline functions in
cma.h. 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>
---
Applies on top of my previous patch due to a context change, but
otherwise independent thereof.
On second thought, we might as well move these functions to cma.c as
this is the only place where they are called, so it's hard to justify
why they should be in a header file. Opinions?
mm/cma.h | 20 +++++++++++++++++---
mm/cma_sysfs.c | 15 ---------------
2 files changed, 17 insertions(+), 18 deletions(-)
--- linux-6.17.orig/mm/cma.h
+++ linux-6.17/mm/cma.h
@@ -81,9 +81,23 @@ static inline unsigned long cma_bitmap_m
}
#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);
+static inline void cma_sysfs_account_success_pages(struct cma *cma,
+ unsigned long nr_pages)
+{
+ atomic64_add(nr_pages, &cma->nr_pages_succeeded);
+}
+
+static inline void cma_sysfs_account_fail_pages(struct cma *cma,
+ unsigned long nr_pages)
+{
+ atomic64_add(nr_pages, &cma->nr_pages_failed);
+}
+
+static inline void cma_sysfs_account_release_pages(struct cma *cma,
+ unsigned long nr_pages)
+{
+ atomic64_add(nr_pages, &cma->nr_pages_released);
+}
#else
static inline void cma_sysfs_account_success_pages(struct cma *cma,
unsigned long nr_pages) {};
--- 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;
--
Jean Delvare
SUSE L3 Support
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [RFC PATCH] mm/cma: Inline cma_sysfs counter hooks
2025-11-14 10:03 [RFC PATCH] mm/cma: Inline cma_sysfs counter hooks Jean Delvare
@ 2025-11-15 1:48 ` SeongJae Park
2025-11-17 10:49 ` Jean Delvare
0 siblings, 1 reply; 3+ messages in thread
From: SeongJae Park @ 2025-11-15 1:48 UTC (permalink / raw)
To: Jean Delvare
Cc: SeongJae Park, linux-mm, LKML, David Hildenbrand, Oscar Salvador
On Fri, 14 Nov 2025 11:03:01 +0100 Jean Delvare <jdelvare@suse.de> wrote:
> Move cma_sysfs counter hooks from cma_sysfs.c to inline functions in
> cma.h. 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>
Acked-by: SeongJae Park <sj@kernel.org>
> ---
> Applies on top of my previous patch due to a context change, but
> otherwise independent thereof.
>
> On second thought, we might as well move these functions to cma.c as
> this is the only place where they are called, so it's hard to justify
> why they should be in a header file. Opinions?
I think that should also be nice. In the case, I think it can drop 'inline'
keyword to let the compiler makes good decisions with its nice knowledge. Also
the similar event accounting code such as count_vm_event() and trace_*() calls
can be moved into the new function together. If do so, the function name may
also better to be updated to represent it is not only for cma sysfs but general
events accounting. Just my two cents.
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFC PATCH] mm/cma: Inline cma_sysfs counter hooks
2025-11-15 1:48 ` SeongJae Park
@ 2025-11-17 10:49 ` Jean Delvare
0 siblings, 0 replies; 3+ messages in thread
From: Jean Delvare @ 2025-11-17 10:49 UTC (permalink / raw)
To: SeongJae Park; +Cc: linux-mm, LKML, David Hildenbrand, Oscar Salvador
Hi SeongJae,
On Fri, 14 Nov 2025 17:48:09 -0800, SeongJae Park wrote:
> On Fri, 14 Nov 2025 11:03:01 +0100 Jean Delvare <jdelvare@suse.de> wrote:
> > On second thought, we might as well move these functions to cma.c as
> > this is the only place where they are called, so it's hard to justify
> > why they should be in a header file. Opinions?
>
> I think that should also be nice. In the case, I think it can drop 'inline'
> keyword to let the compiler makes good decisions with its nice knowledge. Also
> the similar event accounting code such as count_vm_event() and trace_*() calls
> can be moved into the new function together. If do so, the function name may
> also better to be updated to represent it is not only for cma sysfs but general
> events accounting. Just my two cents.
Thanks for your feedback. I have prepared an alternative patch which
moves the code to cma.c, I'll post it shortly.
I also experimented with your idea of consolidating accounting. I'm not
totally sold to the idea though, structurally it's nicer, but it implies
scattering the ifdef SYSFS across all 3 accounting functions, which not
everybody may like. I'm really not sure which I prefer. I'll post it
and let the maintainers decide.
--
Jean Delvare
SUSE L3 Support
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-11-17 10:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-14 10:03 [RFC PATCH] mm/cma: Inline cma_sysfs counter hooks Jean Delvare
2025-11-15 1:48 ` SeongJae Park
2025-11-17 10:49 ` Jean Delvare
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox