Commit 23b76949 authored by Andrew Vagin's avatar Andrew Vagin Committed by Pavel Emelyanov

dump: optimize dead_pid_conflict by searching in rbtree

All task are collected in rbtree what allows us to search
any task by a virtual pid for O(n log(n)).
Signed-off-by: 's avatarAndrew Vagin <avagin@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent 018e8985
...@@ -806,36 +806,34 @@ static int dump_linked_remap(char *path, int len, const struct stat *ost, ...@@ -806,36 +806,34 @@ static int dump_linked_remap(char *path, int len, const struct stat *ost,
static pid_t *dead_pids; static pid_t *dead_pids;
static int n_dead_pids; static int n_dead_pids;
static int dead_pid_check_threads(struct pstree_item *item, pid_t pid) int dead_pid_conflict(void)
{ {
int i; int i;
for (i = 0; i < item->nr_threads; i++) { for (i = 0; i < n_dead_pids; i++) {
/* struct pid *node;
* If the dead PID was given to a main thread of another pid_t pid = dead_pids[i];
* process, this is handled during restore.
*/
if (item->pid.real == item->threads[i].real ||
item->threads[i].virt != pid)
continue;
pr_err("Conflict with a dead task with the same PID as of this thread (virt %d, real %d).\n", node = pstree_pid_by_virt(pid);
item->threads[i].virt, item->threads[i].real); if (!node)
return 1; continue;
}
return 0; if (node->state != TASK_THREAD) {
} struct pstree_item *item;
int dead_pid_conflict(void) /*
{ * If the dead PID was given to a main thread of another
struct pstree_item *item; * process, this is handled during restore.
int i; */
item = container_of(node, struct pstree_item, pid);
if (item->pid.real == item->threads[i].real ||
item->threads[i].virt != pid)
continue;
}
for (i = 0; i < n_dead_pids; i++) { pr_err("Conflict with a dead task with the same PID as of this thread (virt %d, real %d).\n",
for_each_pstree_item(item) node->virt, node->real);
if (dead_pid_check_threads(item, dead_pids[i])) return -1;
return 1;
} }
return 0; return 0;
......
...@@ -68,6 +68,7 @@ extern void init_pstree_helper(struct pstree_item *ret); ...@@ -68,6 +68,7 @@ extern void init_pstree_helper(struct pstree_item *ret);
extern struct pstree_item *lookup_create_item(pid_t pid); extern struct pstree_item *lookup_create_item(pid_t pid);
extern void pstree_insert_pid(pid_t pid, struct pid *pid_node); extern void pstree_insert_pid(pid_t pid, struct pid *pid_node);
extern struct pid *pstree_pid_by_virt(pid_t pid);
extern struct pstree_item *root_item; extern struct pstree_item *root_item;
extern struct pstree_item *pstree_item_next(struct pstree_item *item); extern struct pstree_item *pstree_item_next(struct pstree_item *item);
......
...@@ -430,7 +430,7 @@ struct pstree_item *lookup_create_item(pid_t pid) ...@@ -430,7 +430,7 @@ struct pstree_item *lookup_create_item(pid_t pid)
return container_of(node, struct pstree_item, pid); return container_of(node, struct pstree_item, pid);
} }
static struct pid *pstree_pid_by_virt(pid_t pid) struct pid *pstree_pid_by_virt(pid_t pid)
{ {
struct rb_node *node = pid_root_rb.rb_node; struct rb_node *node = pid_root_rb.rb_node;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment