Skip to content

chmod:fix file descriptor limits issue#9595

Open
mattsu2020 wants to merge 11 commits intouutils:mainfrom
mattsu2020:chmod_FD_fix
Open

chmod:fix file descriptor limits issue#9595
mattsu2020 wants to merge 11 commits intouutils:mainfrom
mattsu2020:chmod_FD_fix

Conversation

@mattsu2020
Copy link
Contributor

As mentioned in the comment below, it hits the file descriptor limit.

#9554 (comment)

Make adjustments to reduce the use of FD.

@github-actions
Copy link

github-actions bot commented Dec 7, 2025

GNU testsuite comparison:

Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)

@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/sort/sort-stale-thread-mem. tests/sort/sort-stale-thread-mem is passing on 'main'. Maybe you have to rebase?

@uutils uutils deleted a comment from github-actions bot Dec 26, 2025
@uutils uutils deleted a comment from github-actions bot Dec 26, 2025
@github-actions
Copy link

github-actions bot commented Jan 5, 2026

GNU testsuite comparison:

GNU test failed: tests/tty/tty-eof. tests/tty/tty-eof is passing on 'main'. Maybe you have to rebase?

@github-actions
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/stty/bad-speed is now passing!

@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/shuf/shuf-reservoir (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/sort/sort-stale-thread-mem (passes in this run but fails in the 'main' branch)

1 similar comment
@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/shuf/shuf-reservoir (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/sort/sort-stale-thread-mem (passes in this run but fails in the 'main' branch)


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())];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you look at the impact on the memory ?

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 15, 2026

Merging this PR will not alter performance

✅ 162 untouched benchmarks
🆕 2 new benchmarks
⏩ 160 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
🆕 Memory chmod_recursive_wide_tree[(2000, 200)] N/A 191.9 KB N/A
🆕 Memory chmod_recursive_deep_tree[(200, 2)] N/A 50.2 KB N/A

Comparing mattsu2020:chmod_FD_fix (9d0efb9) with main (54566dd)

Open in CodSpeed

Footnotes

  1. 160 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.

@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)

@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tty/tty-eof (fails in this run but passes in the 'main' branch)

@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/shuf/shuf-reservoir (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/sort/sort-stale-thread-mem (passes in this run but fails in the 'main' branch)

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.
@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/factor/t10. tests/factor/t10 is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/factor/t33. tests/factor/t33 is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/factor/t34. tests/factor/t34 is passing on 'main'. Maybe you have to rebase?
Skipping an intermittent issue tests/tty/tty-eof (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/tail/pipe-f is now being skipped but was previously passing.
Congrats! The gnu test tests/cut/cut-huge-range is now passing!
Congrats! The gnu test tests/rm/many-dir-entries-vs-OOM is now passing!

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
@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/factor/t10. tests/factor/t10 is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/tail/symlink (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/pr/bounded-memory is no longer failing!
Note: The gnu test tests/dd/no-allocate is now being skipped but was previously passing.
Note: The gnu test tests/printf/printf-surprise is now being skipped but was previously passing.
Congrats! The gnu test tests/cut/cut-huge-range is now passing!
Congrats! The gnu test tests/rm/many-dir-entries-vs-OOM is now passing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants