fix(rm): keep directory FD use O(1) on deep trees#13420
Open
l46983284-cpu wants to merge 4 commits into
Open
Conversation
Recursive rm held one DirFd per nesting level, so deep trees failed with EMFILE under normal NOFILE limits while GNU rm succeeded. Walk directories with an explicit stack, close the parent DirFd before descending, and reopen it from the saved path when returning to unlink. Preserves openat/unlinkat safety and adds a low-NOFILE regression test. Fixes uutils#7995 Signed-off-by: Alex Chen <l46983284@gmail.com>
Signed-off-by: Alex Chen <l46983284@gmail.com>
Merging this PR will degrade performance by 6.11%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Simulation | rm_recursive_tree |
12 ms | 13 ms | -7.69% |
| ❌ | Simulation | complex_relative_date |
137.2 µs | 147.9 µs | -7.21% |
| ❌ | Simulation | du_max_depth_balanced_tree[(6, 4, 10)] |
25.2 ms | 26.1 ms | -3.36% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing l46983284-cpu:fix/rm-deep-tree-emfile (bcda98a) with main (9846eb8)
Footnotes
-
46 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
Flip child_error branch for clippy::if_not_else and reword the doc comment so cspell does not flag EMFILE. Signed-off-by: Alex Chen <l46983284@gmail.com>
Use cargo fmt import order (CI) and else-if chain for clippy if_not_else / collapsible_else_if cleanliness. Signed-off-by: Alex Chen <l46983284@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
rm -ron a very deep directory tree fails withToo many open files(EMFILE) while GNUrmsucceeds. Recursive safe traversal kept oneDirFdopen per nesting level, so FD use grew with depth.This change walks the tree with an explicit stack, closes the parent directory descriptor before descending, and reopens it from the saved path when returning to unlink the child.
openat/unlinkatsafety is preserved; open-file use stays O(1) with depth.Test plan
cargo build -p uu_rm --releaseprlimit --nofile=32removes successfullytests/by-util/test_rm.rsincluding newtest_rm_recursive_deep_tree_low_nofile(NOFILE=32, depth 80)Fixes #7995