From: Chen Ridong <chenridong@huaweicloud.com>
To: Michal Hocko <mhocko@suse.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 2/2] memcg: remove mem_cgroup_size()
Date: Wed, 10 Dec 2025 16:42:09 +0800 [thread overview]
Message-ID: <48f734fa-531a-4b3f-9c96-02dd342d41d2@huaweicloud.com> (raw)
In-Reply-To: <aTkp1tIIiw8Nti10@tiehlicka>
On 2025/12/10 16:05, Michal Hocko wrote:
> On Wed 10-12-25 07:11:42, Chen Ridong wrote:
>> From: Chen Ridong <chenridong@huawei.com>
>>
>> The mem_cgroup_size helper is used only in apply_proportional_protection
>> to read the current memory usage. Its semantics are unclear and
>> inconsistent with other sites, which directly call page_counter_read for
>> the same purpose.
>>
>> Remove this helper and replace its usage with page_counter_read for
>> clarity. Additionally, rename the local variable 'cgroup_size' to 'usage'
>> to better reflect its meaning.
>>
>> This change is safe because page_counter_read() is only called when memcg
>> is enabled in the apply_proportional_protection.
>>
>> No functional changes intended.
>
> I would prefer to keep the code as is.
>
I find the mem_cgroup_size() function name misleading—it suggests counting the number of memory
cgroups, but it actually returns the current memory usage.
When looking for a clearer alternative, I found mem_cgroup_usage(), which is only called by v1. This
raised the question of whether mem_cgroup_size() is truly necessary. Moreover, I noticed other code
locations simply call page_counter_read() directly to obtain current usage.
> Btw.
> [...]
>> diff --git a/mm/vmscan.c b/mm/vmscan.c
>> index 670fe9fae5ba..fe48d0376e7c 100644
>> --- a/mm/vmscan.c
>> +++ b/mm/vmscan.c
>> @@ -2451,6 +2451,7 @@ static inline void calculate_pressure_balance(struct scan_control *sc,
>> static unsigned long apply_proportional_protection(struct mem_cgroup *memcg,
>> struct scan_control *sc, unsigned long scan)
>> {
>> +#ifdef CONFIG_MEMCG
>> unsigned long min, low;
>>
>> mem_cgroup_protection(sc->target_mem_cgroup, memcg, &min, &low);
> [...]
>> @@ -2508,6 +2509,7 @@ static unsigned long apply_proportional_protection(struct mem_cgroup *memcg,
>> */
>> scan = max(scan, SWAP_CLUSTER_MAX);
>> }
>> +#endif
>> return scan;
>> }
>
> This returns a random garbage for !CONFIG_MEMCG, doesn't it?
>
--
Best regards,
Ridong
next prev parent reply other threads:[~2025-12-10 8:42 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
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 [this message]
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=48f734fa-531a-4b3f-9c96-02dd342d41d2@huaweicloud.com \
--to=chenridong@huaweicloud.com \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=cgroups@vger.kernel.org \
--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=mhocko@suse.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 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).