On Sun, Dec 19, 2021 at 07:53:00PM -0500, Kelvin Zhang wrote: > I don't understand why re-using the context struct(<50 bytes) helps prevent > stack overflow, when the current implementation of erofs_iterate_dir holds > a 4096 bytes buffer on stack. If is erofs_iterate_dir called recursively, > it's probably the char buf[EROFS_BLKSIZ]; who's using up stack space.
For two reasons, 1) I'd like dir_context totally allocated by callers, rather than introduce another on-stack context, pass together, and long arguments. 2) As I said, there can be a non-recursive version, which has only one level to iterate dir and chain them together in the DFS/BFS approach. Actually I really don't tend to add recursive feature to erofs_iterate_dir(). As for buf[EROFS_BLKSIZ], it can be moved into dir_context with a pointer as well if later needed, so it can be allocated on heap for all recursive versions. I (and Igor Ostapenko) already converts all use cases (fsck, dump, fsck, including get_pathname and Igor's image extraction) to the unique API these days. I do think it can be easily used by Android upgrade use cases As well. btw, I have switched to new ztailpacking feature urgently since I'd really like to get it ready for 5.17 cycle, which is more important to the whole ecosystem for us. Thanks, Gao Xiang
