FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-38061: subprocess uses closefrom() on FreeBSD by vstinner · Pull Request #19697 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .rst  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 4 additions & 0 deletions Doc/whatsnew/3.9.rst
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
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,10 @@ Optimizations
until the main thread handles signals.
(Contributed by Victor Stinner in :issue:`40010`.)

* Optimize the :mod:`subprocess` module on FreeBSD using ``closefrom()``.
(Contributed by Ed Maste, Conrad Meyer, Kyle Evans, Kubilay Kocak and Victor
Stinner in :issue:`38061`.)


Build and C API Changes
=======================
Expand Down
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Optimize the :mod:`subprocess` module on FreeBSD using ``closefrom()``.
A single ``close(fd)`` syscall is cheap, but when ``sysconf(_SC_OPEN_MAX)`` is
high, the loop calling ``close(fd)`` on each file descriptor can take several
milliseconds.

The workaround on FreeBSD to improve performance was to load and mount the
fdescfs kernel module, but this is not enabled by default.

Initial patch by Ed Maste (emaste), Conrad Meyer (cem), Kyle Evans (kevans) and
Kubilay Kocak (koobs):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Can remove this, full credit to Ed, Conrad & Kyle

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Even if you didn't write the patch directly, you helped to get it packaged. Thanks @koobs, you deserved to be credited ;-)

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=242274
8 changes: 7 additions & 1 deletion Modules/_posixsubprocess.c
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
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,15 @@ _close_fds_by_brute_force(long start_fd, PyObject *py_fds_to_keep)
start_fd = keep_fd + 1;
}
if (start_fd <= end_fd) {
#if defined(__FreeBSD__)
/* Any errors encountered while closing file descriptors are ignored */
closefrom(start_fd);
#else
for (fd_num = start_fd; fd_num < end_fd; ++fd_num) {
close(fd_num);
/* Ignore errors */
(void)close(fd_num);
}
#endif
}
}

Expand Down

Back | FazBrowse Home | New Git URL