Commit fe5a5ba2 authored by Pavel Emelyanov's avatar Pavel Emelyanov

pstree: Relax parent finding fast path

When we didn't have tree with pids, the search for parent
item was optimized. Nowadays we can just use one rbtree
lookup.
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Acked-by: 's avatarAndrew Vagin <avagin@virtuozzo.com>
parent 7bce51f6
......@@ -474,7 +474,7 @@ static int read_pstree_image(void)
{
int ret = 0, i;
struct cr_img *img;
struct pstree_item *pi, *parent = NULL;
struct pstree_item *pi;
pr_info("Reading image tree\n");
......@@ -520,37 +520,22 @@ static int read_pstree_image(void)
root_item = pi;
pi->parent = NULL;
} else {
/*
* Fast path -- if the pstree image is not edited, the
* parent of any item should have already being restored
* and sit among the last item's ancestors.
*/
while (parent) {
if (parent->pid.virt == e->ppid)
break;
parent = parent->parent;
}
if (parent == NULL) {
for_each_pstree_item(parent) {
if (parent->pid.virt == e->ppid)
break;
}
struct pid *pid;
struct pstree_item *parent;
if (parent == NULL) {
pid = pstree_pid_by_virt(e->ppid);
if (!pid || pid->state == TASK_UNDEF || pid->state == TASK_THREAD) {
pr_err("Can't find a parent for %d\n", pi->pid.virt);
pstree_entry__free_unpacked(e, NULL);
xfree(pi);
goto err;
}
}
parent = container_of(pid, struct pstree_item, pid);
pi->parent = parent;
list_add(&pi->sibling, &parent->children);
}
parent = pi;
pi->nr_threads = e->n_threads;
pi->threads = xmalloc(e->n_threads * sizeof(struct pid));
if (!pi->threads)
......
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