richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
a4b143
From 5ba4f4d42db066c3a9255768d5c38d841127bd07 Mon Sep 17 00:00:00 2001
a4b143
From: Lennart Poettering <lennart@poettering.net>
a4b143
Date: Tue, 17 Sep 2013 14:58:00 -0500
a4b143
Subject: [PATCH] cgroup: get rid of MemorySoftLimit=
a4b143
a4b143
The cgroup attribute memory.soft_limit_in_bytes is unlikely to stay
a4b143
around in the kernel for good, so let's not expose it for now. We can
a4b143
readd something like it later when the kernel guys decided on a final
a4b143
API for this.
a4b143
a4b143
Conflicts:
a4b143
	TODO
a4b143
---
a4b143
 TODO                                  |  9 +++++++++
a4b143
 man/systemd.resource-control.xml      | 15 +++++----------
a4b143
 src/core/cgroup.c                     | 16 ++--------------
a4b143
 src/core/cgroup.h                     |  1 -
a4b143
 src/core/dbus-cgroup.c                | 10 ++--------
a4b143
 src/core/dbus-cgroup.h                |  1 -
a4b143
 src/core/load-fragment-gperf.gperf.m4 |  1 -
a4b143
 src/core/load-fragment.c              |  7 ++-----
a4b143
 src/systemctl/systemctl.c             |  2 +-
a4b143
 9 files changed, 21 insertions(+), 41 deletions(-)
a4b143
a4b143
diff --git a/TODO b/TODO
a4b143
index bfeaa81..4c3e14f 100644
a4b143
--- a/TODO
a4b143
+++ b/TODO
a4b143
@@ -58,6 +58,15 @@ CGroup Rework Completion:
a4b143
 
a4b143
 Features:
a4b143
 
a4b143
+* always set memory.user_hierarchy for all cgroups we create
a4b143
+
a4b143
+* After coming back from hibernation reset hibernation swap partition
a4b143
+
a4b143
+* mounts: do not test each mount unit against each other mount unit to
a4b143
+  determine prefixes. Instead generated list of all prefixes and
a4b143
+  interate through that to bring down complexity from O(n^2) to O(n)
a4b143
+  when loading units
a4b143
+
a4b143
 * Move backlight and random-seed into /var/lib/systemd
a4b143
 
a4b143
 * If we try to find a unit via a danglign symlink generate a clean
a4b143
diff --git a/man/systemd.resource-control.xml b/man/systemd.resource-control.xml
a4b143
index 2427f208..de017a7 100644
a4b143
--- a/man/systemd.resource-control.xml
a4b143
+++ b/man/systemd.resource-control.xml
a4b143
@@ -134,22 +134,17 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>.
a4b143
 
a4b143
       <varlistentry>
a4b143
         <term><varname>MemoryLimit=<replaceable>bytes</replaceable></varname></term>
a4b143
-        <term><varname>MemorySoftLimit=<replaceable>bytes</replaceable></varname></term>
a4b143
 
a4b143
         <listitem>
a4b143
-          <para>Specify the hard and soft limits on maximum memory
a4b143
-          usage of the executed processes. The "hard" limit specifies
a4b143
-          how much process and kernel memory can be used by tasks in
a4b143
-          this unit, when there is no memory contention. If the kernel
a4b143
-          detects memory contention, memory reclaim will be performed
a4b143
-          until the memory usage is within the "soft" limit. Takes a
a4b143
+          <para>Specify the limit on maximum memory usage of the
a4b143
+          executed processes. The limit specifies how much process and
a4b143
+          kernel memory can be used by tasks in this unit. Takes a
a4b143
           memory size in bytes. If the value is suffixed with K, M, G
a4b143
           or T, the specified memory size is parsed as Kilobytes,
a4b143
           Megabytes, Gigabytes, or Terabytes (with the base 1024),
a4b143
           respectively. This controls the
a4b143
-          <literal>memory.limit_in_bytes</literal> and
a4b143
-          <literal>memory.soft_limit_in_bytes</literal> control group
a4b143
-          attributes. For details about these control group attributes,
a4b143
+          <literal>memory.limit_in_bytes</literal> control group
a4b143
+          attribute. For details about this control group attribute,
a4b143
           see 
a4b143
           url="https://www.kernel.org/doc/Documentation/cgroups/memory.txt">memory.txt</ulink>.</para>
a4b143
 
a4b143
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
a4b143
index 2f1e4a3..8bf4d89 100644
a4b143
--- a/src/core/cgroup.c
a4b143
+++ b/src/core/cgroup.c
a4b143
@@ -33,7 +33,7 @@ void cgroup_context_init(CGroupContext *c) {
a4b143
          * structure is preinitialized to 0 */
a4b143
 
a4b143
         c->cpu_shares = 1024;
a4b143
-        c->memory_limit = c->memory_soft_limit = (uint64_t) -1;
a4b143
+        c->memory_limit = (uint64_t) -1;
a4b143
         c->blockio_weight = 1000;
a4b143
 }
a4b143
 
