[CRIU] [PATCH 1/2] restore: Fetch mmap_minimal_address runtime
Cyrill Gorcunov
gorcunov at openvz.org
Fri Dec 23 01:15:48 PST 2016
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 | 37 +++++++++++++++++++++++++++++++++++++
3 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index c313ed476b0b..1c87c6ed3f5d 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -2106,7 +2106,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 ab6ef3f55ab7..9931ac103f3a 100644
--- a/criu/include/kerndat.h
+++ b/criu/include/kerndat.h
@@ -40,6 +40,7 @@ struct kerndat_s {
unsigned int has_xtlocks;
bool has_tcp_half_closed;
unsigned long uffd_features;
+ unsigned long mmap_min_addr;
};
extern struct kerndat_s kdat;
diff --git a/criu/kerndat.c b/criu/kerndat.c
index 1cc0a1dc6c6f..d8f6f06df54f 100644
--- a/criu/kerndat.c
+++ b/criu/kerndat.c
@@ -10,6 +10,8 @@
#include <sys/sysmacros.h>
#include <sys/socket.h>
#include <arpa/inet.h> /* for sockaddr_in and inet_ntoa() */
+#include <sys/sysmacros.h>
+#include <stdint.h>
#include "int.h"
#include "log.h"
@@ -111,6 +113,39 @@ static int parse_self_maps(unsigned long vm_start, dev_t *device)
return -1;
}
+static void kerndat_mmap_min_addr(void)
+{
+ /* From kernel's default CONFIG_LSM_MMAP_MIN_ADDR */
+ static const unsigned long default_mmap_min_addr = 65536;
+ 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, (unsigned long)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",
+ (unsigned long)value,
+ (unsigned long)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",
+ (unsigned long)kdat.mmap_min_addr);
+}
+
static int kerndat_get_shmemdev(void)
{
void *map;
@@ -603,6 +638,7 @@ int kerndat_init(void)
ret = kerndat_tcp_repair();
kerndat_lsm();
+ kerndat_mmap_min_addr();
return ret;
}
@@ -640,6 +676,7 @@ int kerndat_init_rst(void)
ret = kerndat_uffd(opts.lazy_pages);
kerndat_lsm();
+ kerndat_mmap_min_addr();
return ret;
}
--
2.7.4
More information about the CRIU
mailing list