[Devel] [PATCH libvzctl 3/3] Rework setting up memory limits on restore
Cyrill Gorcunov
gorcunov at openvz.org
Tue Feb 14 05:40:48 PST 2017
Currenlty we restore memory limits in post-resume
stage where applications are already executing
after restore stage which in worst scenario may
cause container to stop restoration procedure.
Instead lets use another strategy:
- start restore with ram limited but unlimited swap
- on post-restore stage setup swap limit back
- kick containers to run
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 | 21 ++-------
4 files changed, 88 insertions(+), 73 deletions(-)
diff --git a/lib/env.c b/lib/env.c
index f804ca4..a412b65 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 post-restore 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 post-restore 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_POST_RESTORE);
+ if (ret)
+ goto err;
+ }
+
+ logger(10, 0, "* Continue post-restore 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 post-restore 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..5240c2d 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_POST_RESTORE = 0x80000,
};
struct vzctl_opts {
diff --git a/lib/env_nsops.c b/lib/env_nsops.c
index a5f1ec4..ad9ae73 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_post_restore(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_POST_RESTORE)
+ return env_apply_param_post_restore(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..53db5f5 100755
--- a/scripts/vz-rst-action.in
+++ b/scripts/vz-rst-action.in
@@ -96,22 +96,6 @@ 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
- ;;
"post-restore")
if [ -z "$CRTOOLS_IMAGE_DIR" ]; then
echo "Missing parameter CRTOOLS_IMAGE_DIR"
@@ -132,10 +116,11 @@ case "$CRTOOLS_SCRIPT_ACTION" in
> /proc/sys/kernel/randomize_va_space || { echo "Failed to restore randomize_va_space"; exit 1; } }
fi
[ -n "$VEID" ] && { cgset -r ve.pseudosuper="0" $VEID || { echo "Failed to drop pseudosuper on $VEID"; exit 1; } }
- ;;
-"post-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 post-restore for $VEID"; exit 1; }
;;
esac
--
2.7.4
More information about the Devel
mailing list