[PATCH 4/9] mm: memcontrol: remove the kmem states

From: Muchun Song
Date: Wed Apr 28 2021 - 05:54:30 EST


Now the kmem states is only used to indicate whether the kmem is
offlined. But we can use ->kmemcg_id to do the same things. So
remove the kmem states to simplify the code.

Signed-off-by: Muchun Song <songmuchun@xxxxxxxxxxxxx>
---
include/linux/memcontrol.h | 7 -------
mm/memcontrol.c | 10 ++--------
2 files changed, 2 insertions(+), 15 deletions(-)

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index c193be760709..6350c563c7b8 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 c1ce4fdba028..9b9a5368a3e9 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3461,7 +3461,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)
@@ -3478,7 +3477,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;
}
@@ -3488,11 +3486,6 @@ static void memcg_offline_kmem(struct mem_cgroup *memcg)
struct mem_cgroup *parent;
int kmemcg_id;

- if (memcg->kmem_state != KMEM_ONLINE)
- return;
-
- memcg->kmem_state = KMEM_ALLOCATED;
-
parent = parent_mem_cgroup(memcg);
if (!parent)
parent = root_mem_cgroup;
@@ -3506,12 +3499,13 @@ static void memcg_offline_kmem(struct mem_cgroup *memcg)
memcg_reparent_list_lrus(memcg, 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