mm, memcg: introduce mem_cgroup_kmem_disabled()
authorRoman Gushchin <guro@fb.com>
Thu, 3 Jun 2021 01:09:30 +0000 (18:09 -0700)
committerDennis Zhou <dennis@kernel.org>
Sat, 5 Jun 2021 20:41:14 +0000 (20:41 +0000)
Introduce a new mem_cgroup_kmem_disabled() helper, similar to
mem_cgroup_disabled(), to check whether the kernel memory accounting
is off. A user could disable it using a boot option to eliminate
some associated costs.

The helper can be used outside of memcontrol.c to dynamically disable
the kmem-related code. The returned value is stable after the kernel
initialization is finished.

Signed-off-by: Roman Gushchin <guro@fb.com>
Signed-off-by: Dennis Zhou <dennis@kernel.org>
include/linux/memcontrol.h
mm/memcontrol.c

index 0c04d39a7967659ff74babf8e57743fdead8712e..8ef51c58f470350863bc0a7c07214d4ec387e6af 100644 (file)
@@ -1583,6 +1583,7 @@ static inline void memcg_set_shrinker_bit(struct mem_cgroup *memcg,
 #endif
 
 #ifdef CONFIG_MEMCG_KMEM
+bool mem_cgroup_kmem_disabled(void);
 int __memcg_kmem_charge_page(struct page *page, gfp_t gfp, int order);
 void __memcg_kmem_uncharge_page(struct page *page, int order);
 
@@ -1636,6 +1637,10 @@ static inline int memcg_cache_id(struct mem_cgroup *memcg)
 struct mem_cgroup *mem_cgroup_from_obj(void *p);
 
 #else
+static inline bool mem_cgroup_kmem_disabled(void)
+{
+       return true;
+}
 
 static inline int memcg_kmem_charge_page(struct page *page, gfp_t gfp,
                                         int order)
index e6203ee24a11a3a331c2d50212887de4f36dd1f4..1fa9b00ec71d90c56e12901f169f4c13bd9c1016 100644 (file)
@@ -255,6 +255,11 @@ struct cgroup_subsys_state *vmpressure_to_css(struct vmpressure *vmpr)
 #ifdef CONFIG_MEMCG_KMEM
 extern spinlock_t css_set_lock;
 
+bool mem_cgroup_kmem_disabled(void)
+{
+       return cgroup_memory_nokmem;
+}
+
 static int __memcg_kmem_charge(struct mem_cgroup *memcg, gfp_t gfp,
                               unsigned int nr_pages);
 static void __memcg_kmem_uncharge(struct mem_cgroup *memcg,