[Devel] [PATCH rh7] Port diff-ubc-initialize-all-beancounters-as-unlimited
Vladimir Davydov
vdavydov at parallels.com
Fri May 22 08:10:40 PDT 2015
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 93f8d6ff4a22..98d84317bf31 100644
--- a/config.OpenVZ
+++ b/config.OpenVZ
@@ -5305,4 +5305,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 a3379f949d3c..cabebdd728c8 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 60388ce7cf42..30762f55c179 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);
@@ -252,7 +252,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 */
@@ -276,12 +275,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);
@@ -341,8 +339,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);
}
@@ -884,47 +880,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;
}
@@ -1022,14 +995,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)
--
1.7.10.4
More information about the Devel
mailing list