a4b143
@@ -94,7 +94,6 @@ void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix) {
a4b143
                 "%sCPUShares=%lu\n"
a4b143
                 "%sBlockIOWeight=%lu\n"
a4b143
                 "%sMemoryLimit=%" PRIu64 "\n"
a4b143
-                "%sMemorySoftLimit=%" PRIu64 "\n"
a4b143
                 "%sDevicePolicy=%s\n",
a4b143
                 prefix, yes_no(c->cpu_accounting),
a4b143
                 prefix, yes_no(c->blockio_accounting),
a4b143
@@ -102,7 +101,6 @@ void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix) {
a4b143
                 prefix, c->cpu_shares,
a4b143
                 prefix, c->blockio_weight,
a4b143
                 prefix, c->memory_limit,
a4b143
-                prefix, c->memory_soft_limit,
a4b143
                 prefix, cgroup_device_policy_to_string(c->device_policy));
a4b143
 
a4b143
         LIST_FOREACH(device_allow, a, c->device_allow)
a4b143
@@ -266,15 +264,6 @@ void cgroup_context_apply(CGroupContext *c, CGroupControllerMask mask, const cha
a4b143
 
a4b143
                 if (r < 0)
a4b143
                         log_error("Failed to set memory.limit_in_bytes on %s: %s", path, strerror(-r));
a4b143
-
a4b143
-                if (c->memory_soft_limit != (uint64_t) -1) {
a4b143
-                        sprintf(buf, "%" PRIu64 "\n", c->memory_soft_limit);
a4b143
-                        r = cg_set_attribute("memory", path, "memory.soft_limit_in_bytes", buf);
a4b143
-                } else
a4b143
-                        r = cg_set_attribute("memory", path, "memory.soft_limit_in_bytes", "-1");
a4b143
-
a4b143
-                if (r < 0)
a4b143
-                        log_error("Failed to set memory.soft_limit_in_bytes on %s: %s", path, strerror(-r));
a4b143
         }
a4b143
 
a4b143
         if (mask & CGROUP_DEVICE) {
a4b143
@@ -337,8 +326,7 @@ CGroupControllerMask cgroup_context_get_mask(CGroupContext *c) {
a4b143
                 mask |= CGROUP_BLKIO;
a4b143
 
a4b143
         if (c->memory_accounting ||
a4b143
-            c->memory_limit != (uint64_t) -1 ||
a4b143
-            c->memory_soft_limit != (uint64_t) -1)
a4b143
+            c->memory_limit != (uint64_t) -1)
a4b143
                 mask |= CGROUP_MEMORY;
a4b143
 
a4b143
         if (c->device_allow || c->device_policy != CGROUP_AUTO)
a4b143
diff --git a/src/core/cgroup.h b/src/core/cgroup.h
a4b143
index 786bd71..0a079e9 100644
a4b143
--- a/src/core/cgroup.h
a4b143
+++ b/src/core/cgroup.h
a4b143
@@ -77,7 +77,6 @@ struct CGroupContext {
a4b143
         LIST_HEAD(CGroupBlockIODeviceBandwidth, blockio_device_bandwidths);
a4b143
 
a4b143
         uint64_t memory_limit;
a4b143
-        uint64_t memory_soft_limit;
a4b143
 
a4b143
         CGroupDevicePolicy device_policy;
a4b143
         LIST_HEAD(CGroupDeviceAllow, device_allow);
a4b143
diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c
a4b143
index 1f2a396..9ebcad9 100644
a4b143
--- a/src/core/dbus-cgroup.c
a4b143
+++ b/src/core/dbus-cgroup.c
a4b143
@@ -133,7 +133,6 @@ const BusProperty bus_cgroup_context_properties[] = {
a4b143
         { "BlockIOWriteBandwidth",   bus_cgroup_append_device_bandwidths, "a(st)", 0                                           },
a4b143
         { "MemoryAccounting",        bus_property_append_bool,            "b",     offsetof(CGroupContext, memory_accounting)  },
a4b143
         { "MemoryLimit",             bus_property_append_uint64,          "t",     offsetof(CGroupContext, memory_limit)       },
a4b143
-        { "MemorySoftLimit",         bus_property_append_uint64,          "t",     offsetof(CGroupContext, memory_soft_limit)  },
a4b143
         { "DevicePolicy",            bus_cgroup_append_device_policy,     "s",     offsetof(CGroupContext, device_policy)      },
a4b143
         { "DeviceAllow",             bus_cgroup_append_device_allow,      "a(ss)", 0                                           },
a4b143
         {}
a4b143
@@ -418,21 +417,16 @@ int bus_cgroup_set_property(
a4b143
 
a4b143
                 return 1;
a4b143
 
a4b143
-        } else if (streq(name, "MemoryLimit") || streq(name, "MemorySoftLimit")) {
a4b143
+        } else if (streq(name, "MemoryLimit")) {
a4b143
 
a4b143
                 if (dbus_message_iter_get_arg_type(i) != DBUS_TYPE_UINT64)
a4b143
                         return -EINVAL;
a4b143
 
a4b143
                 if (mode != UNIT_CHECK) {
a4b143
                         uint64_t limit;
a4b143
-
a4b143
                         dbus_message_iter_get_basic(i, &limit);
a4b143
 
a4b143
-                        if (streq(name, "MemoryLimit"))
a4b143
-                                c->memory_limit = limit;
a4b143
-                        else
a4b143
-                                c->memory_soft_limit = limit;
a4b143
-
a4b143
+                        c->memory_limit = limit;
a4b143
                         unit_write_drop_in_private_format(u, mode, name, "%s=%" PRIu64, name, limit);
a4b143
                 }
a4b143
 
a4b143
diff --git a/src/core/dbus-cgroup.h b/src/core/dbus-cgroup.h
a4b143
index 4ce1e7e..e5ac4c3 100644
a4b143
--- a/src/core/dbus-cgroup.h
a4b143
+++ b/src/core/dbus-cgroup.h
a4b143
@@ -37,7 +37,6 @@
a4b143
         "  <property name=\"BlockIOWriteBandwidth=\" type=\"a(st)\" access=\"read\"/>\n" \
a4b143
         "  <property name=\"MemoryAccounting\" type=\"b\" access=\"read\"/>\n" \
a4b143
         "  <property name=\"MemoryLimit\" type=\"t\" access=\"read\"/>\n" \
a4b143
-        "  <property name=\"MemorySoftLimit\" type=\"t\" access=\"read\"/>\n" \
a4b143
         "  <property name=\"DevicePolicy\" type=\"s\" access=\"read\"/>\n" \
a4b143
         "  <property name=\"DeviceAllow\" type=\"a(ss)\" access=\"read\"/>\n"
a4b143
 
a4b143
diff --git a/src/core/load-fragment-gperf.gperf.m4 b/src/core/load-fragment-gperf.gperf.m4
a4b143
index 3f064a9..31fb7bc 100644
a4b143
--- a/src/core/load-fragment-gperf.gperf.m4
a4b143
+++ b/src/core/load-fragment-gperf.gperf.m4
a4b143
@@ -89,7 +89,6 @@ $1.CPUAccounting,                config_parse_bool,                  0,
a4b143
 $1.CPUShares,                    config_parse_cpu_shares,            0,                             offsetof($1, cgroup_context)
a4b143
 $1.MemoryAccounting,             config_parse_bool,                  0,                             offsetof($1, cgroup_context.memory_accounting)
a4b143
 $1.MemoryLimit,                  config_parse_memory_limit,          0,                             offsetof($1, cgroup_context)
a4b143
-$1.MemorySoftLimit,              config_parse_memory_limit,          0,                             offsetof($1, cgroup_context)
a4b143
 $1.DeviceAllow,                  config_parse_device_allow,          0,                             offsetof($1, cgroup_context)
a4b143
 $1.DevicePolicy,                 config_parse_device_policy,         0,                             offsetof($1, cgroup_context.device_policy)
a4b143
 $1.BlockIOAccounting,            config_parse_bool,                  0,                             offsetof($1, cgroup_context.blockio_accounting)
a4b143
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
a4b143
index ed8602f..6e0a180 100644
a4b143
--- a/src/core/load-fragment.c
a4b143
+++ b/src/core/load-fragment.c
a4b143
@@ -2015,14 +2015,11 @@ int config_parse_memory_limit(
a4b143
                 void *userdata) {
a4b143
 
a4b143
         CGroupContext *c = data;
a4b143
-        uint64_t *limit;
a4b143
         off_t bytes;
a4b143
         int r;
a4b143
 
a4b143
-        limit = streq(lvalue, "MemoryLimit") ? &c->memory_limit : &c->memory_soft_limit;
a4b143
-
a4b143
         if (isempty(rvalue)) {
a4b143
-                *limit = (uint64_t) -1;
a4b143
+                c->memory_limit = (uint64_t) -1;
a4b143
                 return 0;
a4b143
         }
a4b143
 
a4b143
@@ -2035,7 +2032,7 @@ int config_parse_memory_limit(
a4b143
                 return 0;
a4b143
         }
a4b143
 
a4b143
-        *limit = (uint64_t) bytes;
a4b143
+        c->memory_limit = (uint64_t) bytes;
a4b143
         return 0;
a4b143
 }
a4b143
 
a4b143
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
a4b143
index 16da293..1080065 100644
a4b143
--- a/src/systemctl/systemctl.c
a4b143
+++ b/src/systemctl/systemctl.c
a4b143
@@ -3657,7 +3657,7 @@ static int append_assignment(DBusMessageIter *iter, const char *assignment) {
a4b143
                     !dbus_message_iter_append_basic(&sub, DBUS_TYPE_BOOLEAN, &b))
a4b143
                         return log_oom();
a4b143
 
a4b143
-        } else if (streq(field, "MemoryLimit") || streq(field, "MemorySoftLimit")) {
a4b143
+        } else if (streq(field, "MemoryLimit")) {
a4b143
                 off_t bytes;
a4b143
                 uint64_t u;
a4b143