chmod:fix file descriptor limits issue#9595
Open
mattsu2020 wants to merge 11 commits intouutils:mainfrom
Open
Conversation
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
1 similar comment
|
GNU testsuite comparison: |
sylvestre
reviewed
Jan 13, 2026
src/uu/chmod/src/chmod.rs
Outdated
|
|
||
| let entries = dir_fd.read_dir()?; | ||
| // Depth-first traversal without recursive calls to avoid stacking FDs. | ||
| let mut stack: Vec<(DirFd, PathBuf)> = vec![(dir_fd, dir_path.to_path_buf())]; |
Contributor
There was a problem hiding this comment.
did you look at the impact on the memory ?
Merging this PR will not alter performance
Performance Changes
Comparing Footnotes
|
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
Replace recursive safe_traverse_dir with iterative depth-first search using a stack to prevent file descriptor exhaustion during deep directory hierarchies. Also collect read_dir entries upfront to release the directory iterator early, reducing resource usage.
Use rlimit crate's .limit() method instead of manual libc rlimit calls for constraining NOFILE. This cleans up the test code and leverages existing utilities in the rlimit crate. Additionally, optimize import by using PathBuf directly from std::path.
… chown executors Use match expressions for metadata retrieval to improve readability and reduce nesting. Hoist variable declarations for better scope management in ChownExecutor. These changes enhance code clarity without altering functionality.
Add dev-dependencies (divan, tempfile, uucore with benchmark features) and a bench target for chmod_bench to enable performance benchmarking. This allows measuring and optimizing the chmod utility's efficiency.
- Added uu_chmod to the list of packages in the benchmarks workflow matrix to include it in performance testing alongside other utilities.
…trlimit calls Wrap System allocator method calls (alloc, dealloc, realloc) and getrlimit in explicit unsafe blocks to satisfy Rust safety requirements and potential linting rules, improving code clarity in the benchmark file.
Reorder divan and uucore::libc imports to alphabetical order for improved code consistency and readability.
Replace `&mut lim as *mut _` with `&raw mut lim` to use the newer, more explicit Rust syntax for creating raw mutable pointers. This improves code clarity and aligns with modern Rust idioms.
d5cf925 to
dd0f7f4
Compare
|
GNU testsuite comparison: |
Replace per-directory file descriptors with a single root descriptor and relative path chains. This change eliminates the need to keep multiple directory file descriptors open simultaneously during recursive traversal, reducing resource consumption and potential file descriptor exhaustion in deep directory trees. The new approach uses `open_subdir_chain()` to open subdirectories on-demand from the root descriptor.
- Replaced format! macro with string interpolation in chmod_bench.rs for cleaner code - Updated test_chmod.rs to use string interpolation instead of format! macro - Both changes improve readability while maintaining identical functionality
|
GNU testsuite comparison: |
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.
As mentioned in the comment below, it hits the file descriptor limit.
#9554 (comment)
Make adjustments to reduce the use of FD.