Commit a87425a3 authored by Yafang Shao's avatar Yafang Shao Committed by Linus Torvalds
Browse files

mm, memcg: fix build error around the usage of kmem_caches

When I manually set default n to MEMCG_KMEM in init/Kconfig, bellow error

  mm/slab_common.c: In function 'memcg_slab_start':
  mm/slab_common.c:1530:30: error: 'struct mem_cgroup' has no member named
    return seq_list_start(&memcg->kmem_caches, *pos);
  mm/slab_common.c: In function 'memcg_slab_next':
  mm/slab_common.c:1537:32: error: 'struct mem_cgroup' has no member named
    return seq_list_next(p, &memcg->kmem_caches, pos);
  mm/slab_common.c: In function 'memcg_slab_show':
  mm/slab_common.c:1551:16: error: 'struct mem_cgroup' has no member named
    if (p == memcg->
    CC      arch/x86/xen/smp.o
  mm/slab_common.c: In function 'memcg_slab_start':
  mm/slab_common.c:1531:1: warning: control reaches end of non-void function
  mm/slab_common.c: In function 'memcg_slab_next':
  mm/slab_common.c:1538:1: warning: control reaches end of non-void function

That's because kmem_caches is defined only when CONFIG_MEMCG_KMEM is set,
while memcg_slab_start() will use it no matter CONFIG_MEMCG_KMEM is defined
or not.

By the way, the reason I mannuly undefined CONFIG_MEMCG_KMEM is to verify
whether my some other code change is still stable when CONFIG_MEMCG_KMEM is
not set. Unfortunately, the existing code has been already unstable since

Fixes: bc2791f8

 ("slab: link memcg kmem_caches on their associated memory cgroup")
Signed-off-by: default avatarYafang Shao <>
Signed-off-by: default avatarAndrew Morton <>
Acked-by: default avatarAndrew Morton <>
Cc: Tejun Heo <>
Cc: Vladimir Davydov <>
Cc: Johannes Weiner <>
Cc: Michal Hocko <>

Signed-off-by: default avatarLinus Torvalds <>
parent cb774451
......@@ -4792,7 +4792,8 @@ static struct cftype mem_cgroup_legacy_files[] = {
.write = mem_cgroup_reset,
.read_u64 = mem_cgroup_read_u64,
#if defined(CONFIG_SLAB) || defined(CONFIG_SLUB_DEBUG)
#if defined(CONFIG_MEMCG_KMEM) && \
(defined(CONFIG_SLAB) || defined(CONFIG_SLUB_DEBUG))
.name = "kmem.slabinfo",
.seq_start = memcg_slab_start,
......@@ -1521,7 +1521,7 @@ void dump_unreclaimable_slab(void)
#if defined(CONFIG_MEMCG)
#if defined(CONFIG_MEMCG_KMEM)
void *memcg_slab_start(struct seq_file *m, loff_t *pos)
struct mem_cgroup *memcg = mem_cgroup_from_seq(m);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment