mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-31 14:25:49 +00:00
rst: Rework task_entries to use rst_mem engine
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@parallels.com>
This commit is contained in:
32
cr-restore.c
32
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();
|
||||
|
@@ -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 */
|
||||
|
@@ -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);
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user