Skip to content

Commit eee9f1d

Browse files
committed
mm: memcontrol: don't allocate cgroup swap arrays when memcg is disabled
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2077665 commit c91bdc9 Author: Johannes Weiner <hannes@cmpxchg.org> Date: Mon, 26 Sep 2022 09:57:01 -0400 mm: memcontrol: don't allocate cgroup swap arrays when memcg is disabled Patch series "memcg swap fix & cleanups". This patch (of 4): Since commit 2d1c498 ("mm: memcontrol: make swap tracking an integral part of memory control"), the cgroup swap arrays are used to track memory ownership at the time of swap readahead and swapoff, even if swap space *accounting* has been turned off by the user via swapaccount=0 (which sets cgroup_memory_noswap). However, the patch was overzealous: by simply dropping the cgroup_memory_noswap conditionals in the swapon, swapoff and uncharge path, it caused the cgroup arrays being allocated even when the memory controller as a whole is disabled. This is a waste of that memory. Restore mem_cgroup_disabled() checks, implied previously by cgroup_memory_noswap, in the swapon, swapoff, and swap_entry_free callbacks. Link: https://lkml.kernel.org/r/20220926135704.400818-1-hannes@cmpxchg.org Link: https://lkml.kernel.org/r/20220926135704.400818-2-hannes@cmpxchg.org Fixes: 2d1c498 ("mm: memcontrol: make swap tracking an integral part of memory control") Signed-off-by: Johannes Weiner <hannes@cmpxchg.org> Reported-by: Hugh Dickins <hughd@google.com> Reviewed-by: Shakeel Butt <shakeelb@google.com> Acked-by: Hugh Dickins <hughd@google.com> Acked-by: Michal Hocko <mhocko@suse.com> Cc: Roman Gushchin <roman.gushchin@linux.dev> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Waiman Long <longman@redhat.com>
1 parent 7491f7e commit eee9f1d

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

mm/memcontrol.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7372,6 +7372,9 @@ void __mem_cgroup_uncharge_swap(swp_entry_t entry, unsigned int nr_pages)
73727372
struct mem_cgroup *memcg;
73737373
unsigned short id;
73747374

7375+
if (mem_cgroup_disabled())
7376+
return;
7377+
73757378
id = swap_cgroup_record(entry, 0, nr_pages);
73767379
rcu_read_lock();
73777380
memcg = mem_cgroup_from_id(id);

mm/swap_cgroup.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ int swap_cgroup_swapon(int type, unsigned long max_pages)
170170
unsigned long length;
171171
struct swap_cgroup_ctrl *ctrl;
172172

173+
if (mem_cgroup_disabled())
174+
return 0;
175+
173176
length = DIV_ROUND_UP(max_pages, SC_PER_PAGE);
174177

175178
array = vcalloc(length, sizeof(void *));
@@ -204,6 +207,9 @@ void swap_cgroup_swapoff(int type)
204207
unsigned long i, length;
205208
struct swap_cgroup_ctrl *ctrl;
206209

210+
if (mem_cgroup_disabled())
211+
return;
212+
207213
mutex_lock(&swap_cgroup_mutex);
208214
ctrl = &swap_cgroup_ctrl[type];
209215
map = ctrl->map;

0 commit comments

Comments
 (0)