[Devel] [PATCH RHEL7 COMMIT] bc: initialize all beancounters as unlimited

Konstantin Khorenko khorenko at virtuozzo.com
Thu May 28 06:19:43 PDT 2015


The commit is pushed to "branch-rh7-3.10.0-123.1.2-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-123.1.2.vz7.5.7
------>
commit 3f27fe7672dc5e649fecf9da8896daec2ba0e92e
Author: Vladimir Davydov <vdavydov at parallels.com>
Date:   Thu May 28 17:19:43 2015 +0400

    bc: initialize all beancounters as unlimited
    
    Port diff-ubc-initialize-all-beancounters-as-unlimited
    
    Port the following RH6 commit:
    
      Author: Konstantin Khlebnikov
      Email: khlebnikov at openvz.org
      Subject: UBC: initialize all beancounters as unlimited
      Date: Tue, 19 Feb 2013 13:11:03 +0400
    
      Here more accurate version of Dmitry's patch.
    
      * we must set vmguarpages.barrier to zero to obey sistem-wide overcommit policy
      * default oomguarpages.barrier is 75% of ram to make fresh beancounters and host
        non-immune to oom-killer and in the same time give them chance to survive
      * correct some comments in code
      * and as usual this patch removes bunch of useless code
    
      Comment from Dmitry's version:
    
      We have problems with tools working under beancounter, like
      vzmdest, vzmsrc, etc. They use default limits from kernel and
      then apply limits from config file.
    
      Let's fix it in the kernel - set all limits to unlimited, so
      tools will limit only needed resources.
    
      https://jira.sw.ru/browse/PCLIN-31512
      https://jira.sw.ru/browse/PCLIN-31511
    
      Signed-off-by: Konstantin Khlebnikov <khlebnikov at openvz.org>
      Cc: Dmitry Guryanov <dguryanov at parallels.com>
    
    Signed-off-by: Vladimir Davydov <vdavydov at parallels.com>
---
 config.OpenVZ           |  1 -
 kernel/bc/Kconfig       |  6 -----
 kernel/bc/beancounter.c | 65 ++++++++++++-------------------------------------
 3 files changed, 15 insertions(+), 57 deletions(-)

diff --git a/config.OpenVZ b/config.OpenVZ
index 68b5778..9fd794f 100644
--- a/config.OpenVZ
+++ b/config.OpenVZ
@@ -5306,4 +5306,3 @@ CONFIG_BC_IO_PRIORITY=y
 CONFIG_BC_PROC=y
 CONFIG_BC_DEBUG=y
 # CONFIG_BC_DEBUG_ITEMS is not set
-# CONFIG_BC_UNLIMITED is not set
diff --git a/kernel/bc/Kconfig b/kernel/bc/Kconfig
index a3379f9..cabebdd 100644
--- a/kernel/bc/Kconfig
+++ b/kernel/bc/Kconfig
@@ -68,10 +68,4 @@ config BC_DEBUG_ITEMS
 	  When true some of the resources (e.g. kmemsize) are accounted
 	  in items instead of bytes.
 
-config BC_UNLIMITED
-	bool "Use unlimited ubc settings"
-	default n
-	depends on BC_DEBUG
-	help
-	  When ON all limits and barriers are set to max values.
 endmenu
diff --git a/kernel/bc/beancounter.c b/kernel/bc/beancounter.c
index bffdf0a..4ea2375 100644
--- a/kernel/bc/beancounter.c
+++ b/kernel/bc/beancounter.c
@@ -45,7 +45,7 @@
 #include <bc/proc.h>
 
 static struct kmem_cache *ub_cachep;
-static struct user_beancounter default_beancounter;
+
 struct user_beancounter ub0 = {
 };
 EXPORT_SYMBOL(ub0);
@@ -280,7 +280,6 @@ static void uncharge_beancounter_precharge(struct user_beancounter *ub)
 
 static void init_beancounter_struct(struct user_beancounter *ub);
 static void init_beancounter_nolimits(struct user_beancounter *ub);
-static void init_beancounter_syslimits(struct user_beancounter *ub);
 
 static DEFINE_SPINLOCK(ub_list_lock);
 LIST_HEAD(ub_list_head); /* protected by ub_list_lock */
@@ -304,12 +303,11 @@ static struct user_beancounter *alloc_ub(const char *name)
 	struct user_beancounter *new_ub;
 	ub_debug(UBD_ALLOC, "Creating ub %p\n", new_ub);
 
-	new_ub = (struct user_beancounter *)kmem_cache_alloc(ub_cachep, 
-			GFP_KERNEL);
+	new_ub = kmem_cache_zalloc(ub_cachep, GFP_KERNEL);
 	if (new_ub == NULL)
 		return NULL;
 
