Setting the 'MemoryAccounting' unit property to true, puts the unit into the right cgroup but does the memory.usage_in_bytes does not reflect the pages already allocated to the processes in that cgroup.
This is because the memory.move_charge_at_immigrate needs to be set before migrating processes to the new cgroup memory controller path: https://www.kernel.org/doc/Documentation/cgroups/memory.txt The attached path sets the memory.move_charge_at_immigrate to 0x01 | 0x02 before migrating processes to a new memory cgroup. --- src/core/cgroup.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 3dd4c91..fcdbb07 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -26,6 +26,7 @@ #include "special.h" #include "cgroup-util.h" #include "cgroup.h" +#include "fileio.h" void cgroup_context_init(CGroupContext *c) { assert(c); @@ -567,6 +568,8 @@ static const char *migrate_callback(CGroupControllerMask mask, void *userdata) { static int unit_create_cgroups(Unit *u, CGroupControllerMask mask) { _cleanup_free_ char *path = NULL; + _cleanup_free_ char *fs = NULL; + char c[DECIMAL_STR_MAX(pid_t) + 2]; int r; assert(u); @@ -596,6 +599,16 @@ static int unit_create_cgroups(Unit *u, CGroupControllerMask mask) { u->cgroup_realized = true; u->cgroup_realized_mask = mask; + /* Before migrating actually turn memory migration on */ + if (mask & CGROUP_MEMORY) { + snprintf(c, sizeof(c), "%d\n", 3); + r = cg_get_path_and_check("memory", u->cgroup_path, "memory.move_charge_at_immigrate", &fs); + if (r >= 0) + r = write_string_file(fs, c); + if (r < 0) + log_error("Failed to set memory.move_change_at_immigrate on %s: %s", fs, strerror(-r)); + } + /* Then, possibly move things over */ r = cg_migrate_everywhere(u->manager->cgroup_supported, u->cgroup_path, u->cgroup_path, migrate_callback, u); if (r < 0) -- 1.8.5.3 _______________________________________________ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel