]> www.infradead.org Git - nvme.git/commitdiff
mm: memcg: gather memcg1-specific fields initialization in memcg1_memcg_init()
authorRoman Gushchin <roman.gushchin@linux.dev>
Fri, 28 Jun 2024 21:03:12 +0000 (21:03 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 5 Jul 2024 01:05:56 +0000 (18:05 -0700)
Gather all memcg1-specific struct mem_cgroup's members initialization in a
new memcg1_memcg_init() function, defined in mm/memcontrol-v1.c.
Obviously, if CONFIG_MEMCG_V1 is not set, there is no need to initialize
these fields, so the function becomes trivial.

Link: https://lkml.kernel.org/r/20240628210317.272856-5-roman.gushchin@linux.dev
Signed-off-by: Roman Gushchin <roman.gushchin@linux.dev>
Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/memcontrol-v1.c
mm/memcontrol-v1.h
mm/memcontrol.c

index c1d5076927a6da0bec3e0967f281f08a424b60fb..7218884bc3c99fb98dbc3c7ab4dd74ea0b6f2cc0 100644 (file)
@@ -1961,6 +1961,15 @@ out_kfree:
        return ret;
 }
 
+void memcg1_memcg_init(struct mem_cgroup *memcg)
+{
+       INIT_LIST_HEAD(&memcg->oom_notify);
+       mutex_init(&memcg->thresholds_lock);
+       spin_lock_init(&memcg->move_lock);
+       INIT_LIST_HEAD(&memcg->event_list);
+       spin_lock_init(&memcg->event_list_lock);
+}
+
 void memcg1_css_offline(struct mem_cgroup *memcg)
 {
        struct mem_cgroup_event *event, *tmp;
index a5e35eb8374f546c15b7c138687ffb406bd9e836..56d7eaa98274193c1599a66b322e6ce1bd38176e 100644 (file)
@@ -71,6 +71,7 @@ int memory_stat_show(struct seq_file *m, void *v);
 
 /* Cgroup v1-specific declarations */
 #ifdef CONFIG_MEMCG_V1
+void memcg1_memcg_init(struct mem_cgroup *memcg);
 void memcg1_remove_from_trees(struct mem_cgroup *memcg);
 
 static inline void memcg1_soft_limit_reset(struct mem_cgroup *memcg)
@@ -119,6 +120,7 @@ extern struct cftype mem_cgroup_legacy_files[];
 
 #else  /* CONFIG_MEMCG_V1 */
 
+static inline void memcg1_memcg_init(struct mem_cgroup *memcg) {}
 static inline void memcg1_remove_from_trees(struct mem_cgroup *memcg) {}
 static inline void memcg1_soft_limit_reset(struct mem_cgroup *memcg) {}
 static inline bool memcg1_wait_acct_move(struct mem_cgroup *memcg) { return false; }
index c6a5b0c60247109f09ba2853601a95cfdac226ba..d1ae097f0351e4228797a7226b92cbff62947518 100644 (file)
@@ -3589,13 +3589,9 @@ static struct mem_cgroup *mem_cgroup_alloc(struct mem_cgroup *parent)
                goto fail;
 
        INIT_WORK(&memcg->high_work, high_work_func);
-       INIT_LIST_HEAD(&memcg->oom_notify);
-       mutex_init(&memcg->thresholds_lock);
-       spin_lock_init(&memcg->move_lock);
        vmpressure_init(&memcg->vmpressure);
-       INIT_LIST_HEAD(&memcg->event_list);
-       spin_lock_init(&memcg->event_list_lock);
        memcg->socket_pressure = jiffies;
+       memcg1_memcg_init(memcg);
 #ifdef CONFIG_MEMCG_KMEM
        memcg->kmemcg_id = -1;
        INIT_LIST_HEAD(&memcg->objcg_list);