[PATCH] slab, memcontrol: undefined reference to `memcg_kmem_get_cache'

From: Mircea CIRJALIU - MELIU
Date: Tue Sep 24 2019 - 04:46:55 EST


Having CONFIG_MEMCG turned off causes these issues:
mm/slub.o: In function `slab_pre_alloc_hook':
/home/mircea/build/mm/slab.h:425: undefined reference to `memcg_kmem_get_cache'
mm/slub.o: In function `slab_post_alloc_hook':
/home/mircea/build/mm/slab.h:444: undefined reference to `memcg_kmem_put_cache'

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 1dcb763..61a1391 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -1265,10 +1265,10 @@ static inline bool mem_cgroup_under_socket_pressure(struct mem_cgroup *memcg)
}
#endif

+#ifdef CONFIG_MEMCG_KMEM
struct kmem_cache *memcg_kmem_get_cache(struct kmem_cache *cachep);
void memcg_kmem_put_cache(struct kmem_cache *cachep);

-#ifdef CONFIG_MEMCG_KMEM
int __memcg_kmem_charge(struct page *page, gfp_t gfp, int order);
void __memcg_kmem_uncharge(struct page *page, int order);
int __memcg_kmem_charge_memcg(struct page *page, gfp_t gfp, int order,
@@ -1329,6 +1329,14 @@ extern int memcg_expand_shrinker_maps(int new_id);
extern void memcg_set_shrinker_bit(struct mem_cgroup *memcg,
int nid, int shrinker_id);
#else
+static inline struct kmem_cache *memcg_kmem_get_cache(struct kmem_cache *cachep)
+{
+ return cachep;
+}
+
+static inline void memcg_kmem_put_cache(struct kmem_cache *cachep)
+{
+}

static inline int memcg_kmem_charge(struct page *page, gfp_t gfp, int order)
{