summaryrefslogtreecommitdiff
path: root/src/core/cgroup.c
diff options
context:
space:
mode:
authorWaLyong Cho <walyong.cho@samsung.com>2014-05-16 00:09:34 +0900
committerLennart Poettering <lennart@poettering.net>2014-05-22 07:13:56 +0900
commit95ae05c0e79868c22b3e8e6fbc53432786876730 (patch)
tree874e9eb9902db34ded1e65ef88bbaf29d2f5aa4e /src/core/cgroup.c
parent7e4f9431caf4be39f39b64634f7708d7ca217d41 (diff)
core: add startup resource control option
Similar to CPUShares= and BlockIOWeight= respectively. However only assign the specified weight during startup. Each control group attribute is re-assigned as weight by CPUShares=weight and BlockIOWeight=weight after startup. If not CPUShares= or BlockIOWeight= be specified, then the attribute is re-assigned to each default attribute value. (default cpu.shares=1024, blkio.weight=1000) If only CPUShares=weight or BlockIOWeight=weight be specified, then that implies StartupCPUShares=weight and StartupBlockIOWeight=weight.
Diffstat (limited to 'src/core/cgroup.c')
-rw-r--r--src/core/cgroup.c40
1 files changed, 30 insertions, 10 deletions
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index 29ab645f9..80a55755a 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -34,8 +34,12 @@ void cgroup_context_init(CGroupContext *c) {
* structure is preinitialized to 0 */
c->cpu_shares = 1024;
+ c->startup_cpu_shares = 1024;
+ c->startup_cpu_shares_set = false;
c->memory_limit = (uint64_t) -1;
c->blockio_weight = 1000;
+ c->startup_blockio_weight = 1000;
+ c->startup_blockio_weight_set = false;
c->cpu_quota_per_sec_usec = (usec_t) -1;
c->cpu_quota_usec = (usec_t) -1;
@@ -124,20 +128,24 @@ void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix) {
"%sBlockIOAccounting=%s\n"
"%sMemoryAccounting=%s\n"
"%sCPUShares=%lu\n"
+ "%sStartupCPUShares=%lu\n"
"%sCPUQuota=%s\n"
"%sCPUQuotaPerSecSec=%s\n"
"%sCPUQuotaPeriodSec=%s\n"
"%sBlockIOWeight=%lu\n"
+ "%sStartupBlockIOWeight=%lu\n"
"%sMemoryLimit=%" PRIu64 "\n"
"%sDevicePolicy=%s\n",
prefix, yes_no(c->cpu_accounting),
prefix, yes_no(c->blockio_accounting),
prefix, yes_no(c->memory_accounting),
prefix, c->cpu_shares,
+ prefix, c->startup_cpu_shares,
prefix, strna(format_timespan(u, sizeof(u), cgroup_context_get_cpu_quota_usec(c), 1)),
prefix, strna(format_timespan(t, sizeof(t), cgroup_context_get_cpu_quota_per_sec_usec(c), 1)),
prefix, strna(format_timespan(s, sizeof(s), c->cpu_quota_period_usec, 1)),
prefix, c->blockio_weight,
+ prefix, c->startup_blockio_weight,
prefix, c->memory_limit,
prefix, cgroup_device_policy_to_string(c->device_policy));
@@ -306,7 +314,7 @@ fail:
return -errno;
}
-void cgroup_context_apply(CGroupContext *c, CGroupControllerMask mask, const char *path) {
+void cgroup_context_apply(Manager *m, CGroupContext *c, CGroupControllerMask mask, const char *path) {
bool is_root;
int r;
@@ -324,7 +332,9 @@ void cgroup_context_apply(CGroupContext *c, CGroupControllerMask mask, const cha
char buf[MAX(DECIMAL_STR_MAX(unsigned long), DECIMAL_STR_MAX(usec_t)) + 1];
usec_t q;
- sprintf(buf, "%lu\n", c->cpu_shares);
+ sprintf(buf, "%lu\n", manager_state(m) == MANAGER_STARTING
+ ? c->startup_cpu_shares
+ : c->cpu_shares);
r = cg_set_attribute("cpu", path, "cpu.shares", buf);
if (r < 0)
log_warning("Failed to set cpu.shares on %s: %s", path, strerror(-r));
@@ -352,7 +362,9 @@ void cgroup_context_apply(CGroupContext *c, CGroupControllerMask mask, const cha
CGroupBlockIODeviceBandwidth *b;
if (!is_root) {
- sprintf(buf, "%lu\n", c->blockio_weight);
+ sprintf(buf, "%lu\n", manager_state(m) == MANAGER_STARTING
+ ? c->startup_blockio_weight
+ : c->blockio_weight);
r = cg_set_attribute("blkio", path, "blkio.weight", buf);
if (r < 0)
log_warning("Failed to set blkio.weight on %s: %s", path, strerror(-r));
@@ -462,22 +474,30 @@ void cgroup_context_apply(CGroupContext *c, CGroupControllerMask mask, const cha
}
}
-CGroupControllerMask cgroup_context_get_mask(CGroupContext *c) {
+CGroupControllerMask cgroup_context_get_mask(Manager *m, CGroupContext *c) {
CGroupControllerMask mask = 0;
/* Figure out which controllers we need */
if (c->cpu_accounting ||
- c->cpu_shares != 1024 ||
+ (manager_state(m) == MANAGER_STARTING ? c->startup_cpu_shares : c->cpu_shares) != 1024 ||
+ (manager_state(m) != MANAGER_STARTING && c->startup_cpu_shares_set && c->startup_cpu_shares != c->cpu_shares) ||
c->cpu_quota_usec != (usec_t) -1 ||
- c->cpu_quota_per_sec_usec != (usec_t) -1)
+ c->cpu_quota_per_sec_usec != (usec_t) -1) {
mask |= CGROUP_CPUACCT | CGROUP_CPU;
+ if (manager_state(m) != MANAGER_STARTING)
+ c->startup_cpu_shares_set = false;
+ }
if (c->blockio_accounting ||
- c->blockio_weight != 1000 ||
+ (manager_state(m) == MANAGER_STARTING ? c->startup_blockio_weight : c->blockio_weight) != 1000 ||
+ (manager_state(m) != MANAGER_STARTING && c->startup_blockio_weight_set && c->startup_blockio_weight != c->blockio_weight) ||
c->blockio_device_weights ||
- c->blockio_device_bandwidths)
+ c->blockio_device_bandwidths) {
mask |= CGROUP_BLKIO;
+ if (manager_state(m) != MANAGER_STARTING)
+ c->startup_blockio_weight_set = false;
+ }
if (c->memory_accounting ||
c->memory_limit != (uint64_t) -1)
@@ -496,7 +516,7 @@ CGroupControllerMask unit_get_cgroup_mask(Unit *u) {
if (!c)
return 0;
- return cgroup_context_get_mask(c);
+ return cgroup_context_get_mask(u->manager, c);
}
CGroupControllerMask unit_get_members_mask(Unit *u) {
@@ -700,7 +720,7 @@ static int unit_realize_cgroup_now(Unit *u) {
return r;
/* Finally, apply the necessary attributes. */
- cgroup_context_apply(unit_get_cgroup_context(u), mask, u->cgroup_path);
+ cgroup_context_apply(u->manager, unit_get_cgroup_context(u), mask, u->cgroup_path);
return 0;
}