All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@suse.com>
To: Chen Ridong <chenridong@huaweicloud.com>
Cc: hannes@cmpxchg.org, roman.gushchin@linux.dev,
	shakeel.butt@linux.dev, muchun.song@linux.dev,
	akpm@linux-foundation.org, axelrasmussen@google.com,
	yuanchu@google.com, weixugc@google.com, david@kernel.org,
	zhengqi.arch@bytedance.com, lorenzo.stoakes@oracle.com,
	cgroups@vger.kernel.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, lujialin4@huawei.com
Subject: Re: [PATCH -next v2 1/2] memcg: move mem_cgroup_usage memcontrol-v1.c
Date: Wed, 10 Dec 2025 09:01:51 +0100	[thread overview]
Message-ID: <aTko72qBxxm2YzHT@tiehlicka> (raw)
In-Reply-To: <20251210071142.2043478-2-chenridong@huaweicloud.com>

On Wed 10-12-25 07:11:41, Chen Ridong wrote:
> From: Chen Ridong <chenridong@huawei.com>
> 
> Currently, mem_cgroup_usage is only used for v1, just move it to
> memcontrol-v1.c
> 
> Signed-off-by: Chen Ridong <chenridong@huawei.com>

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

> ---
>  mm/memcontrol-v1.c | 22 ++++++++++++++++++++++
>  mm/memcontrol-v1.h |  2 --
>  mm/memcontrol.c    | 22 ----------------------
>  3 files changed, 22 insertions(+), 24 deletions(-)
> 
> diff --git a/mm/memcontrol-v1.c b/mm/memcontrol-v1.c
> index 6eed14bff742..0b50cb122ff3 100644
> --- a/mm/memcontrol-v1.c
> +++ b/mm/memcontrol-v1.c
> @@ -427,6 +427,28 @@ static int mem_cgroup_move_charge_write(struct cgroup_subsys_state *css,
>  }
>  #endif
>  
> +static unsigned long mem_cgroup_usage(struct mem_cgroup *memcg, bool swap)
> +{
> +	unsigned long val;
> +
> +	if (mem_cgroup_is_root(memcg)) {
> +		/*
> +		 * Approximate root's usage from global state. This isn't
> +		 * perfect, but the root usage was always an approximation.
> +		 */
> +		val = global_node_page_state(NR_FILE_PAGES) +
> +			global_node_page_state(NR_ANON_MAPPED);
> +		if (swap)
> +			val += total_swap_pages - get_nr_swap_pages();
> +	} else {
> +		if (!swap)
> +			val = page_counter_read(&memcg->memory);
> +		else
> +			val = page_counter_read(&memcg->memsw);
> +	}
> +	return val;
> +}
> +
>  static void __mem_cgroup_threshold(struct mem_cgroup *memcg, bool swap)
>  {
>  	struct mem_cgroup_threshold_ary *t;
> diff --git a/mm/memcontrol-v1.h b/mm/memcontrol-v1.h
> index 6358464bb416..e92b21af92b1 100644
> --- a/mm/memcontrol-v1.h
> +++ b/mm/memcontrol-v1.h
> @@ -22,8 +22,6 @@
>  	     iter != NULL;				\
>  	     iter = mem_cgroup_iter(NULL, iter, NULL))
>  
> -unsigned long mem_cgroup_usage(struct mem_cgroup *memcg, bool swap);
> -
>  void drain_all_stock(struct mem_cgroup *root_memcg);
>  
>  unsigned long memcg_events(struct mem_cgroup *memcg, int event);
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index e2e49f4ec9e0..dbe7d8f93072 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -3272,28 +3272,6 @@ void folio_split_memcg_refs(struct folio *folio, unsigned old_order,
>  	css_get_many(&__folio_memcg(folio)->css, new_refs);
>  }
>  
> -unsigned long mem_cgroup_usage(struct mem_cgroup *memcg, bool swap)
> -{
> -	unsigned long val;
> -
> -	if (mem_cgroup_is_root(memcg)) {
> -		/*
> -		 * Approximate root's usage from global state. This isn't
> -		 * perfect, but the root usage was always an approximation.
> -		 */
> -		val = global_node_page_state(NR_FILE_PAGES) +
> -			global_node_page_state(NR_ANON_MAPPED);
> -		if (swap)
> -			val += total_swap_pages - get_nr_swap_pages();
> -	} else {
> -		if (!swap)
> -			val = page_counter_read(&memcg->memory);
> -		else
> -			val = page_counter_read(&memcg->memsw);
> -	}
> -	return val;
> -}
> -
>  static int memcg_online_kmem(struct mem_cgroup *memcg)
>  {
>  	struct obj_cgroup *objcg;
> -- 
> 2.34.1
> 

-- 
Michal Hocko
SUSE Labs

  reply	other threads:[~2025-12-10  8:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-10  7:11 [PATCH -next v2 0/2] memcg cleanups Chen Ridong
2025-12-10  7:11 ` [PATCH -next v2 1/2] memcg: move mem_cgroup_usage memcontrol-v1.c Chen Ridong
2025-12-10  8:01   ` Michal Hocko [this message]
2025-12-10 16:28   ` Johannes Weiner
2025-12-10  7:11 ` [PATCH -next v2 2/2] memcg: remove mem_cgroup_size() Chen Ridong
2025-12-10  8:05   ` Michal Hocko
2025-12-10  8:31     ` Chen Ridong
2025-12-10  8:37       ` Michal Hocko
2025-12-10  8:42     ` Chen Ridong
2025-12-10 16:36   ` Johannes Weiner
2025-12-11  0:43     ` Chen Ridong

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=aTko72qBxxm2YzHT@tiehlicka \
    --to=mhocko@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=axelrasmussen@google.com \
    --cc=cgroups@vger.kernel.org \
    --cc=chenridong@huaweicloud.com \
    --cc=david@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=lujialin4@huawei.com \
    --cc=muchun.song@linux.dev \
    --cc=roman.gushchin@linux.dev \
    --cc=shakeel.butt@linux.dev \
    --cc=weixugc@google.com \
    --cc=yuanchu@google.com \
    --cc=zhengqi.arch@bytedance.com \
    /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.