-
Notifications
You must be signed in to change notification settings - Fork 90
Open
Description
Background:
- https://www.phoronix.com/scan.php?page=news_item&px=Linux-5.9-Close-Range
- https://lwn.net/Articles/789023/
As written in
process/System/Process/Common.hs
Line 91 in cb1d1a6
| close_fds :: Bool, -- ^ Close all file descriptors except stdin, stdout and stderr in the new process (on Windows, only works if std_in, std_out, and std_err are all Inherit). This implementation will call close an every fd from 3 to the maximum of open files, which can be slow for high maximum of open files. |
This implementation will call
close()an every fd from 3 to the maximum of open files, which can be slow for high maximum of open files.
The new close_range() syscall solves this, closing them all in 1 go. According to the LWN link, it is very fast, and you can give it MAXINT.
The code that needs to be augmented (with CPP):
process/cbits/posix/runProcess.c
Lines 255 to 273 in cb1d1a6
| if (close_fds) { | |
| int i; | |
| if (max_fd == 0) { | |
| #if HAVE_SYSCONF | |
| max_fd = sysconf(_SC_OPEN_MAX); | |
| if (max_fd == -1) { | |
| max_fd = 256; | |
| } | |
| #else | |
| max_fd = 256; | |
| #endif | |
| } | |
| // XXX Not the pipe | |
| for (i = 3; i < max_fd; i++) { | |
| if (i != forkCommunicationFds[1]) { | |
| close(i); | |
| } | |
| } | |
| } |
Metadata
Metadata
Assignees
Labels
No labels