miztake / certmonger

Forked from certmonger 4 years ago
Clone

9bbb628 Optimize closing open file descriptors

Authored and Committed by rcritten 4 years ago
1 file changed. 62 lines added. 9 lines removed.
    Optimize closing open file descriptors
    
    When forking, the code would close all unused file descriptors up
    to maximum number of files. In the default case this is 1024. In
    the container case this is 1048576. Huge delays in startup were
    seen due to this.
    
    Even in a default 1024 ulimit case this drastically reduces the
    number of file descriptors to mark FD_CLOEXEC but in the container
    default case this saves another order of magnitude of work.
    
    This patch takes inspiration from systemd[1] and walks /proc/self/fd
    if it is available to determine the list of open descriptors. It
    falls back to the "close all fds we don't care about up to limit"
    method.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1656519
    
    [1] https://github.com/systemd/systemd/blob/5238e9575906297608ff802a27e2ff9effa3b338/src/basic/fd-util.c#L217
    
        
file modified
+62 -9