[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210527062148.9361-4-songmuchun@bytedance.com>
Date: Thu, 27 May 2021 14:21:30 +0800
From: Muchun Song <songmuchun@...edance.com>
To: willy@...radead.org, akpm@...ux-foundation.org, hannes@...xchg.org,
mhocko@...nel.org, vdavydov.dev@...il.com, shakeelb@...gle.com,
guro@...com, shy828301@...il.com, alexs@...nel.org,
richard.weiyang@...il.com, david@...morbit.com,
trond.myklebust@...merspace.com, anna.schumaker@...app.com
Cc: linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-mm@...ck.org, linux-nfs@...r.kernel.org,
zhengqi.arch@...edance.com, duanxiongchun@...edance.com,
fam.zheng@...edance.com, Muchun Song <songmuchun@...edance.com>
Subject: [PATCH v2 03/21] mm: memcontrol: remove the kmem states
Now the kmem states is only used to indicate whether the kmem is
offline. Because css_alloc() could fail, then we didn't make the
kmem offline. In this case, we need the kmem state to mark this
so that memcg_free_kmem() can make the kmem offline.
However, we can set ->kmemcg_id to -1 to indicate the kmem has
been offline. So we can remove the kmem states to simplify the
code.
Signed-off-by: Muchun Song <songmuchun@...edance.com>
---
include/linux/memcontrol.h | 7 -------
mm/memcontrol.c | 9 +++------
2 files changed, 3 insertions(+), 13 deletions(-)
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 0ce97eff79e2..6d0638e13fc1 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -182,12 +182,6 @@ struct mem_cgroup_thresholds {
struct mem_cgroup_threshold_ary *spare;
};
-enum memcg_kmem_state {
- KMEM_NONE,
- KMEM_ALLOCATED,
- KMEM_ONLINE,
-};
-
#if defined(CONFIG_SMP)
struct memcg_padding {
char x[0];
@@ -320,7 +314,6 @@ struct mem_cgroup {
#ifdef CONFIG_MEMCG_KMEM
int kmemcg_id;
- enum memcg_kmem_state kmem_state;
struct obj_cgroup __rcu *objcg;
struct list_head objcg_list; /* list of inherited objcgs */
#endif
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 9add859f69d7..23a9fc8dc143 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3630,7 +3630,6 @@ static int memcg_online_kmem(struct mem_cgroup *memcg)
return 0;
BUG_ON(memcg->kmemcg_id >= 0);
- BUG_ON(memcg->kmem_state);
memcg_id = memcg_alloc_cache_id();
if (memcg_id < 0)
@@ -3647,7 +3646,6 @@ static int memcg_online_kmem(struct mem_cgroup *memcg)
static_branch_enable(&memcg_kmem_enabled_key);
memcg->kmemcg_id = memcg_id;
- memcg->kmem_state = KMEM_ONLINE;
return 0;
}
@@ -3657,11 +3655,9 @@ static void memcg_offline_kmem(struct mem_cgroup *memcg)
struct mem_cgroup *parent;
int kmemcg_id;
- if (memcg->kmem_state != KMEM_ONLINE)
+ if (cgroup_memory_nokmem)
return;
- memcg->kmem_state = KMEM_ALLOCATED;
-
parent = parent_mem_cgroup(memcg);
if (!parent)
parent = root_mem_cgroup;
@@ -3675,12 +3671,13 @@ static void memcg_offline_kmem(struct mem_cgroup *memcg)
memcg_drain_all_list_lrus(kmemcg_id, parent);
memcg_free_cache_id(kmemcg_id);
+ memcg->kmemcg_id = -1;
}
static void memcg_free_kmem(struct mem_cgroup *memcg)
{
/* css_alloc() failed, offlining didn't happen */
- if (unlikely(memcg->kmem_state == KMEM_ONLINE))
+ if (unlikely(memcg->kmemcg_id != -1))
memcg_offline_kmem(memcg);
}
#else
--
2.11.0
Powered by blists - more mailing lists