<div dir="ltr">I don't understand why re-using the context struct(<50 bytes) helps prevent stack overflow, when the current implementation of <span style="color:rgb(0,128,0);font-family:monospace;font-size:13.3333px;white-space:pre">erofs_iterate_dir</span> holds a 4096 bytes buffer on stack. If is <span style="color:rgb(0,128,0);font-family:monospace;font-size:13.3333px;white-space:pre">erofs_iterate_dir </span>called recursively, it's probably the <span style="color:rgb(0,128,0);font-family:monospace;font-size:13.3333px;white-space:pre">char buf[EROFS_BLKSIZ];</span> who's using up stack space.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Dec 17, 2021 at 7:36 PM Gao Xiang <<a href="mailto:hsiangkao@linux.alibaba.com">hsiangkao@linux.alibaba.com</a>> 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 Kelvin,<br>
<br>
On Fri, Dec 17, 2021 at 02:54:09PM -0500, Kelvin Zhang wrote:<br>
> Hi Gao,<br>
>     I drafted a new patchset on top of the dev branch. Changes since v6:<br>
> <br>
>     1. block buffer moved to the heap, due to stack size concerns when<br>
> iterating recursively<br>
>     2. Added a "recursive" option to input parameters<br>
>     3. dname buffers are still on the heap, but allocation is done once per<br>
> directory, instead of once for each directory entry.<br>
>     4. Added a void* arg which will be forwarded to the callback function.<br>
> <br>
> I ran scripts/<a href="http://checkpatch.pl" rel="noreferrer" target="_blank">checkpatch.pl</a> . Hopefully this makes your life easier. Thanks<br>
> for the reply!.<br>
> <br>
> <br>
<br>
Many thanks for your reply! I plan to take the patches in the<br>
experimental branch.<br>
<br>
The reason was written in include/erofs/dir.h:<br>
<a href="https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/tree/include/erofs/dir.h?h=experimenta" rel="noreferrer" target="_blank">https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/tree/include/erofs/dir.h?h=experimenta</a><br>
<br>
 erofs_dir_context can be allocated on heap (in summary, by<br>
 the caller) and chain together in order to avoid recursion<br>
 totally later. I think it should benefit Android scenario to<br>
 avoid stack overflow due to deep level as well.<br>
<br>
Also Igor Eisberg sent a patch for a new get_pathname in the<br>
erofs_dir_context reuse way:<br>
 <a href="https://lore.kernel.org/linux-erofs/CABjEcnE84FNBgiHFk6Q+V3d-4L-93bUFDkdfN4ftPX19kpC=ww@mail.gmail.com/" rel="noreferrer" target="_blank">https://lore.kernel.org/linux-erofs/CABjEcnE84FNBgiHFk6Q+V3d-4L-93bUFDkdfN4ftPX19kpC=ww@mail.gmail.com/</a><br>
<br>
I plan to polish and apply them as well.<br>
<br>
Thanks,<br>
Gao Xiang<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr">Sincerely,<div><br></div><div>Kelvin Zhang</div></div></div>