<div dir="ltr"><div dir="auto" style="word-wrap:break-word">Replace miss typing va-&gt;va_start &gt; tmp_va-&gt;va_start and va-&gt;va_end &lt; tmp_va-&gt;va_end<div>with va-&gt;va_start &gt; tmp_va-&gt;va_end and va-&gt;va_end &lt; tmp_va-&gt;va_start.</div><div>It ensures va and tmp never overlap.</div><div><br><div style="direction:ltr"><blockquote type="cite"><div>On Sep 4, 2016, at 9:29 PM, Peng Gao &lt;<a href="mailto:peng.gao.dut@gmail.com" target="_blank">peng.gao.dut@gmail.com</a>&gt; wrote:</div><br><div><div>I am browsing the code <br><br>static void __insert_vmap_area(struct vmap_area *va)<br>{<br><span style="white-space:pre-wrap">        </span>struct rb_node **p = &amp;vmap_area_root.rb_node;<br><span style="white-space:pre-wrap">        </span>struct rb_node *parent = NULL;<br><span style="white-space:pre-wrap">        </span>struct rb_node *tmp;<br><br><span style="white-space:pre-wrap">        </span>while (*p) {<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>struct vmap_area *tmp_va;<br><br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>parent = *p;<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>tmp_va = rb_entry(parent, struct vmap_area, rb_node);<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>if (va-&gt;va_start &lt; tmp_va-&gt;va_end)<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>p = &amp;(*p)-&gt;rb_left;<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>else if (va-&gt;va_end &gt; tmp_va-&gt;va_start)<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>p = &amp;(*p)-&gt;rb_right;<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>else<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>BUG();<br><span style="white-space:pre-wrap">        </span>}<br><br><span style="white-space:pre-wrap">        </span>rb_link_node(&amp;va-&gt;rb_node, parent, p);<br><span style="white-space:pre-wrap">        </span>rb_insert_color(&amp;va-&gt;rb_node, &amp;vmap_area_root);<br><br><span style="white-space:pre-wrap">        </span>/* address-sort this list */<br><span style="white-space:pre-wrap">        </span>tmp = rb_prev(&amp;va-&gt;rb_node);<br><span style="white-space:pre-wrap">        </span>if (tmp) {<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>struct vmap_area *prev;<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>prev = rb_entry(tmp, struct vmap_area, rb_node);<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>list_add_rcu(&amp;va-&gt;list, &amp;prev-&gt;list);<br><span style="white-space:pre-wrap">        </span>} else<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>list_add_rcu(&amp;va-&gt;list, &amp;vmap_area_list);<br>}<br><br>As far as I can know map_area is a range for the vmalloc to alloc non-contigious memory, which confuses me is that why not use va-&gt;va_start &gt; tmp_va-&gt;va_start and va-&gt;va_end &lt; tmp_va-&gt;va_end to insert a new vmap_area. Can a virtual address mapping overlap?<br><br>One more question<br><br>In alloc_map_area, I found this part of code.<br><br><span style="white-space:pre-wrap">        </span>/* from the starting point, walk areas until a suitable hole is found */<br><span style="white-space:pre-wrap">        </span>while (addr + size &gt; first-&gt;va_start &amp;&amp; addr + size &lt;= vend) {<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>if (addr + cached_hole_size &lt; first-&gt;va_start) /* cached_hole_size */<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>cached_hole_size = first-&gt;va_start - addr;<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>addr = ALIGN(first-&gt;va_end, align);<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>if (addr + size &lt; addr)<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>goto overflow;<br><br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>if (list_is_last(&amp;first-&gt;list, &amp;vmap_area_list))<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>goto found;<br><br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>first = list_next_entry(first, list);<br><span style="white-space:pre-wrap">        </span>}<br><br>It seems like just inert a map_area at the end of list, what dose suitable hole means? <br>Why not add this?<br><br>if(addr+size &lt; first-&gt;va_start) <br><span style="white-space:pre-wrap">        </span>goto notound <br><br></div></div></blockquote></div><br></div></div></div>