-	memcpy(new_ub, &default_beancounter, sizeof(*new_ub));
+	init_beancounter_nolimits(new_ub);
 	init_beancounter_struct(new_ub);
 
 	init_beancounter_precharges(new_ub);
@@ -369,8 +367,6 @@ struct user_beancounter *get_beancounter_by_name(const char *name, int create)
 			cg = cgroup_kernel_open(ub_cgroup_root, CGRP_CREAT, name);
 			if (IS_ERR_OR_NULL(cg))
 				return NULL;
-			pr_warn_once("Allocating UB with syslimits is deprecated!\n");
-			init_beancounter_syslimits(cgroup_ub(cg));
 			if (ub_update_memcg(cgroup_ub(cg)) != 0)
 				pr_warn("Failed to init UB %s limits\n", name);
 		}
@@ -911,47 +907,24 @@ static void init_beancounter_nolimits(struct user_beancounter *ub)
 
 	for (k = 0; k < UB_RESOURCES; k++) {
 		ub->ub_parms[k].limit = UB_MAXVALUE;
-		/* FIXME: whether this is right for physpages and guarantees? */
 		ub->ub_parms[k].barrier = UB_MAXVALUE;
 	}
 
-	ub->ub_parms[UB_VMGUARPAGES].limit = 0;
+	/*
+	 * Unlimited vmguarpages gives immunity against systemwide overcommit
+	 * policy. It makes sense in some cases but by default we must obey it.
+	 */
 	ub->ub_parms[UB_VMGUARPAGES].barrier = 0;
 
-	/* FIXME: set unlimited rate? */
-	ub->ub_ratelimit.burst = 4;
-	ub->ub_ratelimit.interval = 300*HZ;
-}
-
-static void init_beancounter_syslimits(struct user_beancounter *ub)
-{
-	unsigned long mp;
-	extern int max_threads;
-	int k;
-
-	mp = num_physpages;
-	ub->ub_parms[UB_KMEMSIZE].limit = UB_MAXVALUE;
-	ub->ub_parms[UB_LOCKEDPAGES].limit = 8;
-	ub->ub_parms[UB_PRIVVMPAGES].limit = UB_MAXVALUE;
-	ub->ub_parms[UB_SHMPAGES].limit = 64;
-	ub->ub_parms[UB_NUMPROC].limit = max_threads / 2;
-	ub->ub_parms[UB_NUMTCPSOCK].limit = 1024;
-	ub->ub_parms[UB_TCPSNDBUF].limit = 1024*4*1024; /* 4k per socket */
-	ub->ub_parms[UB_TCPRCVBUF].limit = 1024*6*1024; /* 6k per socket */
-	ub->ub_parms[UB_NUMOTHERSOCK].limit = 256;
-	ub->ub_parms[UB_DGRAMRCVBUF].limit = 256*4*1024; /* 4k per socket */
-	ub->ub_parms[UB_OTHERSOCKBUF].limit = 256*8*1024; /* 8k per socket */
-	ub->ub_parms[UB_NUMFLOCK].limit = 1024;
-	ub->ub_parms[UB_NUMPTY].limit = 16;
-	ub->ub_parms[UB_NUMSIGINFO].limit = 1024;
-	ub->ub_parms[UB_DCACHESIZE].limit = UB_MAXVALUE;
-	ub->ub_parms[UB_NUMFILE].limit = 1024;
-	ub->ub_parms[UB_PHYSPAGES].limit = UB_MAXVALUE;
-	ub->ub_parms[UB_SWAPPAGES].limit = UB_MAXVALUE;
-
-	for (k = 0; k < UB_RESOURCES; k++)
-		ub->ub_parms[k].barrier = ub->ub_parms[k].limit;
+	/*
+	 * Unlimited oomguarpages makes container or host mostly immune to
+	 * to the OOM-killer while other containers exists. Withal we cannot
+	 * set it to zero, otherwise single unconfigured container will be
+	 * first target for OOM-killer. 75% of ram looks like sane default.
+	 */
+	ub->ub_parms[UB_OOMGUARPAGES].barrier = totalram_pages * 3 / 4;
 
+	/* Ratelimit for messages in the kernel log */
 	ub->ub_ratelimit.burst = 4;
 	ub->ub_ratelimit.interval = 300*HZ;
 }
@@ -1049,14 +1022,6 @@ void __init ub_init_late(void)
 	ub_cachep = kmem_cache_create("user_beancounters",
 			sizeof(struct user_beancounter),
 			0, SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL);
-
-	memset(&default_beancounter, 0, sizeof(default_beancounter));
-#ifdef CONFIG_BC_UNLIMITED
-	init_beancounter_nolimits(&default_beancounter);
-#else
-	init_beancounter_syslimits(&default_beancounter);
-#endif
-	init_beancounter_struct(&default_beancounter);
 }
 
 int __init ub_init_cgroup(void)



More information about the Devel mailing list