linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: introduce entrance for root_mem_cgroup's current
@ 2023-02-02  4:32 zhaoyang.huang
  2023-02-02  6:30 ` Shakeel Butt
  2023-02-02  8:27 ` Michal Hocko
  0 siblings, 2 replies; 8+ messages in thread
From: zhaoyang.huang @ 2023-02-02  4:32 UTC (permalink / raw)
  To: Andrew Morton, Johannes Weiner, Peter Zijlstra, Michal Hocko,
	Roman Gushchin, Shakeel Butt, linux-mm, linux-kernel, cgroups,
	Zhaoyang Huang, ke.wang

From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>

Introducing memory.root_current for the memory charges on root_mem_cgroup.

Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
---
 mm/memcontrol.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index ab457f0..158d4232 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -6681,6 +6681,11 @@ static ssize_t memory_reclaim(struct kernfs_open_file *of, char *buf,
 
 static struct cftype memory_files[] = {
 	{
+		.name = "root_current",
+		.flags = CFTYPE_ONLY_ON_ROOT,
+		.read_u64 = memory_current_read,
+	},
+	{
 		.name = "current",
 		.flags = CFTYPE_NOT_ON_ROOT,
 		.read_u64 = memory_current_read,
-- 
1.9.1


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

* Re: [PATCH] mm: introduce entrance for root_mem_cgroup's current
  2023-02-02  4:32 [PATCH] mm: introduce entrance for root_mem_cgroup's current zhaoyang.huang
@ 2023-02-02  6:30 ` Shakeel Butt
  2023-02-02  6:36   ` Zhaoyang Huang
  2023-02-02  8:27 ` Michal Hocko
  1 sibling, 1 reply; 8+ messages in thread
From: Shakeel Butt @ 2023-02-02  6:30 UTC (permalink / raw)
  To: zhaoyang.huang
  Cc: Andrew Morton, Johannes Weiner, Peter Zijlstra, Michal Hocko,
	Roman Gushchin, linux-mm, linux-kernel, cgroups, Zhaoyang Huang,
	ke.wang

On Wed, Feb 1, 2023 at 8:34 PM zhaoyang.huang <zhaoyang.huang@unisoc.com> wrote:
>
> From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
>
> Introducing memory.root_current for the memory charges on root_mem_cgroup.

Why and how are you planning to use it?

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

* Re: [PATCH] mm: introduce entrance for root_mem_cgroup's current
  2023-02-02  6:30 ` Shakeel Butt
@ 2023-02-02  6:36   ` Zhaoyang Huang
  0 siblings, 0 replies; 8+ messages in thread
From: Zhaoyang Huang @ 2023-02-02  6:36 UTC (permalink / raw)
  To: Shakeel Butt
  Cc: zhaoyang.huang, Andrew Morton, Johannes Weiner, Peter Zijlstra,
	Michal Hocko, Roman Gushchin, linux-mm, linux-kernel, cgroups,
	ke.wang

On Thu, Feb 2, 2023 at 2:30 PM Shakeel Butt <shakeelb@google.com> wrote:
>
> On Wed, Feb 1, 2023 at 8:34 PM zhaoyang.huang <zhaoyang.huang@unisoc.com> wrote:
> >
> > From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> >
> > Introducing memory.root_current for the memory charges on root_mem_cgroup.
>
> Why and how are you planning to use it?
root_mem_cgroup is lack of such statistic entry for debug purpose,
which is the counterpart of memory.current within other memcgs

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

* Re: [PATCH] mm: introduce entrance for root_mem_cgroup's current
  2023-02-02  4:32 [PATCH] mm: introduce entrance for root_mem_cgroup's current zhaoyang.huang
  2023-02-02  6:30 ` Shakeel Butt
@ 2023-02-02  8:27 ` Michal Hocko
  2023-02-02 18:24   ` Shakeel Butt
  2023-02-03 17:42   ` Roman Gushchin
  1 sibling, 2 replies; 8+ messages in thread
From: Michal Hocko @ 2023-02-02  8:27 UTC (permalink / raw)
  To: zhaoyang.huang
  Cc: Andrew Morton, Johannes Weiner, Peter Zijlstra, Roman Gushchin,
	Shakeel Butt, linux-mm, linux-kernel, cgroups, Zhaoyang Huang,
	ke.wang

On Thu 02-02-23 12:32:57, zhaoyang.huang wrote:
> From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> 
> Introducing memory.root_current for the memory charges on root_mem_cgroup.

Charges are not currently accounted for the root memcg universally. See
try_charge which is used for all user space and skmem charges. I am not
100% sure about objcg based accounting because there is no explicit
check for the root memcg but this might be hidden somewhere as well.

That means that the patch as is doesn't really provide and usable value.
The root exemption has been removed in the past but that has been
reverted due to a regression. See ce00a967377b ("mm: memcontrol: revert
use of root_mem_cgroup res_counter") for more.

> Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> ---
>  mm/memcontrol.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index ab457f0..158d4232 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -6681,6 +6681,11 @@ static ssize_t memory_reclaim(struct kernfs_open_file *of, char *buf,
>  
>  static struct cftype memory_files[] = {
>  	{
> +		.name = "root_current",
> +		.flags = CFTYPE_ONLY_ON_ROOT,
> +		.read_u64 = memory_current_read,
> +	},
> +	{
>  		.name = "current",
>  		.flags = CFTYPE_NOT_ON_ROOT,
>  		.read_u64 = memory_current_read,
> -- 
> 1.9.1

-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH] mm: introduce entrance for root_mem_cgroup's current
  2023-02-02  8:27 ` Michal Hocko
@ 2023-02-02 18:24   ` Shakeel Butt
  2023-02-03  8:58     ` Michal Hocko
  2023-02-03 17:42   ` Roman Gushchin
  1 sibling, 1 reply; 8+ messages in thread
From: Shakeel Butt @ 2023-02-02 18:24 UTC (permalink / raw)
  To: Michal Hocko
  Cc: zhaoyang.huang, Andrew Morton, Johannes Weiner, Peter Zijlstra,
	Roman Gushchin, linux-mm, linux-kernel, cgroups, Zhaoyang Huang,
	ke.wang

On Thu, Feb 2, 2023 at 12:27 AM Michal Hocko <mhocko@suse.com> wrote:
>
> On Thu 02-02-23 12:32:57, zhaoyang.huang wrote:
> > From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> >
> > Introducing memory.root_current for the memory charges on root_mem_cgroup.
>
> Charges are not currently accounted for the root memcg universally. See
> try_charge which is used for all user space and skmem charges. I am not
> 100% sure about objcg based accounting because there is no explicit
> check for the root memcg but this might be hidden somewhere as well.

Yes in __get_obj_cgroup_from_memcg(). However the reason to use
try_charge_memcg() to bypass root check was to avoid the race with
reparenting. More details in c5c8b16b596e ("mm: memcontrol: fix
root_mem_cgroup charging").

>
> That means that the patch as is doesn't really provide and usable value.
> The root exemption has been removed in the past but that has been
> reverted due to a regression. See ce00a967377b ("mm: memcontrol: revert
> use of root_mem_cgroup res_counter") for more.
>

One advantage I can see is if someone is looking for usage for all top
containers (alive or zombie) but I wanted to know if that was the real
motivation behind the patch.

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

* Re: [PATCH] mm: introduce entrance for root_mem_cgroup's current
  2023-02-02 18:24   ` Shakeel Butt
@ 2023-02-03  8:58     ` Michal Hocko
  2023-02-03 19:18       ` Shakeel Butt
  0 siblings, 1 reply; 8+ messages in thread
From: Michal Hocko @ 2023-02-03  8:58 UTC (permalink / raw)
  To: Shakeel Butt
  Cc: zhaoyang.huang, Andrew Morton, Johannes Weiner, Peter Zijlstra,
	Roman Gushchin, linux-mm, linux-kernel, cgroups, Zhaoyang Huang,
	ke.wang

On Thu 02-02-23 10:24:08, Shakeel Butt wrote:
> On Thu, Feb 2, 2023 at 12:27 AM Michal Hocko <mhocko@suse.com> wrote:
> >
> > On Thu 02-02-23 12:32:57, zhaoyang.huang wrote:
> > > From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> > >
> > > Introducing memory.root_current for the memory charges on root_mem_cgroup.
> >
> > Charges are not currently accounted for the root memcg universally. See
> > try_charge which is used for all user space and skmem charges. I am not
> > 100% sure about objcg based accounting because there is no explicit
> > check for the root memcg but this might be hidden somewhere as well.
> 
> Yes in __get_obj_cgroup_from_memcg(). However the reason to use
> try_charge_memcg() to bypass root check was to avoid the race with
> reparenting. More details in c5c8b16b596e ("mm: memcontrol: fix
> root_mem_cgroup charging").

Thanks for the pointer!

> > That means that the patch as is doesn't really provide and usable value.
> > The root exemption has been removed in the past but that has been
> > reverted due to a regression. See ce00a967377b ("mm: memcontrol: revert
> > use of root_mem_cgroup res_counter") for more.
> >
> 
> One advantage I can see is if someone is looking for usage for all top
> containers (alive or zombie) but I wanted to know if that was the real
> motivation behind the patch.

Isn't that just a global stats that we already display via /proc files?

-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH] mm: introduce entrance for root_mem_cgroup's current
  2023-02-02  8:27 ` Michal Hocko
  2023-02-02 18:24   ` Shakeel Butt
@ 2023-02-03 17:42   ` Roman Gushchin
  1 sibling, 0 replies; 8+ messages in thread
From: Roman Gushchin @ 2023-02-03 17:42 UTC (permalink / raw)
  To: Michal Hocko
  Cc: zhaoyang.huang, Andrew Morton, Johannes Weiner, Peter Zijlstra,
	Shakeel Butt, linux-mm, linux-kernel, cgroups, Zhaoyang Huang,
	ke.wang

On Thu, Feb 02, 2023 at 09:27:39AM +0100, Michal Hocko wrote:
> On Thu 02-02-23 12:32:57, zhaoyang.huang wrote:
> > From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> > 
> > Introducing memory.root_current for the memory charges on root_mem_cgroup.
> 
> Charges are not currently accounted for the root memcg universally. See
> try_charge which is used for all user space and skmem charges. I am not
> 100% sure about objcg based accounting because there is no explicit
> check for the root memcg but this might be hidden somewhere as well.

root_mem_cgroup has no corresponding obj_cgroup: see memcg_online_kmem().

Thanks

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

* Re: [PATCH] mm: introduce entrance for root_mem_cgroup's current
  2023-02-03  8:58     ` Michal Hocko
@ 2023-02-03 19:18       ` Shakeel Butt
  0 siblings, 0 replies; 8+ messages in thread
From: Shakeel Butt @ 2023-02-03 19:18 UTC (permalink / raw)
  To: Michal Hocko
  Cc: zhaoyang.huang, Andrew Morton, Johannes Weiner, Peter Zijlstra,
	Roman Gushchin, linux-mm, linux-kernel, cgroups, Zhaoyang Huang,
	ke.wang

On Fri, Feb 03, 2023 at 09:58:56AM +0100, Michal Hocko wrote:
[...]
> > 
> > One advantage I can see is if someone is looking for usage for all top
> > containers (alive or zombie) but I wanted to know if that was the real
> > motivation behind the patch.
> 
> Isn't that just a global stats that we already display via /proc files?
> 

Things are a bit complicated for kernel memory. Let's take a simple
example where there are no processes in the root memcg. In this case the
user memory stats should be similar to the global stats under /proc
because we always charge user memory. However the kernel memory has to
be opted-in to be accounted. So, we have a lot of allocations which are
in the global stats but not in the memcg stats. We can traverse the top
level memcgs to get kernel stats and subtract it from the global stats
which will give the sum of zombie kernel memory and unaccounted kernel
memory. For debugging and history/analysis purpose, differentiating
between zombie and unaccounted makes sense.

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

end of thread, other threads:[~2023-02-03 19:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-02  4:32 [PATCH] mm: introduce entrance for root_mem_cgroup's current zhaoyang.huang
2023-02-02  6:30 ` Shakeel Butt
2023-02-02  6:36   ` Zhaoyang Huang
2023-02-02  8:27 ` Michal Hocko
2023-02-02 18:24   ` Shakeel Butt
2023-02-03  8:58     ` Michal Hocko
2023-02-03 19:18       ` Shakeel Butt
2023-02-03 17:42   ` Roman Gushchin

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