From 95ae05c0e79868c22b3e8e6fbc53432786876730 Mon Sep 17 00:00:00 2001 From: WaLyong Cho Date: Fri, 16 May 2014 00:09:34 +0900 Subject: 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. --- src/core/dbus-cgroup.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/core/dbus-cgroup.c') diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c index e9bdabf931..a7c8ca6c27 100644 --- a/src/core/dbus-cgroup.c +++ b/src/core/dbus-cgroup.c @@ -173,11 +173,13 @@ const sd_bus_vtable bus_cgroup_vtable[] = { SD_BUS_VTABLE_START(0), SD_BUS_PROPERTY("CPUAccounting", "b", bus_property_get_bool, offsetof(CGroupContext, cpu_accounting), 0), SD_BUS_PROPERTY("CPUShares", "t", bus_property_get_ulong, offsetof(CGroupContext, cpu_shares), 0), + SD_BUS_PROPERTY("StartupCPUShares", "t", bus_property_get_ulong, offsetof(CGroupContext, startup_cpu_shares), 0), SD_BUS_PROPERTY("CPUQuotaPerSecUSec", "t", property_get_cpu_quota_per_sec_usec, 0, 0), SD_BUS_PROPERTY("CPUQuotaUSec", "t", property_get_cpu_quota_usec, 0, 0), SD_BUS_PROPERTY("CPUQuotaPeriodUSec", "t", bus_property_get_usec, offsetof(CGroupContext, cpu_quota_period_usec), 0), SD_BUS_PROPERTY("BlockIOAccounting", "b", bus_property_get_bool, offsetof(CGroupContext, blockio_accounting), 0), SD_BUS_PROPERTY("BlockIOWeight", "t", bus_property_get_ulong, offsetof(CGroupContext, blockio_weight), 0), + SD_BUS_PROPERTY("StartupBlockIOWeight", "t", bus_property_get_ulong, offsetof(CGroupContext, startup_blockio_weight), 0), SD_BUS_PROPERTY("BlockIODeviceWeight", "a(st)", property_get_blockio_device_weight, 0, 0), SD_BUS_PROPERTY("BlockIOReadBandwidth", "a(st)", property_get_blockio_device_bandwidths, 0, 0), SD_BUS_PROPERTY("BlockIOWriteBandwidth", "a(st)", property_get_blockio_device_bandwidths, 0, 0), @@ -238,6 +240,26 @@ int bus_cgroup_set_property( return 1; + } else if (streq(name, "StartupCPUShares")) { + uint64_t u64; + unsigned long ul; + + r = sd_bus_message_read(message, "t", &u64); + if (r < 0) + return r; + + ul = (unsigned long) u64; + if (ul <= 0 || (uint64_t) ul != u64) + return sd_bus_error_set_errnof(error, EINVAL, "StartupCPUShares value out of range"); + + if (mode != UNIT_CHECK) { + c->startup_cpu_shares = ul; + c->startup_cpu_shares_set = true; + unit_write_drop_in_private_format(u, mode, name, "StartupCPUShares=%lu", ul); + } + + return 1; + } else if (streq(name, "CPUQuotaPerSecUSec")) { uint64_t u64; @@ -330,6 +352,26 @@ int bus_cgroup_set_property( return 1; + } else if (streq(name, "StartupBlockIOWeight")) { + uint64_t u64; + unsigned long ul; + + r = sd_bus_message_read(message, "t", &u64); + if (r < 0) + return r; + + ul = (unsigned long) u64; + if (ul < 10 || ul > 1000) + return sd_bus_error_set_errnof(error, EINVAL, "StartupBlockIOWeight value out of range"); + + if (mode != UNIT_CHECK) { + c->startup_blockio_weight = ul; + c->startup_blockio_weight_set = true; + unit_write_drop_in_private_format(u, mode, name, "StartupBlockIOWeight=%lu", ul); + } + + return 1; + } else if (streq(name, "BlockIOReadBandwidth") || streq(name, "BlockIOWriteBandwidth")) { const char *path; bool read = true; -- cgit v1.2.3-54-g00ecf