cgroups.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] memcg: manually uninline __memcg_memory_event
@ 2025-10-21 23:44 Shakeel Butt
  2025-10-22  0:58 ` SeongJae Park
  2025-10-23 13:18 ` Michal Hocko
  0 siblings, 2 replies; 9+ messages in thread
From: Shakeel Butt @ 2025-10-21 23:44 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Johannes Weiner, Michal Hocko, Roman Gushchin, Muchun Song,
	linux-mm, cgroups, linux-kernel, Meta kernel team

The function __memcg_memory_event has been unnecessarily marked inline
even when it is not really performance critical. It is usually called
to track extreme conditions. Over the time, it has evolved to include
more functionality and inlining it is causing more harm.

Before the patch:
$ size mm/memcontrol.o net/ipv4/tcp_input.o net/ipv4/tcp_output.o
   text    data     bss     dec     hex filename
  35645   10574    4192   50411    c4eb mm/memcontrol.o
  54738    1658       0   56396    dc4c net/ipv4/tcp_input.o
  34644    1065       0   35709    8b7d net/ipv4/tcp_output.o

After the patch:
$ size mm/memcontrol.o net/ipv4/tcp_input.o net/ipv4/tcp_output.o
   text    data     bss     dec     hex filename
  35137   10446    4192   49775    c26f mm/memcontrol.o
  54322    1562       0   55884    da4c net/ipv4/tcp_input.o
  34492    1017       0   35509    8ab5 net/ipv4/tcp_output.o

Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
---
 include/linux/memcontrol.h | 32 ++------------------------------
 mm/memcontrol.c            | 31 +++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 30 deletions(-)

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index d37e7c93bb8c..8d2e250535a8 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -1002,36 +1002,8 @@ static inline void count_memcg_event_mm(struct mm_struct *mm,
 	count_memcg_events_mm(mm, idx, 1);
 }
 
-static inline void __memcg_memory_event(struct mem_cgroup *memcg,
-					enum memcg_memory_event event,
-					bool allow_spinning)
-{
-	bool swap_event = event == MEMCG_SWAP_HIGH || event == MEMCG_SWAP_MAX ||
-			  event == MEMCG_SWAP_FAIL;
-
-	/* For now only MEMCG_MAX can happen with !allow_spinning context. */
-	VM_WARN_ON_ONCE(!allow_spinning && event != MEMCG_MAX);
-
-	atomic_long_inc(&memcg->memory_events_local[event]);
-	if (!swap_event && allow_spinning)
-		cgroup_file_notify(&memcg->events_local_file);
-
-	do {
-		atomic_long_inc(&memcg->memory_events[event]);
-		if (allow_spinning) {
-			if (swap_event)
-				cgroup_file_notify(&memcg->swap_events_file);
-			else
-				cgroup_file_notify(&memcg->events_file);
-		}
-
-		if (!cgroup_subsys_on_dfl(memory_cgrp_subsys))
-			break;
-		if (cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_LOCAL_EVENTS)
-			break;
-	} while ((memcg = parent_mem_cgroup(memcg)) &&
-		 !mem_cgroup_is_root(memcg));
-}
+void __memcg_memory_event(struct mem_cgroup *memcg,
+			  enum memcg_memory_event event, bool allow_spinning);
 
 static inline void memcg_memory_event(struct mem_cgroup *memcg,
 				      enum memcg_memory_event event)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 1a95049d8b88..93f7c76f0ce9 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1626,6 +1626,37 @@ unsigned long mem_cgroup_size(struct mem_cgroup *memcg)
 	return page_counter_read(&memcg->memory);
 }
 
+void __memcg_memory_event(struct mem_cgroup *memcg,
+			  enum memcg_memory_event event, bool allow_spinning)
+{
+	bool swap_event = event == MEMCG_SWAP_HIGH || event == MEMCG_SWAP_MAX ||
+			  event == MEMCG_SWAP_FAIL;
+
+	/* For now only MEMCG_MAX can happen with !allow_spinning context. */
+	VM_WARN_ON_ONCE(!allow_spinning && event != MEMCG_MAX);
+
+	atomic_long_inc(&memcg->memory_events_local[event]);
+	if (!swap_event && allow_spinning)
+		cgroup_file_notify(&memcg->events_local_file);
+
+	do {
+		atomic_long_inc(&memcg->memory_events[event]);
+		if (allow_spinning) {
+			if (swap_event)
+				cgroup_file_notify(&memcg->swap_events_file);
+			else
+				cgroup_file_notify(&memcg->events_file);
+		}
+
+		if (!cgroup_subsys_on_dfl(memory_cgrp_subsys))
+			break;
+		if (cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_LOCAL_EVENTS)
+			break;
+	} while ((memcg = parent_mem_cgroup(memcg)) &&
+		 !mem_cgroup_is_root(memcg));
+}
+EXPORT_SYMBOL(__memcg_memory_event);
+
 static bool mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask,
 				     int order)
 {
-- 
2.47.3


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

* Re: [PATCH] memcg: manually uninline __memcg_memory_event
  2025-10-21 23:44 [PATCH] memcg: manually uninline __memcg_memory_event Shakeel Butt
@ 2025-10-22  0:58 ` SeongJae Park
  2025-10-22  1:28   ` Shakeel Butt
  2025-10-23 13:18 ` Michal Hocko
  1 sibling, 1 reply; 9+ messages in thread
From: SeongJae Park @ 2025-10-22  0:58 UTC (permalink / raw)
  To: Shakeel Butt
  Cc: SeongJae Park, Andrew Morton, Johannes Weiner, Michal Hocko,
	Roman Gushchin, Muchun Song, linux-mm, cgroups, linux-kernel,
	Meta kernel team

On Tue, 21 Oct 2025 16:44:25 -0700 Shakeel Butt <shakeel.butt@linux.dev> wrote:

> The function __memcg_memory_event has been unnecessarily marked inline
> even when it is not really performance critical. It is usually called
> to track extreme conditions. Over the time, it has evolved to include
> more functionality and inlining it is causing more harm.
> 
> Before the patch:
> $ size mm/memcontrol.o net/ipv4/tcp_input.o net/ipv4/tcp_output.o
>    text    data     bss     dec     hex filename
>   35645   10574    4192   50411    c4eb mm/memcontrol.o
>   54738    1658       0   56396    dc4c net/ipv4/tcp_input.o
>   34644    1065       0   35709    8b7d net/ipv4/tcp_output.o
> 
> After the patch:
> $ size mm/memcontrol.o net/ipv4/tcp_input.o net/ipv4/tcp_output.o
>    text    data     bss     dec     hex filename
>   35137   10446    4192   49775    c26f mm/memcontrol.o
>   54322    1562       0   55884    da4c net/ipv4/tcp_input.o
>   34492    1017       0   35509    8ab5 net/ipv4/tcp_output.o
> 
> Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
> ---
>  include/linux/memcontrol.h | 32 ++------------------------------
>  mm/memcontrol.c            | 31 +++++++++++++++++++++++++++++++
>  2 files changed, 33 insertions(+), 30 deletions(-)
> 
> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index d37e7c93bb8c..8d2e250535a8 100644
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -1002,36 +1002,8 @@ static inline void count_memcg_event_mm(struct mm_struct *mm,
>  	count_memcg_events_mm(mm, idx, 1);
>  }
>  
> -static inline void __memcg_memory_event(struct mem_cgroup *memcg,
> -					enum memcg_memory_event event,
> -					bool allow_spinning)
> -{
> -	bool swap_event = event == MEMCG_SWAP_HIGH || event == MEMCG_SWAP_MAX ||
> -			  event == MEMCG_SWAP_FAIL;
> -
> -	/* For now only MEMCG_MAX can happen with !allow_spinning context. */
> -	VM_WARN_ON_ONCE(!allow_spinning && event != MEMCG_MAX);
> -
> -	atomic_long_inc(&memcg->memory_events_local[event]);
> -	if (!swap_event && allow_spinning)
> -		cgroup_file_notify(&memcg->events_local_file);
> -
> -	do {
> -		atomic_long_inc(&memcg->memory_events[event]);
> -		if (allow_spinning) {
> -			if (swap_event)
> -				cgroup_file_notify(&memcg->swap_events_file);
> -			else
> -				cgroup_file_notify(&memcg->events_file);
> -		}
> -
> -		if (!cgroup_subsys_on_dfl(memory_cgrp_subsys))
> -			break;
> -		if (cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_LOCAL_EVENTS)
> -			break;
> -	} while ((memcg = parent_mem_cgroup(memcg)) &&
> -		 !mem_cgroup_is_root(memcg));
> -}
> +void __memcg_memory_event(struct mem_cgroup *memcg,
> +			  enum memcg_memory_event event, bool allow_spinning);
>  
>  static inline void memcg_memory_event(struct mem_cgroup *memcg,
>  				      enum memcg_memory_event event)
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 1a95049d8b88..93f7c76f0ce9 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -1626,6 +1626,37 @@ unsigned long mem_cgroup_size(struct mem_cgroup *memcg)
>  	return page_counter_read(&memcg->memory);
>  }
>  
> +void __memcg_memory_event(struct mem_cgroup *memcg,
> +			  enum memcg_memory_event event, bool allow_spinning)

Seems this function is called only from memcontrol.c.  Why not making it a
static function?

> +{
> +	bool swap_event = event == MEMCG_SWAP_HIGH || event == MEMCG_SWAP_MAX ||
> +			  event == MEMCG_SWAP_FAIL;
> +
> +	/* For now only MEMCG_MAX can happen with !allow_spinning context. */
> +	VM_WARN_ON_ONCE(!allow_spinning && event != MEMCG_MAX);
> +
> +	atomic_long_inc(&memcg->memory_events_local[event]);
> +	if (!swap_event && allow_spinning)
> +		cgroup_file_notify(&memcg->events_local_file);
> +
> +	do {
> +		atomic_long_inc(&memcg->memory_events[event]);
> +		if (allow_spinning) {
> +			if (swap_event)
> +				cgroup_file_notify(&memcg->swap_events_file);
> +			else
> +				cgroup_file_notify(&memcg->events_file);
> +		}
> +
> +		if (!cgroup_subsys_on_dfl(memory_cgrp_subsys))
> +			break;
> +		if (cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_LOCAL_EVENTS)
> +			break;
> +	} while ((memcg = parent_mem_cgroup(memcg)) &&
> +		 !mem_cgroup_is_root(memcg));
> +}
> +EXPORT_SYMBOL(__memcg_memory_event);

Also, seems there is no reason to export this symbol?


Thanks,
SJ

[...]

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

* Re: [PATCH] memcg: manually uninline __memcg_memory_event
  2025-10-22  0:58 ` SeongJae Park
@ 2025-10-22  1:28   ` Shakeel Butt
  2025-10-22  2:15     ` SeongJae Park
  2025-10-22 18:10     ` Roman Gushchin
  0 siblings, 2 replies; 9+ messages in thread
From: Shakeel Butt @ 2025-10-22  1:28 UTC (permalink / raw)
  To: SeongJae Park
  Cc: Andrew Morton, Johannes Weiner, Michal Hocko, Roman Gushchin,
	Muchun Song, linux-mm, cgroups, linux-kernel, Meta kernel team

On Tue, Oct 21, 2025 at 05:58:00PM -0700, SeongJae Park wrote:
> On Tue, 21 Oct 2025 16:44:25 -0700 Shakeel Butt <shakeel.butt@linux.dev> wrote:
> 
> > The function __memcg_memory_event has been unnecessarily marked inline
> > even when it is not really performance critical. It is usually called
> > to track extreme conditions. Over the time, it has evolved to include
> > more functionality and inlining it is causing more harm.
> > 
> > Before the patch:
> > $ size mm/memcontrol.o net/ipv4/tcp_input.o net/ipv4/tcp_output.o
> >    text    data     bss     dec     hex filename
> >   35645   10574    4192   50411    c4eb mm/memcontrol.o
> >   54738    1658       0   56396    dc4c net/ipv4/tcp_input.o
> >   34644    1065       0   35709    8b7d net/ipv4/tcp_output.o
> > 
> > After the patch:
> > $ size mm/memcontrol.o net/ipv4/tcp_input.o net/ipv4/tcp_output.o
> >    text    data     bss     dec     hex filename
> >   35137   10446    4192   49775    c26f mm/memcontrol.o
> >   54322    1562       0   55884    da4c net/ipv4/tcp_input.o
> >   34492    1017       0   35509    8ab5 net/ipv4/tcp_output.o
> > 
> > Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
> > ---
> >  include/linux/memcontrol.h | 32 ++------------------------------
> >  mm/memcontrol.c            | 31 +++++++++++++++++++++++++++++++
> >  2 files changed, 33 insertions(+), 30 deletions(-)
> > 
> > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> > index d37e7c93bb8c..8d2e250535a8 100644
> > --- a/include/linux/memcontrol.h
> > +++ b/include/linux/memcontrol.h
> > @@ -1002,36 +1002,8 @@ static inline void count_memcg_event_mm(struct mm_struct *mm,
> >  	count_memcg_events_mm(mm, idx, 1);
> >  }
> >  
> > -static inline void __memcg_memory_event(struct mem_cgroup *memcg,
> > -					enum memcg_memory_event event,
> > -					bool allow_spinning)
> > -{
> > -	bool swap_event = event == MEMCG_SWAP_HIGH || event == MEMCG_SWAP_MAX ||
> > -			  event == MEMCG_SWAP_FAIL;
> > -
> > -	/* For now only MEMCG_MAX can happen with !allow_spinning context. */
> > -	VM_WARN_ON_ONCE(!allow_spinning && event != MEMCG_MAX);
> > -
> > -	atomic_long_inc(&memcg->memory_events_local[event]);
> > -	if (!swap_event && allow_spinning)
> > -		cgroup_file_notify(&memcg->events_local_file);
> > -
> > -	do {
> > -		atomic_long_inc(&memcg->memory_events[event]);
> > -		if (allow_spinning) {
> > -			if (swap_event)
> > -				cgroup_file_notify(&memcg->swap_events_file);
> > -			else
> > -				cgroup_file_notify(&memcg->events_file);
> > -		}
> > -
> > -		if (!cgroup_subsys_on_dfl(memory_cgrp_subsys))
> > -			break;
> > -		if (cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_LOCAL_EVENTS)
> > -			break;
> > -	} while ((memcg = parent_mem_cgroup(memcg)) &&
> > -		 !mem_cgroup_is_root(memcg));
> > -}
> > +void __memcg_memory_event(struct mem_cgroup *memcg,
> > +			  enum memcg_memory_event event, bool allow_spinning);
> >  
> >  static inline void memcg_memory_event(struct mem_cgroup *memcg,
> >  				      enum memcg_memory_event event)
> > diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> > index 1a95049d8b88..93f7c76f0ce9 100644
> > --- a/mm/memcontrol.c
> > +++ b/mm/memcontrol.c
> > @@ -1626,6 +1626,37 @@ unsigned long mem_cgroup_size(struct mem_cgroup *memcg)
> >  	return page_counter_read(&memcg->memory);
> >  }
> >  
> > +void __memcg_memory_event(struct mem_cgroup *memcg,
> > +			  enum memcg_memory_event event, bool allow_spinning)
> 
> Seems this function is called only from memcontrol.c.  Why not making it a
> static function?

There is a recent code where this is called (indirectly) from networking
stack for MEMCG_SOCK_THROTTLED.

> 
> > +{
> > +	bool swap_event = event == MEMCG_SWAP_HIGH || event == MEMCG_SWAP_MAX ||
> > +			  event == MEMCG_SWAP_FAIL;
> > +
> > +	/* For now only MEMCG_MAX can happen with !allow_spinning context. */
> > +	VM_WARN_ON_ONCE(!allow_spinning && event != MEMCG_MAX);
> > +
> > +	atomic_long_inc(&memcg->memory_events_local[event]);
> > +	if (!swap_event && allow_spinning)
> > +		cgroup_file_notify(&memcg->events_local_file);
> > +
> > +	do {
> > +		atomic_long_inc(&memcg->memory_events[event]);
> > +		if (allow_spinning) {
> > +			if (swap_event)
> > +				cgroup_file_notify(&memcg->swap_events_file);
> > +			else
> > +				cgroup_file_notify(&memcg->events_file);
> > +		}
> > +
> > +		if (!cgroup_subsys_on_dfl(memory_cgrp_subsys))
> > +			break;
> > +		if (cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_LOCAL_EVENTS)
> > +			break;
> > +	} while ((memcg = parent_mem_cgroup(memcg)) &&
> > +		 !mem_cgroup_is_root(memcg));
> > +}
> > +EXPORT_SYMBOL(__memcg_memory_event);
> 
> Also, seems there is no reason to export this symbol?

The networking code needs this export.

Thanks for taking a look.

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

* Re: [PATCH] memcg: manually uninline __memcg_memory_event
  2025-10-22  1:28   ` Shakeel Butt
@ 2025-10-22  2:15     ` SeongJae Park
  2025-10-22 18:10     ` Roman Gushchin
  1 sibling, 0 replies; 9+ messages in thread
From: SeongJae Park @ 2025-10-22  2:15 UTC (permalink / raw)
  To: Shakeel Butt
  Cc: SeongJae Park, Andrew Morton, Johannes Weiner, Michal Hocko,
	Roman Gushchin, Muchun Song, linux-mm, cgroups, linux-kernel,
	Meta kernel team

On Tue, 21 Oct 2025 18:28:02 -0700 Shakeel Butt <shakeel.butt@linux.dev> wrote:

> On Tue, Oct 21, 2025 at 05:58:00PM -0700, SeongJae Park wrote:
> > On Tue, 21 Oct 2025 16:44:25 -0700 Shakeel Butt <shakeel.butt@linux.dev> wrote:
> > 
> > > The function __memcg_memory_event has been unnecessarily marked inline
> > > even when it is not really performance critical. It is usually called
> > > to track extreme conditions. Over the time, it has evolved to include
> > > more functionality and inlining it is causing more harm.
> > > 
> > > Before the patch:
> > > $ size mm/memcontrol.o net/ipv4/tcp_input.o net/ipv4/tcp_output.o
> > >    text    data     bss     dec     hex filename
> > >   35645   10574    4192   50411    c4eb mm/memcontrol.o
> > >   54738    1658       0   56396    dc4c net/ipv4/tcp_input.o
> > >   34644    1065       0   35709    8b7d net/ipv4/tcp_output.o
> > > 
> > > After the patch:
> > > $ size mm/memcontrol.o net/ipv4/tcp_input.o net/ipv4/tcp_output.o
> > >    text    data     bss     dec     hex filename
> > >   35137   10446    4192   49775    c26f mm/memcontrol.o
> > >   54322    1562       0   55884    da4c net/ipv4/tcp_input.o
> > >   34492    1017       0   35509    8ab5 net/ipv4/tcp_output.o
> > > 
> > > Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
> > > ---
> > >  include/linux/memcontrol.h | 32 ++------------------------------
> > >  mm/memcontrol.c            | 31 +++++++++++++++++++++++++++++++
> > >  2 files changed, 33 insertions(+), 30 deletions(-)
> > > 
> > > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> > > index d37e7c93bb8c..8d2e250535a8 100644
> > > --- a/include/linux/memcontrol.h
> > > +++ b/include/linux/memcontrol.h
> > > @@ -1002,36 +1002,8 @@ static inline void count_memcg_event_mm(struct mm_struct *mm,
> > >  	count_memcg_events_mm(mm, idx, 1);
> > >  }
> > >  
> > > -static inline void __memcg_memory_event(struct mem_cgroup *memcg,
> > > -					enum memcg_memory_event event,
> > > -					bool allow_spinning)
> > > -{
> > > -	bool swap_event = event == MEMCG_SWAP_HIGH || event == MEMCG_SWAP_MAX ||
> > > -			  event == MEMCG_SWAP_FAIL;
> > > -
> > > -	/* For now only MEMCG_MAX can happen with !allow_spinning context. */
> > > -	VM_WARN_ON_ONCE(!allow_spinning && event != MEMCG_MAX);
> > > -
> > > -	atomic_long_inc(&memcg->memory_events_local[event]);
> > > -	if (!swap_event && allow_spinning)
> > > -		cgroup_file_notify(&memcg->events_local_file);
> > > -
> > > -	do {
> > > -		atomic_long_inc(&memcg->memory_events[event]);
> > > -		if (allow_spinning) {
> > > -			if (swap_event)
> > > -				cgroup_file_notify(&memcg->swap_events_file);
> > > -			else
> > > -				cgroup_file_notify(&memcg->events_file);
> > > -		}
> > > -
> > > -		if (!cgroup_subsys_on_dfl(memory_cgrp_subsys))
> > > -			break;
> > > -		if (cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_LOCAL_EVENTS)
> > > -			break;
> > > -	} while ((memcg = parent_mem_cgroup(memcg)) &&
> > > -		 !mem_cgroup_is_root(memcg));
> > > -}
> > > +void __memcg_memory_event(struct mem_cgroup *memcg,
> > > +			  enum memcg_memory_event event, bool allow_spinning);
> > >  
> > >  static inline void memcg_memory_event(struct mem_cgroup *memcg,
> > >  				      enum memcg_memory_event event)
> > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> > > index 1a95049d8b88..93f7c76f0ce9 100644
> > > --- a/mm/memcontrol.c
> > > +++ b/mm/memcontrol.c
> > > @@ -1626,6 +1626,37 @@ unsigned long mem_cgroup_size(struct mem_cgroup *memcg)
> > >  	return page_counter_read(&memcg->memory);
> > >  }
> > >  
> > > +void __memcg_memory_event(struct mem_cgroup *memcg,
> > > +			  enum memcg_memory_event event, bool allow_spinning)
> > 
> > Seems this function is called only from memcontrol.c.  Why not making it a
> > static function?
> 
> There is a recent code where this is called (indirectly) from networking
> stack for MEMCG_SOCK_THROTTLED.

Thank you for enlightening me.  Apparently the code is from
https://lore.kernel.org/20251016161035.86161-1-shakeel.butt@linux.dev.

> 
> > 
> > > +{
> > > +	bool swap_event = event == MEMCG_SWAP_HIGH || event == MEMCG_SWAP_MAX ||
> > > +			  event == MEMCG_SWAP_FAIL;
> > > +
> > > +	/* For now only MEMCG_MAX can happen with !allow_spinning context. */
> > > +	VM_WARN_ON_ONCE(!allow_spinning && event != MEMCG_MAX);
> > > +
> > > +	atomic_long_inc(&memcg->memory_events_local[event]);
> > > +	if (!swap_event && allow_spinning)
> > > +		cgroup_file_notify(&memcg->events_local_file);
> > > +
> > > +	do {
> > > +		atomic_long_inc(&memcg->memory_events[event]);
> > > +		if (allow_spinning) {
> > > +			if (swap_event)
> > > +				cgroup_file_notify(&memcg->swap_events_file);
> > > +			else
> > > +				cgroup_file_notify(&memcg->events_file);
> > > +		}
> > > +
> > > +		if (!cgroup_subsys_on_dfl(memory_cgrp_subsys))
> > > +			break;
> > > +		if (cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_LOCAL_EVENTS)
> > > +			break;
> > > +	} while ((memcg = parent_mem_cgroup(memcg)) &&
> > > +		 !mem_cgroup_is_root(memcg));
> > > +}
> > > +EXPORT_SYMBOL(__memcg_memory_event);
> > 
> > Also, seems there is no reason to export this symbol?
> 
> The networking code needs this export.
> 
> Thanks for taking a look.

Again, thank you for clarifying.

Acked-by: SeongJae Park <sj@kernel.org>


Thanks,
SJ

[...]

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

* Re: [PATCH] memcg: manually uninline __memcg_memory_event
  2025-10-22  1:28   ` Shakeel Butt
  2025-10-22  2:15     ` SeongJae Park
@ 2025-10-22 18:10     ` Roman Gushchin
  1 sibling, 0 replies; 9+ messages in thread
From: Roman Gushchin @ 2025-10-22 18:10 UTC (permalink / raw)
  To: Shakeel Butt
  Cc: SeongJae Park, Andrew Morton, Johannes Weiner, Michal Hocko,
	Muchun Song, linux-mm, cgroups, linux-kernel, Meta kernel team

Shakeel Butt <shakeel.butt@linux.dev> writes:

> On Tue, Oct 21, 2025 at 05:58:00PM -0700, SeongJae Park wrote:
>> On Tue, 21 Oct 2025 16:44:25 -0700 Shakeel Butt <shakeel.butt@linux.dev> wrote:
>> 
>> > The function __memcg_memory_event has been unnecessarily marked inline
>> > even when it is not really performance critical. It is usually called
>> > to track extreme conditions. Over the time, it has evolved to include
>> > more functionality and inlining it is causing more harm.
>> > 
>> > Before the patch:
>> > $ size mm/memcontrol.o net/ipv4/tcp_input.o net/ipv4/tcp_output.o
>> >    text    data     bss     dec     hex filename
>> >   35645   10574    4192   50411    c4eb mm/memcontrol.o
>> >   54738    1658       0   56396    dc4c net/ipv4/tcp_input.o
>> >   34644    1065       0   35709    8b7d net/ipv4/tcp_output.o
>> > 
>> > After the patch:
>> > $ size mm/memcontrol.o net/ipv4/tcp_input.o net/ipv4/tcp_output.o
>> >    text    data     bss     dec     hex filename
>> >   35137   10446    4192   49775    c26f mm/memcontrol.o
>> >   54322    1562       0   55884    da4c net/ipv4/tcp_input.o
>> >   34492    1017       0   35509    8ab5 net/ipv4/tcp_output.o
>> > 
>> > Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>

Acked-by: Roman Gushchin <roman.gushchin@linux.dev>

Thanks!

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

* Re: [PATCH] memcg: manually uninline __memcg_memory_event
  2025-10-21 23:44 [PATCH] memcg: manually uninline __memcg_memory_event Shakeel Butt
  2025-10-22  0:58 ` SeongJae Park
@ 2025-10-23 13:18 ` Michal Hocko
  2025-10-23 21:35   ` Shakeel Butt
  2025-10-27  7:19   ` Christoph Hellwig
  1 sibling, 2 replies; 9+ messages in thread
From: Michal Hocko @ 2025-10-23 13:18 UTC (permalink / raw)
  To: Shakeel Butt
  Cc: Andrew Morton, Johannes Weiner, Roman Gushchin, Muchun Song,
	linux-mm, cgroups, linux-kernel, Meta kernel team

On Tue 21-10-25 16:44:25, Shakeel Butt wrote:
> The function __memcg_memory_event has been unnecessarily marked inline
> even when it is not really performance critical. It is usually called
> to track extreme conditions. Over the time, it has evolved to include
> more functionality and inlining it is causing more harm.
> 
> Before the patch:
> $ size mm/memcontrol.o net/ipv4/tcp_input.o net/ipv4/tcp_output.o
>    text    data     bss     dec     hex filename
>   35645   10574    4192   50411    c4eb mm/memcontrol.o
>   54738    1658       0   56396    dc4c net/ipv4/tcp_input.o
>   34644    1065       0   35709    8b7d net/ipv4/tcp_output.o
> 
> After the patch:
> $ size mm/memcontrol.o net/ipv4/tcp_input.o net/ipv4/tcp_output.o
>    text    data     bss     dec     hex filename
>   35137   10446    4192   49775    c26f mm/memcontrol.o
>   54322    1562       0   55884    da4c net/ipv4/tcp_input.o
>   34492    1017       0   35509    8ab5 net/ipv4/tcp_output.o
> 
> Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>

Acked-by: Michal Hocko <mhocko@suse.com>

As the only user is in tree should we make that EXPORT_SYMBOL_GPL
instead?

-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH] memcg: manually uninline __memcg_memory_event
  2025-10-23 13:18 ` Michal Hocko
@ 2025-10-23 21:35   ` Shakeel Butt
  2025-10-24  6:50     ` Michal Hocko
  2025-10-27  7:19   ` Christoph Hellwig
  1 sibling, 1 reply; 9+ messages in thread
From: Shakeel Butt @ 2025-10-23 21:35 UTC (permalink / raw)
  To: Michal Hocko
  Cc: Andrew Morton, Johannes Weiner, Roman Gushchin, Muchun Song,
	linux-mm, cgroups, linux-kernel, Meta kernel team

On Thu, Oct 23, 2025 at 03:18:14PM +0200, Michal Hocko wrote:
> On Tue 21-10-25 16:44:25, Shakeel Butt wrote:
> > The function __memcg_memory_event has been unnecessarily marked inline
> > even when it is not really performance critical. It is usually called
> > to track extreme conditions. Over the time, it has evolved to include
> > more functionality and inlining it is causing more harm.
> > 
> > Before the patch:
> > $ size mm/memcontrol.o net/ipv4/tcp_input.o net/ipv4/tcp_output.o
> >    text    data     bss     dec     hex filename
> >   35645   10574    4192   50411    c4eb mm/memcontrol.o
> >   54738    1658       0   56396    dc4c net/ipv4/tcp_input.o
> >   34644    1065       0   35709    8b7d net/ipv4/tcp_output.o
> > 
> > After the patch:
> > $ size mm/memcontrol.o net/ipv4/tcp_input.o net/ipv4/tcp_output.o
> >    text    data     bss     dec     hex filename
> >   35137   10446    4192   49775    c26f mm/memcontrol.o
> >   54322    1562       0   55884    da4c net/ipv4/tcp_input.o
> >   34492    1017       0   35509    8ab5 net/ipv4/tcp_output.o
> > 
> > Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
> 
> Acked-by: Michal Hocko <mhocko@suse.com>

Thanks.

> 
> As the only user is in tree should we make that EXPORT_SYMBOL_GPL
> instead?

I just followed the file convention i.e. all other exports in
memcontrol.c are like that. I would keep this as is unless you have
strong opinion otherwise.

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

* Re: [PATCH] memcg: manually uninline __memcg_memory_event
  2025-10-23 21:35   ` Shakeel Butt
@ 2025-10-24  6:50     ` Michal Hocko
  0 siblings, 0 replies; 9+ messages in thread
From: Michal Hocko @ 2025-10-24  6:50 UTC (permalink / raw)
  To: Shakeel Butt
  Cc: Andrew Morton, Johannes Weiner, Roman Gushchin, Muchun Song,
	linux-mm, cgroups, linux-kernel, Meta kernel team

On Thu 23-10-25 14:35:05, Shakeel Butt wrote:
> On Thu, Oct 23, 2025 at 03:18:14PM +0200, Michal Hocko wrote:
[...]
> > As the only user is in tree should we make that EXPORT_SYMBOL_GPL
> > instead?
> 
> I just followed the file convention i.e. all other exports in
> memcontrol.c are like that. I would keep this as is unless you have
> strong opinion otherwise.

OK

-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH] memcg: manually uninline __memcg_memory_event
  2025-10-23 13:18 ` Michal Hocko
  2025-10-23 21:35   ` Shakeel Butt
@ 2025-10-27  7:19   ` Christoph Hellwig
  1 sibling, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2025-10-27  7:19 UTC (permalink / raw)
  To: Michal Hocko
  Cc: Shakeel Butt, Andrew Morton, Johannes Weiner, Roman Gushchin,
	Muchun Song, linux-mm, cgroups, linux-kernel, Meta kernel team

On Thu, Oct 23, 2025 at 03:18:14PM +0200, Michal Hocko wrote:
> As the only user is in tree should we make that EXPORT_SYMBOL_GPL
> instead?

Yes.


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

end of thread, other threads:[~2025-10-27  7:19 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-21 23:44 [PATCH] memcg: manually uninline __memcg_memory_event Shakeel Butt
2025-10-22  0:58 ` SeongJae Park
2025-10-22  1:28   ` Shakeel Butt
2025-10-22  2:15     ` SeongJae Park
2025-10-22 18:10     ` Roman Gushchin
2025-10-23 13:18 ` Michal Hocko
2025-10-23 21:35   ` Shakeel Butt
2025-10-24  6:50     ` Michal Hocko
2025-10-27  7:19   ` Christoph Hellwig

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).