[CRIU] [PATCH v3] restore: Fetch mmap_minimal_address runtime
Cyrill Gorcunov
gorcunov at openvz.org
Wed Dec 7 12:59:12 PST 2016
From: Cyrill Gorcunov <gorcunov at virtuozzo.com>
We assume that mmap_minimal_address with non-default
setting is not widespread but it's not true. Instead
lets fetch this setting runtime.
Signed-off-by: Cyrill Gorcunov <gorcunov at virtuozzo.com>
---
criu/cr-restore.c | 2 +-
criu/include/kerndat.h | 1 +
criu/kerndat.c | 34 ++++++++++++++++++++++++++++++++++
3 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index c248d3df4d07..99345c97a4d3 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -2108,7 +2108,7 @@ static long restorer_get_vma_hint(struct list_head *tgt_vma_list,
end_vma.e = &end_e;
end_e.start = end_e.end = kdat.task_size;
- prev_vma_end = PAGE_SIZE * 0x10; /* CONFIG_LSM_MMAP_MIN_ADDR=65536 */
+ prev_vma_end = kdat.mmap_min_addr;
s_vma = list_first_entry(self_vma_list, struct vma_area, list);
t_vma = list_first_entry(tgt_vma_list, struct vma_area, list);
diff --git a/criu/include/kerndat.h b/criu/include/kerndat.h
index e0e8bc8ff575..cd6a13ee5e61 100644
--- a/criu/include/kerndat.h
+++ b/criu/include/kerndat.h
@@ -38,6 +38,7 @@ struct kerndat_s {
bool has_compat_sigreturn;
enum pagemap_func pmap;
unsigned int has_xtlocks;
+ unsigned long mmap_min_addr;
};
extern struct kerndat_s kdat;
diff --git a/criu/kerndat.c b/criu/kerndat.c
index a6499a1e2e5f..8295fef2bc07 100644
--- a/criu/kerndat.c
+++ b/criu/kerndat.c
@@ -7,6 +7,7 @@
#include <sys/mman.h>
#include <errno.h>
#include <sys/syscall.h>
+#include <stdint.h>
#include "int.h"
#include "log.h"
@@ -106,6 +107,37 @@ static int parse_self_maps(unsigned long vm_start, dev_t *device)
return -1;
}
+static void kerndat_get_mmap_min_addr(void)
+{
+ /* CONFIG_LSM_MMAP_MIN_ADDR=65536 */
+ static const long default_mmap_min_addr = PAGE_SIZE * 0x10;
+ uint64_t value;
+
+ struct sysctl_req req[] = {
+ {
+ .name = "vm/mmap_min_addr",
+ .arg = &value,
+ .type = CTL_U64,
+ },
+ };
+
+ if (sysctl_op(req, ARRAY_SIZE(req), CTL_READ, 0)) {
+ pr_warn("Can't fetch %s value, use default %#lx\n",
+ req[0].name, default_mmap_min_addr);
+ kdat.mmap_min_addr = default_mmap_min_addr;
+ return;
+ }
+
+ if (value < default_mmap_min_addr) {
+ pr_debug("Adjust mmap_min_addr %#lx -> %#lx\n",
+ value, default_mmap_min_addr);
+ kdat.mmap_min_addr = default_mmap_min_addr;
+ } else
+ kdat.mmap_min_addr = value;
+
+ pr_debug("Found mmap_min_addr %#lx\n", kdat.mmap_min_addr);
+}
+
static int kerndat_get_shmemdev(void)
{
void *map;
@@ -495,6 +527,7 @@ int kerndat_init(void)
ret = kerndat_compat_restore();
kerndat_lsm();
+ kerndat_get_mmap_min_addr();
return ret;
}
@@ -528,6 +561,7 @@ int kerndat_init_rst(void)
ret = kerndat_compat_restore();
kerndat_lsm();
+ kerndat_get_mmap_min_addr();
return ret;
}
--
2.7.4
More information about the CRIU
mailing list