Skip to content

Commit bd0b230

Browse files
Waiman-Longtorvalds
authored andcommitted
mm/memcg: unify swap and memsw page counters
The swap page counter is v2 only while memsw is v1 only. As v1 and v2 controllers cannot be active at the same time, there is no point to keep both swap and memsw page counters in mem_cgroup. The previous patch has made sure that memsw page counter is updated and accessed only when in v1 code paths. So it is now safe to alias the v1 memsw page counter to v2 swap page counter. This saves 14 long's in the size of mem_cgroup. This is a saving of 112 bytes for 64-bit archs. While at it, also document which page counters are used in v1 and/or v2. Signed-off-by: Waiman Long <longman@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Shakeel Butt <shakeelb@google.com> Acked-by: Michal Hocko <mhocko@suse.com> Cc: Chris Down <chris@chrisdown.name> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Roman Gushchin <guro@fb.com> Cc: Tejun Heo <tj@kernel.org> Cc: Vladimir Davydov <vdavydov.dev@gmail.com> Cc: Yafang Shao <laoar.shao@gmail.com> Link: https://lkml.kernel.org/r/20200914024452.19167-4-longman@redhat.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 8d387a5 commit bd0b230

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

include/linux/memcontrol.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,16 @@ struct mem_cgroup {
215215
struct mem_cgroup_id id;
216216

217217
/* Accounted resources */
218-
struct page_counter memory;
219-
struct page_counter swap;
218+
struct page_counter memory; /* Both v1 & v2 */
219+
220+
union {
221+
struct page_counter swap; /* v2 only */
222+
struct page_counter memsw; /* v1 only */
223+
};
220224

221225
/* Legacy consumer-oriented counters */
222-
struct page_counter memsw;
223-
struct page_counter kmem;
224-
struct page_counter tcpmem;
226+
struct page_counter kmem; /* v1 only */
227+
struct page_counter tcpmem; /* v1 only */
225228

226229
/* Range enforcement for interrupt charges */
227230
struct work_struct high_work;

mm/memcontrol.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5295,13 +5295,11 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css)
52955295
memcg->use_hierarchy = true;
52965296
page_counter_init(&memcg->memory, &parent->memory);
52975297
page_counter_init(&memcg->swap, &parent->swap);
5298-
page_counter_init(&memcg->memsw, &parent->memsw);
52995298
page_counter_init(&memcg->kmem, &parent->kmem);
53005299
page_counter_init(&memcg->tcpmem, &parent->tcpmem);
53015300
} else {
53025301
page_counter_init(&memcg->memory, NULL);
53035302
page_counter_init(&memcg->swap, NULL);
5304-
page_counter_init(&memcg->memsw, NULL);
53055303
page_counter_init(&memcg->kmem, NULL);
53065304
page_counter_init(&memcg->tcpmem, NULL);
53075305
/*
@@ -5430,7 +5428,6 @@ static void mem_cgroup_css_reset(struct cgroup_subsys_state *css)
54305428

54315429
page_counter_set_max(&memcg->memory, PAGE_COUNTER_MAX);
54325430
page_counter_set_max(&memcg->swap, PAGE_COUNTER_MAX);
5433-
page_counter_set_max(&memcg->memsw, PAGE_COUNTER_MAX);
54345431
page_counter_set_max(&memcg->kmem, PAGE_COUNTER_MAX);
54355432
page_counter_set_max(&memcg->tcpmem, PAGE_COUNTER_MAX);
54365433
page_counter_set_min(&memcg->memory, 0);

0 commit comments

Comments
 (0)