[Devel] [PATCH libvzctl 6/6] Rework setting up memory limits on restore
Cyrill Gorcunov
gorcunov at gmail.com
Tue Feb 7 13:05:41 PST 2017
From: Cyrill Gorcunov <gorcunov at openvz.org>
- use "pre-resume" action instead of "post-sigreturn"
name, this is what vanilla criu will use
- instead of carrying limits in custom images
just set them up inside libvzctl itself when
"pre-resume" script is triggered by criu
- drop "post-resume" action from the script,
since it's not longer needed and all work
is done in "pre-resume" stage
Note all these changes are *not* backward compatible,
and require new CRIU build to functional. But since
they are not in update3 and "post-sigreturn" action
is introduced during development stage, it's allowed
to do so.
https://jira.sw.ru/browse/PSBM-58742
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
lib/env.c | 22 +++++----
lib/env.h | 2 +-
lib/env_nsops.c | 116 +++++++++++++++++++++++++++++------------------
scripts/vz-rst-action.in | 25 +++-------
4 files changed, 91 insertions(+), 74 deletions(-)
diff --git a/lib/env.c b/lib/env.c
index f804ca4..5c75257 100644
--- a/lib/env.c
+++ b/lib/env.c
@@ -1218,27 +1218,29 @@ int vzctl2_env_restore(struct vzctl_env_handle *h,
goto err;
- logger(10, 0, "* Wait for post-resume");
+ logger(10, 0, "* Wait for pre-resume action script");
ret = read_p(h->ctx->status_p[0]);
if (ret) {
- logger(-1, 0, "Error %d reported from post-resume", ret);
+ logger(-1, 0, "Error %d reported from pre-resume action script", ret);
goto err;
}
- logger(10, 0, "* Continue post-resume");
+
+ if (!(flags & VZCTL_SKIP_SETUP)) {
+ logger(10, 0, "* Setting up parameters on container");
+ ret = vzctl2_apply_param(h, env, VZCTL_CPT_PRE_RESUME);
+ if (ret)
+ goto err;
+ }
+
+ logger(10, 0, "* Continue pre-resume action script");
if (write(h->ctx->wait_p[1], &ret, sizeof(ret)) == -1)
ret = vzctl_err(VZCTL_E_SYSTEM, errno, "Unable to write to the"
- " wait fd when post-resume the Container");
+ " wait fd when pre-resume the Container");
if (ret)
goto err;
close(h->ctx->wait_p[1]); h->ctx->wait_p[1] = -1;
- if (!(flags & VZCTL_SKIP_SETUP)) {
- ret = vzctl2_apply_param(h, env, VZCTL_CPT_POST_RESUME);
- if (ret)
- goto err;
- }
-
h->ctx->state = 0;
logger(10, 0, "* Wait on error pipe");
diff --git a/lib/env.h b/lib/env.h
index d56205d..4063b9a 100644
--- a/lib/env.h
+++ b/lib/env.h
@@ -60,7 +60,7 @@
enum {
VZCTL_CONF_PARAM = 0x20000,
VZCTL_CONF_QUIET = 0x40000,
- VZCTL_CPT_POST_RESUME = 0x80000,
+ VZCTL_CPT_PRE_RESUME = 0x80000,
};
struct vzctl_opts {
diff --git a/lib/env_nsops.c b/lib/env_nsops.c
index a5f1ec4..9638d4a 100644
--- a/lib/env_nsops.c
+++ b/lib/env_nsops.c
@@ -331,53 +331,66 @@ static int ns_set_memory_param(struct vzctl_env_handle *h,
cg_env_set_memory(h->ctid, CG_SWAP_LIMIT, new_ms) : 0;
}
+static int ns_apply_memory_param(struct vzctl_env_handle *h,
+ struct vzctl_env_param *env,
+ struct vzctl_ub_param *ub,
+ int mparam_mask)
+{
+ int ret;
+
+ if (is_managed_by_vcmmd()) {
+ if (h->ctx->state == VZCTL_STATE_STARTING) {
+ /* apply parameters to avoid running with
+ * unlimited memory resources until
+ * configuration was activated by vcmmd
+ */
+ ret = ns_set_memory_param(h, ub, mparam_mask);
+ if (!ret)
+ ret = vcmm_register(h, env);
+ } else
+ ret = vcmm_update(h, env);
+ if (ret) {
+ free(env->res->memguar);
+ env->res->memguar = NULL;
+ }
+ } else
+ ret = ns_set_memory_param(h, ub, mparam_mask);
+ return ret;
+}
+
static int ns_apply_res_param(struct vzctl_env_handle *h,
- struct vzctl_env_param *env)
+ struct vzctl_env_param *env,
+ int mparam_mask)
{
- int ret;
- struct vzctl_ub_param *ub;
+ struct vzctl_ub_param *ub;
+ int ret;
- ret = get_vswap_param(h, env, &ub);
- if (ret)
- return ret;
+ ret = get_vswap_param(h, env, &ub);
+ if (ret)
+ return ret;
- if (is_vz_kernel()) {
- ret = ns_set_ub(h, ub);
- if (ret)
- goto err;
- }
+ if (is_vz_kernel()) {
+ ret = ns_set_ub(h, ub);
+ if (ret)
+ goto err;
+ }
- if (is_managed_by_vcmmd()) {
- if (h->ctx->state == VZCTL_STATE_STARTING) {
- /* apply parameters to avoid running with
- * unlimited memory resources until
- * configuration was activated by vcmmd
- */
- ret = ns_set_memory_param(h, ub, MPARAM_ALL);
- if (ret)
- goto err;
- ret = vcmm_register(h, env);
- } else
- ret = vcmm_update(h, env);
- if (ret) {
- free(env->res->memguar);
- env->res->memguar = NULL;
- }
- } else
- ret = ns_set_memory_param(h, ub, MPARAM_ALL);
+ ret = ns_apply_memory_param(h, env, ub, mparam_mask);
+ if (ret)
+ goto err;
- if (env->res->ub->pagecache_isolation) {
- ret = cg_env_set_memory(EID(h), "memory.disable_cleancache",
- env->res->ub->pagecache_isolation == VZCTL_PARAM_ON ?
- 1 : 0);
- if (ret)
- goto err;
- }
+ if (env->res->ub->pagecache_isolation) {
+ ret = cg_env_set_memory(EID(h), "memory.disable_cleancache",
+ env->res->ub->pagecache_isolation == VZCTL_PARAM_ON ?
+ 1 : 0);
+ if (ret)
+ goto err;
+ }
err:
- free_ub_param(ub);
+ free_ub_param(ub);
- return ret;
+ return ret;
}
static int ns_apply_cpu_param(struct vzctl_env_handle *h, struct vzctl_cpu_param *cpu)
@@ -715,6 +728,10 @@ static int do_env_create(struct vzctl_env_handle *h, struct start_param *param)
ret = cg_attach_task(h->ctid, getpid(), NULL);
if (ret)
goto err;
+ } else {
+ ret = cg_attach_task(h->ctid, getpid(), CG_MEMORY);
+ if (ret)
+ goto err;
}
#if 0
@@ -1164,12 +1181,12 @@ static int ns_set_nodemask(struct vzctl_env_handle *h, struct vzctl_nodemask *no
return cg_env_set_nodemask(h->ctid, nodemask->mask, sizeof(nodemask->mask));
}
-static int env_apply_param_post_resume(struct vzctl_env_handle *h,
- struct vzctl_env_param *env)
+static int env_apply_param_pre_resume(struct vzctl_env_handle *h,
+ struct vzctl_env_param *env, int mparam_mask)
{
int ret;
- ret = ns_apply_res_param(h, env);
+ ret = ns_apply_res_param(h, env, mparam_mask);
if (ret)
return ret;
@@ -1180,8 +1197,8 @@ static int ns_env_apply_param(struct vzctl_env_handle *h, struct vzctl_env_param
{
int ret;
- if (flags & VZCTL_CPT_POST_RESUME)
- return env_apply_param_post_resume(h, env);
+ if (flags & VZCTL_CPT_PRE_RESUME)
+ return env_apply_param_pre_resume(h, env, MPARAM_SWAPPAGES);
if (ns_is_env_run(h)) {
if (h->ctx->state == VZCTL_STATE_STARTING) {
@@ -1191,7 +1208,18 @@ static int ns_env_apply_param(struct vzctl_env_handle *h, struct vzctl_env_param
}
if (!(flags & VZCTL_RESTORE)) {
- ret = ns_apply_res_param(h, env);
+ ret = ns_apply_res_param(h, env, MPARAM_ALL);
+ if (ret)
+ return ret;
+ } else {
+ struct vzctl_ub_param *ub;
+
+ ret = get_vswap_param(h, env, &ub);
+ if (!ret) {
+ ret = ns_apply_memory_param(h, env, ub, MPARAM_PHYSPAGES);
+ free_ub_param(ub);
+ }
+
if (ret)
return ret;
}
diff --git a/scripts/vz-rst-action.in b/scripts/vz-rst-action.in
index 77442f8..ee34fbc 100755
--- a/scripts/vz-rst-action.in
+++ b/scripts/vz-rst-action.in
@@ -96,21 +96,12 @@ case "$CRTOOLS_SCRIPT_ACTION" in
[ "$ret" = "0" ] || { echo "Failed on network unlocking for $VEID"; exit 1; }
;;
-"post-sigreturn")
- if [ -z "$CRTOOLS_IMAGE_DIR" ]; then
- echo "Missing parameter CRTOOLS_IMAGE_DIR"
- exit 1
- fi
- if [ -n "$VEID" ]; then
- [ -f "$CRTOOLS_IMAGE_DIR/vz_memory_limit_in_bytes.img" ] && \
- { echo `cat $CRTOOLS_IMAGE_DIR/vz_memory_limit_in_bytes.img` > \
- /sys/fs/cgroup/memory/machine.slice/$VEID/memory.limit_in_bytes || \
- { echo "Failed to restore memory.limit_in_bytes"; exit 1; } }
- [ -f "$CRTOOLS_IMAGE_DIR/vz_memory_memsw_limit_in_bytes.img" ] && \
- { echo `cat $CRTOOLS_IMAGE_DIR/vz_memory_memsw_limit_in_bytes.img` > \
- /sys/fs/cgroup/memory/machine.slice/$VEID/memory.memsw.limit_in_bytes || \
- { echo "Failed to restore memory.memsw.limit_in_bytes"; exit 1; } }
- fi
+"pre-resume")
+ ret=0
+ [ -n "$STATUSFD" ] && printf '\0\0\0\0' >&${STATUSFD}
+ [ -n "$WAITFD" ] && ret=$(head -c 4 <&$WAITFD | hexdump -e '"%d"' -n 4)
+
+ [ "$ret" = "0" ] || { echo "Failed on pre-resume for $VEID"; exit 1; }
;;
"post-restore")
if [ -z "$CRTOOLS_IMAGE_DIR" ]; then
@@ -133,10 +124,6 @@ case "$CRTOOLS_SCRIPT_ACTION" in
fi
[ -n "$VEID" ] && { cgset -r ve.pseudosuper="0" $VEID || { echo "Failed to drop pseudosuper on $VEID"; exit 1; } }
;;
-"post-resume")
- [ -n "$STATUSFD" ] && printf '\0\0\0\0' >&${STATUSFD}
- [ -n "$WAITFD" ] && ret=$(head -c 4 <&$WAITFD | hexdump -e '"%d"' -n 4)
- ;;
esac
#
--
2.7.4
More information about the Devel
mailing list