Skip to content

ci: Improve daemonisation by closing only open FDs#309

Open
aarontomlin wants to merge 1 commit intoXilinx-CNS:masterfrom
aarontomlin:atomlin-ci-Improve-daemonisation-by-closing-only-open-FDs
Open

ci: Improve daemonisation by closing only open FDs#309
aarontomlin wants to merge 1 commit intoXilinx-CNS:masterfrom
aarontomlin:atomlin-ci-Improve-daemonisation-by-closing-only-open-FDs

Conversation

@aarontomlin
Copy link
Copy Markdown

@aarontomlin aarontomlin commented Nov 23, 2025

The ci_server_daemonise() function previously closed file descriptors by iterating from STDERR_FILENO + 1 up to the process's maximum limit (i.e., RLIMIT_NOFILE). This method is very inefficient when the file descriptor limit is very high; calling the close() system call a number of times for non-existent descriptors.

This patch replaces the loop with a call to close_extra_fds(). This new function reads /proc/self/fd to identify and close only the applicable file descriptors currently open in the process.

This provides a significant performance gain during daemonisation, especially on systems configured with large default file descriptor limits. If /proc is not available then revert back to the previously implementation i.e., iterating from file descriptors 3 to the value returned by getrlimit() for RLIMIT_NOFILE.

@aarontomlin aarontomlin requested a review from a team as a code owner November 23, 2025 03:25
The ci_server_daemonise() function previously closed file descriptors by
iterating from STDERR_FILENO + 1 up to the process's maximum limit
(i.e., RLIMIT_NOFILE). This method is very inefficient when the file
descriptor limit is very high; calling the close() system call a
number of times for non-existent descriptors.

This patch replaces the loop with a call to close_extra_fds().
This new function reads /proc/self/fd to identify and close only the
applicable file descriptors currently open in the process.

This provides a significant performance gain during daemonisation,
especially on systems configured with large default file descriptor
limits. If /proc is not available then revert back to the previously
implementation i.e., iterating from file descriptors 3 to the value
returned by getrlimit() for RLIMIT_NOFILE.

Signed-off-by: Aaron Tomlin <atomlin@atomlin.com>
@aarontomlin aarontomlin force-pushed the atomlin-ci-Improve-daemonisation-by-closing-only-open-FDs branch from 73dc236 to aa2c592 Compare November 26, 2025 19:29
@aarontomlin
Copy link
Copy Markdown
Author

@ol-alexandra see the latest changes.

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