Commit 68239003 authored by Radoslaw Burny's avatar Radoslaw Burny Committed by Andrei Vagin

Fix O(n^2) restore in terms of the number of fds.

Since the processes and fds are restored from images in the increasing
order, and they are stored in sorted lists, CRIU always needed (at least
in my experiments) to traverse the whole list before inserting them.
With this change, lists are traversed in reverse, so the fds should be
inserted immediately.
Acked-by: 's avatarKirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: 's avatarRadoslaw Burny <rburny@google.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent a4c9efe1
...@@ -139,13 +139,17 @@ static void collect_task_fd(struct fdinfo_list_entry *new_fle, struct rst_info * ...@@ -139,13 +139,17 @@ static void collect_task_fd(struct fdinfo_list_entry *new_fle, struct rst_info *
{ {
struct fdinfo_list_entry *fle; struct fdinfo_list_entry *fle;
/* fles in fds list are ordered by fd */ /*
list_for_each_entry(fle, &ri->fds, ps_list) { * fles in fds list are ordered by fd. Fds are restored from img files
if (new_fle->fe->fd < fle->fe->fd) * in ascending order, so it is faster to insert them from the end of
* the list.
*/
list_for_each_entry_reverse(fle, &ri->fds, ps_list) {
if (fle->fe->fd < new_fle->fe->fd)
break; break;
} }
list_add_tail(&new_fle->ps_list, &fle->ps_list); list_add(&new_fle->ps_list, &fle->ps_list);
} }
unsigned int find_unused_fd(struct pstree_item *task, int hint_fd) unsigned int find_unused_fd(struct pstree_item *task, int hint_fd)
...@@ -785,10 +789,10 @@ static void __collect_desc_fle(struct fdinfo_list_entry *new_le, struct file_des ...@@ -785,10 +789,10 @@ static void __collect_desc_fle(struct fdinfo_list_entry *new_le, struct file_des
{ {
struct fdinfo_list_entry *le; struct fdinfo_list_entry *le;
list_for_each_entry(le, &fdesc->fd_info_head, desc_list) list_for_each_entry_reverse(le, &fdesc->fd_info_head, desc_list)
if (pid_rst_prio(new_le->pid, le->pid)) if (pid_rst_prio_eq(le->pid, new_le->pid))
break; break;
list_add_tail(&new_le->desc_list, &le->desc_list); list_add(&new_le->desc_list, &le->desc_list);
} }
static void collect_desc_fle(struct fdinfo_list_entry *new_le, static void collect_desc_fle(struct fdinfo_list_entry *new_le,
......
...@@ -54,4 +54,9 @@ static inline bool pid_rst_prio(unsigned pid_a, unsigned pid_b) ...@@ -54,4 +54,9 @@ static inline bool pid_rst_prio(unsigned pid_a, unsigned pid_b)
return pid_a < pid_b; return pid_a < pid_b;
} }
static inline bool pid_rst_prio_eq(unsigned pid_a, unsigned pid_b)
{
return pid_a <= pid_b;
}
#endif /* __CR_PID_H__ */ #endif /* __CR_PID_H__ */
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