[Patch] PR 31228, Fix close-on-exec race.

David Daney ddaney@avtrex.com
Fri Mar 23 00:12:00 GMT 2007


Andrew Haley wrote:
> David Daney writes:
>  > Andrew Haley wrote:
>  > > David Daney writes:
>  
>  > >  > How about this version?
>  > >
>  > > This is impressively heroic, but I really think you should measure the
>  > > performance improvement before committing this.  :-)
>  >
>  > Hard data takes the fun out of things :-(
>
> Haha!  I am *such* a scientist!  :-)
>
>  > What does all this mean?  Well on my x86_64-pc-linux-gnu notebook,
>  > it takes about 1 second to close 10,000,000 times an invalid file
>  > descriptor.  The savings of only closing open files would appear to
>  > make sense only if the default ulimit -n value is raised to a value
>  > greater than about 3000.
>  > 
>  > The only reason to increase ulimit -n, from its default value of
>  > 1024, is if you expect to have a lot of open files.  In this case
>  > This is all moot as the time to close the open files would be much
>  > greater than the overhead of closing invalid descriptors.
>  > 
>  > So if we want to fix the bug, I would recommend my original patch.
>
> Yeah, we want to fix the bug.  This is OK.
>
> Andrew.
>   
Attached is what I ended up committing.

The only difference from the original patch is that I use the rlim_max 
value instead of the flim_cur value.  This will yield the same result 
unless someone has been doing funny things with the limit.  In which 
case we should use the rlim_max value in case there are any vestigial 
descriptors left open above the current limit.

Tested on x86_64-pc-linux-gnu (FC6) with no regressions found.

2007-03-22  David Daney  <ddaney@avtrex.com>

    PR libgcj/31228
    * configure.ac: Add checks for getrlimit and sys/resource.h.
    * include/posix.h (_Jv_platform_close_on_exec): Remove.
    * include/config.h.in: Regenerate.
    * configure: Regenerate.
    * gnu/java/nio/channels/natFileChannelPosix.cc (open): Remove call to
    _Jv_platform_close_on_exec;
    * gnu/java/net/natPlainSocketImplPosix.cc (create): Likewise.
    (accept): Likewise.
    * gnu/java/net/natPlainDatagramSocketImplPosix.cc (create):Likewise.
    * java/lang/natPosixProcess.cc: Include sys/resource.h.
    (nativeSpawn): Close all file descriptors.  Don't set FD_CLOEXEC on
    pipes.


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: closeall.diff.txt
URL: <http://gcc.gnu.org/pipermail/java-patches/attachments/20070323/e147d06d/attachment.txt>


More information about the Java-patches mailing list