[CRIU] [PATCH 3/3] rst: Rework task_entries to use rst_mem engine

Pavel Emelyanov xemul at parallels.com
Mon Aug 18 08:47:20 PDT 2014


The task_entries is a small structure used to coordinate the
processes restore stages. Currentl we allocate one page for
it and handle one separately. No need in this complexity, actually.
The rst_mem engine is already capable to controll this small object.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 cr-restore.c       | 32 +++++++-------------------------
 include/restorer.h |  2 --
 pie/restorer.c     |  1 -
 3 files changed, 7 insertions(+), 28 deletions(-)

diff --git a/cr-restore.c b/cr-restore.c
index b76dcad..6a9cb85 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -95,20 +95,6 @@ static int prepare_signals(int pid);
 
 static int root_as_sibling;
 
-static int shmem_remap(void *old_addr, void *new_addr, unsigned long size)
-{
-	void *ret;
-
-	ret = mremap(old_addr, size, size,
-			MREMAP_FIXED | MREMAP_MAYMOVE, new_addr);
-	if (new_addr != ret) {
-		pr_perror("mremap failed");
-		return -1;
-	}
-
-	return 0;
-}
-
 static int crtools_prepare_shared(void)
 {
 	if (prepare_shared_fdinfo())
@@ -822,6 +808,7 @@ static inline int sig_fatal(int sig)
 }
 
 struct task_entries *task_entries;
+static unsigned long task_entries_pos;
 
 static int restore_one_zombie(int pid, CoreEntry *core)
 {
@@ -1737,13 +1724,15 @@ out:
 	return 1;
 }
 
-static int prepare_task_entries()
+static int prepare_task_entries(void)
 {
-	task_entries = mmap(NULL, TASK_ENTRIES_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, 0, 0);
-	if (task_entries == MAP_FAILED) {
+	task_entries_pos = rst_mem_cpos(RM_SHREMAP);
+	task_entries = rst_mem_alloc(sizeof(*task_entries), RM_SHREMAP);
+	if (!task_entries) {
 		pr_perror("Can't map shmem");
 		return -1;
 	}
+
 	task_entries->nr_threads = 0;
 	task_entries->nr_tasks = 0;
 	task_entries->nr_helpers = 0;
@@ -2455,7 +2444,6 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core)
 
 	BUILD_BUG_ON(sizeof(struct task_restore_args) & 1);
 	BUILD_BUG_ON(sizeof(struct thread_restore_args) & 1);
-	BUILD_BUG_ON(TASK_ENTRIES_SIZE % PAGE_SIZE);
 
 	args_len = round_up(sizeof(*task_args) + sizeof(*thread_args) * current->nr_threads, PAGE_SIZE);
 	pr_info("%d threads require %ldK of memory\n",
@@ -2513,7 +2501,6 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core)
 		goto err;
 
 	restore_bootstrap_len = restorer_len + args_len +
-				TASK_ENTRIES_SIZE +
 				rst_mem_remap_size();
 
 #ifdef CONFIG_VDSO
@@ -2594,15 +2581,10 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core)
 	 */
 
 	mem += args_len;
-	ret = shmem_remap(task_entries, mem, TASK_ENTRIES_SIZE);
-	if (ret < 0)
-		goto err;
-	mem += TASK_ENTRIES_SIZE;
-
 	if (rst_mem_remap(mem))
 		goto err;
 
-	task_args->task_entries = mem - TASK_ENTRIES_SIZE;
+	task_args->task_entries = rst_mem_remap_ptr(task_entries_pos, RM_SHREMAP);
 
 	task_args->rst_mem = mem;
 	task_args->rst_mem_size = rst_mem_remap_size();
diff --git a/include/restorer.h b/include/restorer.h
index 0f1034d..a690341 100644
--- a/include/restorer.h
+++ b/include/restorer.h
@@ -165,8 +165,6 @@ static inline unsigned long restorer_stack(struct thread_restore_args *a)
 	return RESTORE_ALIGN_STACK((long)a->mem_zone.stack, RESTORE_STACK_SIZE);
 }
 
-#define TASK_ENTRIES_SIZE 4096
-
 enum {
 	CR_STATE_FAIL		= -1,
 	CR_STATE_RESTORE_NS	= 0, /* is used for executing "setup-namespace" scripts */
diff --git a/pie/restorer.c b/pie/restorer.c
index 6388fd5..11ad574 100644
--- a/pie/restorer.c
+++ b/pie/restorer.c
@@ -1080,7 +1080,6 @@ long __export_restore_task(struct task_restore_args *args)
 
 	restore_posix_timers(args);
 
-	sys_munmap(args->task_entries, TASK_ENTRIES_SIZE);
 	sys_munmap(args->rst_mem, args->rst_mem_size);
 
 	/*
-- 
1.8.4.2




More information about the CRIU mailing list