Browse Source

mm: memcontrol: introduce CONFIG_MEMCG_LEGACY_KMEM

Let the user know that CONFIG_MEMCG_KMEM does not apply to the cgroup2
interface. This also makes legacy-only code sections stand out better.

[arnd@arndb.de: mm: memcontrol: only manage socket pressure for CONFIG_INET]
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Tejun Heo <tj@kernel.org>
Acked-by: Vladimir Davydov <vdavydov@virtuozzo.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Johannes Weiner 9 years ago
parent
commit
489c2a20a4
5 changed files with 23 additions and 13 deletions
  1. 2 2
      include/linux/memcontrol.h
  2. 9 1
      init/Kconfig
  3. 9 9
      mm/memcontrol.c
  4. 2 0
      mm/vmpressure.c
  5. 1 1
      net/ipv4/Makefile

+ 2 - 2
include/linux/memcontrol.h

@@ -233,7 +233,7 @@ struct mem_cgroup {
 	 */
 	 */
 	struct mem_cgroup_stat_cpu __percpu *stat;
 	struct mem_cgroup_stat_cpu __percpu *stat;
 
 
-#if defined(CONFIG_MEMCG_KMEM) && defined(CONFIG_INET)
+#if defined(CONFIG_MEMCG_LEGACY_KMEM) && defined(CONFIG_INET)
 	struct cg_proto tcp_mem;
 	struct cg_proto tcp_mem;
 #endif
 #endif
 #ifndef CONFIG_SLOB
 #ifndef CONFIG_SLOB
@@ -717,7 +717,7 @@ extern struct static_key_false memcg_sockets_enabled_key;
 #define mem_cgroup_sockets_enabled static_branch_unlikely(&memcg_sockets_enabled_key)
 #define mem_cgroup_sockets_enabled static_branch_unlikely(&memcg_sockets_enabled_key)
 static inline bool mem_cgroup_under_socket_pressure(struct mem_cgroup *memcg)
 static inline bool mem_cgroup_under_socket_pressure(struct mem_cgroup *memcg)
 {
 {
-#ifdef CONFIG_MEMCG_KMEM
+#ifdef CONFIG_MEMCG_LEGACY_KMEM
 	if (memcg->tcp_mem.memory_pressure)
 	if (memcg->tcp_mem.memory_pressure)
 		return true;
 		return true;
 #endif
 #endif

+ 9 - 1
init/Kconfig

@@ -964,10 +964,13 @@ config MEMCG_SWAP_ENABLED
 	  For those who want to have the feature enabled by default should
 	  For those who want to have the feature enabled by default should
 	  select this option (if, for some reason, they need to disable it
 	  select this option (if, for some reason, they need to disable it
 	  then swapaccount=0 does the trick).
 	  then swapaccount=0 does the trick).
+config MEMCG_LEGACY_KMEM
+       bool
 config MEMCG_KMEM
 config MEMCG_KMEM
-	bool "Memory Resource Controller Kernel Memory accounting"
+	bool "Legacy Memory Resource Controller Kernel Memory accounting"
 	depends on MEMCG
 	depends on MEMCG
 	depends on SLUB || SLAB
 	depends on SLUB || SLAB
+	select MEMCG_LEGACY_KMEM
 	help
 	help
 	  The Kernel Memory extension for Memory Resource Controller can limit
 	  The Kernel Memory extension for Memory Resource Controller can limit
 	  the amount of memory used by kernel objects in the system. Those are
 	  the amount of memory used by kernel objects in the system. Those are
@@ -1071,6 +1074,11 @@ config CGROUP_FREEZER
 	  Provides a way to freeze and unfreeze all tasks in a
 	  Provides a way to freeze and unfreeze all tasks in a
 	  cgroup.
 	  cgroup.
 
 
+	  This option affects the ORIGINAL cgroup interface. The cgroup2 memory
+	  controller includes important in-kernel memory consumers per default.
+
+	  If you're using cgroup2, say N.
+
 config CGROUP_HUGETLB
 config CGROUP_HUGETLB
 	bool "HugeTLB controller"
 	bool "HugeTLB controller"
 	depends on HUGETLB_PAGE
 	depends on HUGETLB_PAGE

+ 9 - 9
mm/memcontrol.c

@@ -3001,7 +3001,7 @@ static void memcg_free_kmem(struct mem_cgroup *memcg)
 }
 }
 #endif /* !CONFIG_SLOB */
 #endif /* !CONFIG_SLOB */
 
 
-#ifdef CONFIG_MEMCG_KMEM
+#ifdef CONFIG_MEMCG_LEGACY_KMEM
 static int memcg_update_kmem_limit(struct mem_cgroup *memcg,
 static int memcg_update_kmem_limit(struct mem_cgroup *memcg,
 				   unsigned long limit)
 				   unsigned long limit)
 {
 {
@@ -3025,7 +3025,7 @@ static int memcg_update_kmem_limit(struct mem_cgroup *memcg,
 {
 {
 	return -EINVAL;
 	return -EINVAL;
 }
 }
-#endif /* CONFIG_MEMCG_KMEM */
+#endif /* CONFIG_MEMCG_LEGACY_KMEM */
 
 
 
 
 /*
 /*
@@ -4039,7 +4039,7 @@ static struct cftype mem_cgroup_legacy_files[] = {
 		.seq_show = memcg_numa_stat_show,
 		.seq_show = memcg_numa_stat_show,
 	},
 	},
 #endif
 #endif
-#ifdef CONFIG_MEMCG_KMEM
+#ifdef CONFIG_MEMCG_LEGACY_KMEM
 	{
 	{
 		.name = "kmem.limit_in_bytes",
 		.name = "kmem.limit_in_bytes",
 		.private = MEMFILE_PRIVATE(_KMEM, RES_LIMIT),
 		.private = MEMFILE_PRIVATE(_KMEM, RES_LIMIT),
@@ -4266,13 +4266,13 @@ mem_cgroup_css_online(struct cgroup_subsys_state *css)
 	if (ret)
 	if (ret)
 		return ret;
 		return ret;
 
 
-#ifdef CONFIG_MEMCG_KMEM
+#ifdef CONFIG_INET
+#ifdef CONFIG_MEMCG_LEGACY_KMEM
 	ret = tcp_init_cgroup(memcg);
 	ret = tcp_init_cgroup(memcg);
 	if (ret)
 	if (ret)
 		return ret;
 		return ret;
 #endif
 #endif
 
 
-#ifdef CONFIG_INET
 	if (cgroup_subsys_on_dfl(memory_cgrp_subsys) && !cgroup_memory_nosocket)
 	if (cgroup_subsys_on_dfl(memory_cgrp_subsys) && !cgroup_memory_nosocket)
 		static_branch_inc(&memcg_sockets_enabled_key);
 		static_branch_inc(&memcg_sockets_enabled_key);
 #endif
 #endif
@@ -4329,7 +4329,7 @@ static void mem_cgroup_css_free(struct cgroup_subsys_state *css)
 
 
 	memcg_free_kmem(memcg);
 	memcg_free_kmem(memcg);
 
 
-#ifdef CONFIG_MEMCG_KMEM
+#if defined(CONFIG_MEMCG_LEGACY_KMEM) && defined(CONFIG_INET)
 	tcp_destroy_cgroup(memcg);
 	tcp_destroy_cgroup(memcg);
 #endif
 #endif
 
 
@@ -5558,7 +5558,7 @@ void sock_update_memcg(struct sock *sk)
 	memcg = mem_cgroup_from_task(current);
 	memcg = mem_cgroup_from_task(current);
 	if (memcg == root_mem_cgroup)
 	if (memcg == root_mem_cgroup)
 		goto out;
 		goto out;
-#ifdef CONFIG_MEMCG_KMEM
+#ifdef CONFIG_MEMCG_LEGACY_KMEM
 	if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && !memcg->tcp_mem.active)
 	if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && !memcg->tcp_mem.active)
 		goto out;
 		goto out;
 #endif
 #endif
@@ -5587,7 +5587,7 @@ bool mem_cgroup_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages)
 {
 {
 	gfp_t gfp_mask = GFP_KERNEL;
 	gfp_t gfp_mask = GFP_KERNEL;
 
 
-#ifdef CONFIG_MEMCG_KMEM
+#ifdef CONFIG_MEMCG_LEGACY_KMEM
 	if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) {
 	if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) {
 		struct page_counter *counter;
 		struct page_counter *counter;
 
 
@@ -5619,7 +5619,7 @@ bool mem_cgroup_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages)
  */
  */
 void mem_cgroup_uncharge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages)
 void mem_cgroup_uncharge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages)
 {
 {
-#ifdef CONFIG_MEMCG_KMEM
+#ifdef CONFIG_MEMCG_LEGACY_KMEM
 	if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) {
 	if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) {
 		page_counter_uncharge(&memcg->tcp_mem.memory_allocated,
 		page_counter_uncharge(&memcg->tcp_mem.memory_allocated,
 				      nr_pages);
 				      nr_pages);

+ 2 - 0
mm/vmpressure.c

@@ -275,6 +275,7 @@ void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, bool tree,
 
 
 		level = vmpressure_calc_level(scanned, reclaimed);
 		level = vmpressure_calc_level(scanned, reclaimed);
 
 
+#ifdef CONFIG_INET
 		if (level > VMPRESSURE_LOW) {
 		if (level > VMPRESSURE_LOW) {
 			/*
 			/*
 			 * Let the socket buffer allocator know that
 			 * Let the socket buffer allocator know that
@@ -286,6 +287,7 @@ void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, bool tree,
 			 */
 			 */
 			memcg->socket_pressure = jiffies + HZ;
 			memcg->socket_pressure = jiffies + HZ;
 		}
 		}
+#endif
 	}
 	}
 }
 }
 
 

+ 1 - 1
net/ipv4/Makefile

@@ -56,7 +56,7 @@ obj-$(CONFIG_TCP_CONG_SCALABLE) += tcp_scalable.o
 obj-$(CONFIG_TCP_CONG_LP) += tcp_lp.o
 obj-$(CONFIG_TCP_CONG_LP) += tcp_lp.o
 obj-$(CONFIG_TCP_CONG_YEAH) += tcp_yeah.o
 obj-$(CONFIG_TCP_CONG_YEAH) += tcp_yeah.o
 obj-$(CONFIG_TCP_CONG_ILLINOIS) += tcp_illinois.o
 obj-$(CONFIG_TCP_CONG_ILLINOIS) += tcp_illinois.o
-obj-$(CONFIG_MEMCG_KMEM) += tcp_memcontrol.o
+obj-$(CONFIG_MEMCG_LEGACY_KMEM) += tcp_memcontrol.o
 obj-$(CONFIG_NETLABEL) += cipso_ipv4.o
 obj-$(CONFIG_NETLABEL) += cipso_ipv4.o
 
 
 obj-$(CONFIG_XFRM) += xfrm4_policy.o xfrm4_state.o xfrm4_input.o \
 obj-$(CONFIG_XFRM) += xfrm4_policy.o xfrm4_state.o xfrm4_input.o \