[CRIU] [PATCH v2] restore: Fetch mmap_minimal_address runtime
Cyrill Gorcunov
gorcunov at openvz.org
Wed Dec 7 04:43:03 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. For speed sake the value
is cached.
Signed-off-by: Cyrill Gorcunov <gorcunov at virtuozzo.com>
---
criu/cr-restore.c | 39 ++++++++++++++++++++++++++++++++++++++-
1 file changed, 38 insertions(+), 1 deletion(-)
diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index c248d3df4d07..25e6a106f443 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -2098,6 +2098,43 @@ err:
return ret;
}
+static long restorer_get_mmap_min_addr(void)
+{
+ /* CONFIG_LSM_MMAP_MIN_ADDR=65536 */
+ static const long default_mmap_min_addr = PAGE_SIZE * 0x10;
+ static const char path[] = "/proc/sys/vm/mmap_min_addr";
+ static long mmap_min_addr = 0;
+ char buf[128];
+ int ret, fd;
+
+ if (mmap_min_addr)
+ return mmap_min_addr;
+
+ fd = open(path, O_RDONLY);
+ if (fd < 0) {
+ pr_perror("Can't open %s, switching to default", path);
+ return default_mmap_min_addr;
+ }
+
+ ret = read(fd, buf, sizeof(buf));
+ /* Al least it should be 4096, or something */
+ if (ret < 4) {
+ pr_perror("Can't read %s, switching to default", path);
+ close(fd);
+ return default_mmap_min_addr;
+ }
+ close(fd);
+
+ mmap_min_addr = atol(buf);
+ pr_debug("Obtained %#lx as mmap_min_addr\n", mmap_min_addr);
+ if (mmap_min_addr < default_mmap_min_addr) {
+ pr_debug("Adjust %#lx -> %#lx\n", mmap_min_addr, default_mmap_min_addr);
+ mmap_min_addr = default_mmap_min_addr;
+ }
+
+ return mmap_min_addr;
+}
+
static long restorer_get_vma_hint(struct list_head *tgt_vma_list,
struct list_head *self_vma_list, long vma_len)
{
@@ -2108,7 +2145,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 = restorer_get_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);
--
2.7.4
More information about the CRIU
mailing list