[CRIU] [PATCH 1/3] rst: Fix helpers memory allocation
Pavel Emelyanov
xemul at parallels.com
Thu Jun 25 05:36:30 PDT 2015
Calling rst_mem_alloc() in a loop with increasing size causes the
n^2 memory grow :) since _alloc is not _realloc.
Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
cr-restore.c | 22 ++++++++--------------
1 file changed, 8 insertions(+), 14 deletions(-)
diff --git a/cr-restore.c b/cr-restore.c
index 45c746e..67fde2a 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -117,7 +117,6 @@ static int prepare_posix_timers(int pid, CoreEntry *core);
static int prepare_signals(int pid, CoreEntry *core);
static int root_as_sibling;
-static pid_t *helpers = NULL;
static unsigned long helpers_pos = 0;
static int n_helpers = 0;
@@ -736,25 +735,20 @@ static int collect_helper_pids()
{
struct pstree_item *pi;
+ helpers_pos = rst_mem_cpos(RM_PRIVATE);
+
list_for_each_entry(pi, ¤t->children, sibling) {
+ static pid_t *helper;
if (pi->state != TASK_HELPER)
continue;
- if (helpers) {
- void *m;
- m = rst_mem_alloc(sizeof(*helpers) * ++n_helpers, RM_PRIVATE);
- if (!m)
- return -1;
- } else {
- helpers_pos = rst_mem_cpos(RM_PRIVATE);
- helpers = rst_mem_alloc(sizeof(*helpers), RM_PRIVATE);
- if (!helpers)
- return -1;
- n_helpers = 1;
- }
+ helper = rst_mem_alloc(sizeof(*helper), RM_PRIVATE);
+ if (!helper)
+ return -1;
- helpers[n_helpers - 1] = pi->pid.virt;
+ n_helpers++;
+ *helper = pi->pid.virt;
}
return 0;
--
1.9.3
More information about the CRIU
mailing list