]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
memcg: remove mem_cgroup_size()
authorChen Ridong <chenridong@huawei.com>
Thu, 11 Dec 2025 01:30:19 +0000 (01:30 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 21 Jan 2026 03:24:42 +0000 (19:24 -0800)
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 get its usage via mem_cgroup_protection for
clarity.  Additionally, rename the local variable 'cgroup_size' to 'usage'
to better reflect its meaning.

No functional changes intended.

Link: https://lkml.kernel.org/r/20251211013019.2080004-3-chenridong@huaweicloud.com
Signed-off-by: Chen Ridong <chenridong@huawei.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Michal Hocko <mhocko@suse.com>
Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Michal Koutný <mkoutny@suse.com>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Lu Jialin <lujialin4@huawei.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Qi Zheng <zhengqi.arch@bytedance.com>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Wei Xu <weixugc@google.com>
Cc: Yuanchu Xie <yuanchu@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/memcontrol.h
mm/memcontrol.c
mm/vmscan.c

index 0651865a4564fab9feb5c1d1aa24bd9543826cbe..25908ba307009d7e321aa8dfb3b1cbf9f5cc41cd 100644 (file)
@@ -557,13 +557,15 @@ static inline bool mem_cgroup_disabled(void)
 static inline void mem_cgroup_protection(struct mem_cgroup *root,
                                         struct mem_cgroup *memcg,
                                         unsigned long *min,
-                                        unsigned long *low)
+                                        unsigned long *low,
+                                        unsigned long *usage)
 {
-       *min = *low = 0;
+       *min = *low = *usage = 0;
 
        if (mem_cgroup_disabled())
                return;
 
+       *usage = page_counter_read(&memcg->memory);
        /*
         * There is no reclaim protection applied to a targeted reclaim.
         * We are special casing this specific case here because
@@ -919,8 +921,6 @@ static inline void mem_cgroup_handle_over_high(gfp_t gfp_mask)
 
 unsigned long mem_cgroup_get_max(struct mem_cgroup *memcg);
 
-unsigned long mem_cgroup_size(struct mem_cgroup *memcg);
-
 void mem_cgroup_print_oom_context(struct mem_cgroup *memcg,
                                struct task_struct *p);
 
@@ -1102,9 +1102,10 @@ static inline void memcg_memory_event_mm(struct mm_struct *mm,
 static inline void mem_cgroup_protection(struct mem_cgroup *root,
                                         struct mem_cgroup *memcg,
                                         unsigned long *min,
-                                        unsigned long *low)
+                                        unsigned long *low,
+                                        unsigned long *usage)
 {
-       *min = *low = 0;
+       *min = *low = *usage = 0;
 }
 
 static inline void mem_cgroup_calculate_protection(struct mem_cgroup *root,
@@ -1328,11 +1329,6 @@ static inline unsigned long mem_cgroup_get_max(struct mem_cgroup *memcg)
        return 0;
 }
 
-static inline unsigned long mem_cgroup_size(struct mem_cgroup *memcg)
-{
-       return 0;
-}
-
 static inline void
 mem_cgroup_print_oom_context(struct mem_cgroup *memcg, struct task_struct *p)
 {
index 7d4b93d30eb0da90fcc5d93f9974e561e5011d53..15323d5dc69b818207d689013a1d2b931aa3f113 100644 (file)
@@ -1621,11 +1621,6 @@ unsigned long mem_cgroup_get_max(struct mem_cgroup *memcg)
        return max;
 }
 
-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)
 {
index 67234613fbfff34913bbcadb58263044e476729c..1c87945fa761be73aabb59d8a777cce925e6e28c 100644 (file)
@@ -2451,9 +2451,9 @@ 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)
 {
-       unsigned long min, low;
+       unsigned long min, low, usage;
 
-       mem_cgroup_protection(sc->target_mem_cgroup, memcg, &min, &low);
+       mem_cgroup_protection(sc->target_mem_cgroup, memcg, &min, &low, &usage);
 
        if (min || low) {
                /*
@@ -2485,7 +2485,6 @@ static unsigned long apply_proportional_protection(struct mem_cgroup *memcg,
                 * again by how much of the total memory used is under
                 * hard protection.
                 */
-               unsigned long cgroup_size = mem_cgroup_size(memcg);
                unsigned long protection;
 
                /* memory.low scaling, make sure we retry before OOM */
@@ -2497,9 +2496,9 @@ static unsigned long apply_proportional_protection(struct mem_cgroup *memcg,
                }
 
                /* Avoid TOCTOU with earlier protection check */
-               cgroup_size = max(cgroup_size, protection);
+               usage = max(usage, protection);
 
-               scan -= scan * protection / (cgroup_size + 1);
+               scan -= scan * protection / (usage + 1);
 
                /*
                 * Minimally target SWAP_CLUSTER_MAX pages to keep