[systemd-devel] [PATCH v2 1/4] cgroup: add the setting memory.use_hierarchy support for systemd
Gao feng
gaofeng at cn.fujitsu.com
Mon Sep 23 17:36:52 PDT 2013
On 09/24/2013 05:06 AM, Lennart Poettering wrote:
> On Mon, 23.09.13 14:30, Gao feng (gaofeng at cn.fujitsu.com) wrote:
>
>> Some programs need to set the memory.use_hierarchy(such as libvirt),
>> Add this feature.
>
> As mentioned already: this really shouldn't be configurable but simply
> the unconditional configuration that systemd requires. I have hence now
> commited a different patch that strictly enables this option at
> boot-time in the root memory hierarchy and does not turn this into yet
> another user config switch.
So administrator has no rights to set use_hierarchy to false?
This patchset enables use_hierarchy for unit by default. but give
users the rights to disable this.
>
> THis is what Tejun suggested to do and is also what makes the most sense
> to me. cgroups after all are organized logically in a tree and it is
> simply contradictory ignore this all and pretend everything was flat...
>
>> ---
>> src/core/cgroup.c | 6 ++++++
>> src/core/cgroup.h | 1 +
>> src/core/dbus-cgroup.c | 16 ++++++++++++++++
>> src/core/load-fragment-gperf.gperf.m4 | 1 +
>> 4 files changed, 24 insertions(+)
>>
>> diff --git a/src/core/cgroup.c b/src/core/cgroup.c
>> index d10f205..68615c3 100644
>> --- a/src/core/cgroup.c
>> +++ b/src/core/cgroup.c
>> @@ -32,6 +32,7 @@ void cgroup_context_init(CGroupContext *c) {
>> /* Initialize everything to the kernel defaults, assuming the
>> * structure is preinitialized to 0 */
>>
>> + c->memory_hierarchy = true;
>> c->cpu_shares = 1024;
>> c->memory_limit = (uint64_t) -1;
>> c->blockio_weight = 1000;
>> @@ -263,6 +264,11 @@ void cgroup_context_apply(CGroupContext *c, CGroupControllerMask mask, const cha
>>
>> if (r < 0)
>> log_error("Failed to set memory.limit_in_bytes on %s: %s", path, strerror(-r));
>> +
>> + r = cg_set_attribute("memory", path, "memory.use_hierarchy", c->memory_hierarchy ? "1" : "0");
>> +
>> + if (r < 0)
>> + log_error("Failed to set memory.use_hierarchy on %s: %s", path, strerror(-r));
>> }
>>
>> if (mask & CGROUP_DEVICE) {
>> diff --git a/src/core/cgroup.h b/src/core/cgroup.h
>> index 0a079e9..f87c16a 100644
>> --- a/src/core/cgroup.h
>> +++ b/src/core/cgroup.h
>> @@ -69,6 +69,7 @@ struct CGroupContext {
>> bool cpu_accounting;
>> bool blockio_accounting;
>> bool memory_accounting;
>> + bool memory_hierarchy;
>>
>> unsigned long cpu_shares;
>>
>> diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c
>> index 9ebcad9..a8a5f81 100644
>> --- a/src/core/dbus-cgroup.c
>> +++ b/src/core/dbus-cgroup.c
>> @@ -132,6 +132,7 @@ const BusProperty bus_cgroup_context_properties[] = {
>> { "BlockIOReadBandwidth", bus_cgroup_append_device_bandwidths, "a(st)", 0 },
>> { "BlockIOWriteBandwidth", bus_cgroup_append_device_bandwidths, "a(st)", 0 },
>> { "MemoryAccounting", bus_property_append_bool, "b", offsetof(CGroupContext, memory_accounting) },
>> + { "MemoryHierarchy", bus_property_append_bool, "b", offsetof(CGroupContext, memory_hierarchy) },
>> { "MemoryLimit", bus_property_append_uint64, "t", offsetof(CGroupContext, memory_limit) },
>> { "DevicePolicy", bus_cgroup_append_device_policy, "s", offsetof(CGroupContext, device_policy) },
>> { "DeviceAllow", bus_cgroup_append_device_allow, "a(ss)", 0 },
>> @@ -417,6 +418,21 @@ int bus_cgroup_set_property(
>>
>> return 1;
>>
>> + } else if (streq(name, "MemoryHierarchy")) {
>> +
>> + if (dbus_message_iter_get_arg_type(i) != DBUS_TYPE_BOOLEAN)
>> + return -EINVAL;
>> +
>> + if (mode != UNIT_CHECK) {
>> + dbus_bool_t b;
>> + dbus_message_iter_get_basic(i, &b);
>> +
>> + c->memory_hierarchy = b;
>> + unit_write_drop_in_private(u, mode, name, b ? "MemoryHierarchy=yes" : "MemoryHierarchy=no");
>> + }
>> +
>> + return 1;
>> +
>> } else if (streq(name, "MemoryLimit")) {
>>
>> if (dbus_message_iter_get_arg_type(i) != DBUS_TYPE_UINT64)
>> diff --git a/src/core/load-fragment-gperf.gperf.m4 b/src/core/load-fragment-gperf.gperf.m4
>> index 25bd3aa..b43ca05 100644
>> --- a/src/core/load-fragment-gperf.gperf.m4
>> +++ b/src/core/load-fragment-gperf.gperf.m4
>> @@ -88,6 +88,7 @@ m4_define(`CGROUP_CONTEXT_CONFIG_ITEMS',
>> $1.CPUAccounting, config_parse_bool, 0, offsetof($1, cgroup_context.cpu_accounting)
>> $1.CPUShares, config_parse_cpu_shares, 0, offsetof($1, cgroup_context)
>> $1.MemoryAccounting, config_parse_bool, 0, offsetof($1, cgroup_context.memory_accounting)
>> +$1.MemoryHierarchy, config_parse_bool, 0, offsetof($1, cgroup_context.memory_hierarchy)
>> $1.MemoryLimit, config_parse_memory_limit, 0, offsetof($1, cgroup_context)
>> $1.DeviceAllow, config_parse_device_allow, 0, offsetof($1, cgroup_context)
>> $1.DevicePolicy, config_parse_device_policy, 0, offsetof($1, cgroup_context.device_policy)
>
>
> Lennart
>
More information about the systemd-devel
mailing list