-
-
Notifications
You must be signed in to change notification settings - Fork 818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Heavy resource usage with "--follow" flag and /sys #378
Comments
Thank you very much for the detailed bug report. I can reproduce this.
I am pretty sure this is the case. It's not just an explosion of the number of symlinks. There are loops, too.
Interestingly,
Still, even with these checks in place, In principle (as I understand it), loops should be detected by the
So something must be different inside |
This is just
I don't believe there is much special about /sys except for symlinks that point back up the tree very high, and high fanout. Cycle detection in
so /sys seems to have a similar thing going on with traversals like
|
Something that might be nice is a "visit files only once" mode, that remembers which files (by identity, i.e. st_dev/st_ino pair on *nix) have already been seen. |
There's some discussion about that in #318 |
I have been thinking about this for some time. I currently don't want to implement a "visit files only once" mode, as it would require proper synchronization across threads with a global set of visited device/inode pairs (on Unix. No idea about Windows). This would (1) increase code complexity and (2) might have a performance impact, as the global set has to be managed on the receiver side (in a single thread). However, if someone wants to experiment with this, I have an implementation of this exact concept in https://github.com/sharkdp/diskus/ A much simpler (but also more "hacky") solution would be the following: Let's assume that it is very unlikely that someone wants to find something within |
It looks like this has been resolved in v7.5.0 for some (yet unknown) reason: ❯ /usr/bin/time -f "%M" fd-v7.4.0 --follow --max-depth 8 non-existing /sys
741792
❯ /usr/bin/time -f "%M" fd-v7.5.0 --follow --max-depth 8 non-existing /sys
7600 Timing is still the same though:
|
Since it's no longer hogging up all my ram and causing the system to crash when I run the command I consider this fixed 🙂 |
I actually looked into this a bit and it seems to be another instance of an unexpected performance If I compile
If I compile it with Rust 1.36 or newer, I get this:
Rust 1.36 introduced some changes concerning memory management, so this seems plausible at least (https://blog.rust-lang.org/2019/07/04/Rust-1.36.0.html). But I have no idea what exactly caused the previous memory consumption. |
If I run
fd --follow something /
(on Linux) fd will use 100% of my CPU and slowly allocate more and more ram until the system runs out and stops responding (unless I kill fd).Killing fd after a few minutes frees a ton of ram:
Other details
fd --follow --hidden something ~
causes it too, if the user has installed Wine, since that creates a symlinks to/
from.wine/dosdevices/z:
.--follow
it only takes a second/sys
(but not/proc
) it completes in ~10 seconds.821,92s user 1006,11s system 819% cpu 3:42,93 total
). Ram allocation peaks about halfway, and then starts freeing up ram.--threads 1
(on a system with 8 vcores) oddly makes it run significantly faster 😮 ~2:30m (78,85s user 99,34s system 119% cpu 2:29,18 total
). It peaks at about the same amount of RAM though.I'm using fd 7.2.0 and
/proc
isn't the problem, so this isn't #288, though the symptoms are nearly identical. Maybe the very large number of symlinks in /sys is the problem (symlinks to folders containing symlinks to folders to ...), causing an even much larger number of full paths that the ignore crate needs to store? Maybe this warrants gigabytes of ram allocated?I'm not sure if this is to be considered a bug or just an unfortunate combination, but since the outcome is quite serious I thought it deserved it's own issue.
The text was updated successfully, but these errors were encountered: