<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Fri, Aug 3, 2018 at 10:11 AM Kirill Tkhai &lt;<a href="mailto:ktkhai@virtuozzo.com">ktkhai@virtuozzo.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi, Radoslaw,<br>
<br>
On 02.08.2018 13:58, Radoslaw Burny wrote:<br>
&gt; Since the processes and fds are restored from images in the increasing<br>
&gt; order, and they are stored in sorted lists, CRIU always needed (at least<br>
&gt; in my experiments) to traverse the whole list before inserting them.<br>
&gt; With this change, lists are traversed in reverse, so the fds should be<br>
&gt; inserted immediately.<br>
&gt; <br>
&gt; Signed-off-by: Radoslaw Burny &lt;<a href="mailto:rburny@google.com" target="_blank">rburny@google.com</a>&gt;<br>
&gt; ---<br>
&gt;  criu/files.c       | 12 ++++++------<br>
&gt;  criu/include/pid.h |  5 +++++<br>
&gt;  2 files changed, 11 insertions(+), 6 deletions(-)<br>
&gt; <br>
&gt; diff --git a/criu/files.c b/criu/files.c<br>
&gt; index 4ed84305..ea41f59e 100644<br>
&gt; --- a/criu/files.c<br>
&gt; +++ b/criu/files.c<br>
&gt; @@ -140,12 +140,12 @@ static void collect_task_fd(struct fdinfo_list_entry *new_fle, struct rst_info *<br>
&gt;       struct fdinfo_list_entry *fle;<br>
&gt;  <br>
&gt;       /* fles in fds list are ordered by fd */<br>
&gt; -     list_for_each_entry(fle, &amp;ri-&gt;fds, ps_list) {<br>
&gt; -             if (new_fle-&gt;fe-&gt;fd &lt; fle-&gt;fe-&gt;fd)<br>
&gt; +     list_for_each_entry_reverse(fle, &amp;ri-&gt;fds, ps_list) {<br>
&gt; +             if (fle-&gt;fe-&gt;fd &lt; new_fle-&gt;fe-&gt;fd)<br>
&gt;                       break;<br>
&gt;       }<br>
&gt;  <br>
&gt; -     list_add_tail(&amp;new_fle-&gt;ps_list, &amp;fle-&gt;ps_list);<br>
&gt; +     list_add(&amp;new_fle-&gt;ps_list, &amp;fle-&gt;ps_list);<br>
<br>
Looks OK. Could you add a small comment, that reverse traverse is faster<br>
since we keep fles ordered im images?<br>
<br></blockquote><div><br></div><div>Sure, done. I&#39;ll send a new version of the patch in a minute.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
&gt;  }<br>
&gt;  <br>
&gt;  unsigned int find_unused_fd(struct pstree_item *task, int hint_fd)<br>
&gt; @@ -785,10 +785,10 @@ static void __collect_desc_fle(struct fdinfo_list_entry *new_le, struct file_des<br>
&gt;  {<br>
&gt;       struct fdinfo_list_entry *le;<br>
&gt;  <br>
&gt; -     list_for_each_entry(le, &amp;fdesc-&gt;fd_info_head, desc_list)<br>
&gt; -             if (pid_rst_prio(new_le-&gt;pid, le-&gt;pid))<br>
&gt; +     list_for_each_entry_reverse(le, &amp;fdesc-&gt;fd_info_head, desc_list)<br>
&gt; +             if (pid_rst_prio_eq(le-&gt;pid, new_le-&gt;pid))<br>
<br>
Two fle with equal pids are bug in this place, aren&#39;t they?<br>
I&#39;d added direct BUG() for that.<br>
<br></blockquote><div><br></div><div>Actually, I have seen the same (fd, pid) pair appear twice when the process had</div><div>stdin &amp; stdout redirected to /dev/null, and /dev/null was injected through  --inherit-fd.</div><div>(I&#39;m not sure if --inherit-fd is necessary to trigger this scenario)</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
&gt;                       break;<br>
&gt; -     list_add_tail(&amp;new_le-&gt;desc_list, &amp;le-&gt;desc_list);<br>
&gt; +     list_add(&amp;new_le-&gt;desc_list, &amp;le-&gt;desc_list);<br>
&gt;  }<br>
&gt;  <br>
&gt;  static void collect_desc_fle(struct fdinfo_list_entry *new_le,<br>
&gt; diff --git a/criu/include/pid.h b/criu/include/pid.h<br>
&gt; index 81786ec4..c749176f 100644<br>
&gt; --- a/criu/include/pid.h<br>
&gt; +++ b/criu/include/pid.h<br>
&gt; @@ -54,4 +54,9 @@ static inline bool pid_rst_prio(unsigned pid_a, unsigned pid_b)<br>
&gt;       return pid_a &lt; pid_b;<br>
&gt;  }<br>
&gt;  <br>
&gt; +static inline bool pid_rst_prio_eq(unsigned pid_a, unsigned pid_b)<br>
&gt; +{<br>
&gt; +     return pid_a &lt;= pid_b;<br>
&gt; +}<br>
&gt; +<br>
&gt;  #endif /* __CR_PID_H__ */<br>
<br>
Thanks,<br>
Kirill<br>
</blockquote></div></div>