diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c index e4d8243a1..d51fd838f 100644 --- a/src/lxc/cgroups/cgfsng.c +++ b/src/lxc/cgroups/cgfsng.c @@ -2703,6 +2703,32 @@ static int cg_legacy_set_data(struct cgroup_ops *ops, const char *filename, return lxc_write_openat(h->path_lim, filename, value, strlen(value)); } +/* + * Return the list of cgroup_settings sorted according to the following rules + * 1. Put memory.limit_in_bytes before memory.memsw.limit_in_bytes + */ +static void sort_cgroup_settings(struct lxc_conf *conf) +{ + LIST_HEAD(memsw_list); + struct lxc_cgroup *cgroup, *ncgroup; + + /* Iterate over the cgroup settings and copy them to the output list. */ + list_for_each_entry_safe(cgroup, ncgroup, &conf->cgroup, head) { + if (!strequal(cgroup->subsystem, "memory.memsw.limit_in_bytes")) + continue; + + /* Move the memsw entry from the cgroup settings list. */ + list_move_tail(&cgroup->head, &memsw_list); + } + + /* + * Append all the memsw entries to the end of the cgroup settings list + * to make sure they are applied after all memory limit settings. + */ + list_splice_tail(&memsw_list, &conf->cgroup); + +} + __cgfsng_ops static bool cgfsng_setup_limits_legacy(struct cgroup_ops *ops, struct lxc_conf *conf, bool do_devices) diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 59cfbc940..8aaefa16f 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -5679,29 +5679,6 @@ void suggest_default_idmap(void) ERROR("lxc.idmap = g 0 %u %u", gid, grange); } -/* Return the list of cgroup_settings sorted according to the following rules - * 1. Put memory.limit_in_bytes before memory.memsw.limit_in_bytes - */ -void sort_cgroup_settings(struct lxc_conf *conf) -{ - struct lxc_cgroup *cgroup, *memsw_limit, *ncgroup; - - /* Iterate over the cgroup settings and copy them to the output list. */ - list_for_each_entry_safe(cgroup, ncgroup, &conf->cgroup, head) { - if (strequal(cgroup->subsystem, "memory.memsw.limit_in_bytes")) { - /* Store the memsw_limit location */ - memsw_limit = cgroup; - } else if (memsw_limit && strequal(cgroup->subsystem, "memory.limit_in_bytes")) { - /* - * lxc.cgroup.memory.memsw.limit_in_bytes is found - * before lxc.cgroup.memory.limit_in_bytes, swap these - * two items. - */ - list_swap(&memsw_limit->head, &cgroup->head); - } - } -} - int lxc_set_environment(const struct lxc_conf *conf) { struct environment_entry *env; diff --git a/src/lxc/conf.h b/src/lxc/conf.h index 7cc41afd2..270b7f8d2 100644 --- a/src/lxc/conf.h +++ b/src/lxc/conf.h @@ -568,7 +568,6 @@ __hidden extern int parse_mount_attrs(struct lxc_mount_options *opts, const char __hidden extern void tmp_proc_unmount(struct lxc_conf *lxc_conf); __hidden extern void suggest_default_idmap(void); __hidden extern FILE *make_anonymous_mount_file(struct lxc_list *mount, bool include_nesting_helpers); -__hidden extern void sort_cgroup_settings(struct lxc_conf *conf); __hidden extern int run_script(const char *name, const char *section, const char *script, ...); __hidden extern int run_script_argv(const char *name, unsigned int hook_version, const char *section, const char *script, const char *hookname, char **argsin);