[PATCH] io: Refactor {n}ftw to use fts for stack safety and conformance (BZ 33882)
Collin Funk
collin.funk1@gmail.com
Fri Feb 13 22:14:07 GMT 2026
Adhemerval Zanella Netto <adhemerval.zanella@linaro.org> writes:
>
> However it does way better memory usage for the pathological cases. Using the
> nested 5000 directories from tst-nftw-bz33882 massif for master shows:
[...]
> And I do not if we can implement a feasible {n}ftw with recursion *without*
> imposing some path limits (which is an arbitrary limits that conflict with the
> GNU Coding Standards).
>
> Maybe we can optimize it better by reimplement a FTS without some extra
> requirement, but this will also duplicate code.
FWIW, my opinion is that the ability to visit arbitrary depths is more
important than the performance here.
Gnulib uses a slightly modified implementation of fts, e.g., it uses
openat and avoids f?chdir, but both versions manage memory very
efficiently and can visit arbitrary depths. This is quite important for
GNU coreutils, for obvious reasons. Other implementations tend to impose
arbitrary limits and/or overflow the stack.
Collin
More information about the Libc-alpha
mailing list