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) ...@@ -474,7 +474,7 @@ static int read_pstree_image(void)
{ {
int ret = 0, i; int ret = 0, i;
struct cr_img *img; struct cr_img *img;
struct pstree_item *pi, *parent = NULL; struct pstree_item *pi;
pr_info("Reading image tree\n"); pr_info("Reading image tree\n");
...@@ -520,37 +520,22 @@ static int read_pstree_image(void) ...@@ -520,37 +520,22 @@ static int read_pstree_image(void)
root_item = pi; root_item = pi;
pi->parent = NULL; pi->parent = NULL;
} else { } else {
/* struct pid *pid;
* Fast path -- if the pstree image is not edited, the struct pstree_item *parent;
* 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;
}
if (parent == NULL) { pid = pstree_pid_by_virt(e->ppid);
pr_err("Can't find a parent for %d\n", pi->pid.virt); if (!pid || pid->state == TASK_UNDEF || pid->state == TASK_THREAD) {
pstree_entry__free_unpacked(e, NULL); pr_err("Can't find a parent for %d\n", pi->pid.virt);
xfree(pi); pstree_entry__free_unpacked(e, NULL);
goto err; xfree(pi);
} goto err;
} }
parent = container_of(pid, struct pstree_item, pid);
pi->parent = parent; pi->parent = parent;
list_add(&pi->sibling, &parent->children); list_add(&pi->sibling, &parent->children);
} }
parent = pi;
pi->nr_threads = e->n_threads; pi->nr_threads = e->n_threads;
pi->threads = xmalloc(e->n_threads * sizeof(struct pid)); pi->threads = xmalloc(e->n_threads * sizeof(struct pid));
if (!pi->threads) 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