From owner-freebsd-hackers@FreeBSD.ORG Fri Jul 6 16:56:53 2007 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 25FDD16A400 for ; Fri, 6 Jul 2007 16:56:53 +0000 (UTC) (envelope-from julian@elischer.org) Received: from outQ.internet-mail-service.net (outQ.internet-mail-service.net [216.240.47.240]) by mx1.freebsd.org (Postfix) with ESMTP id 0F9EC13C48A for ; Fri, 6 Jul 2007 16:56:53 +0000 (UTC) (envelope-from julian@elischer.org) Received: from mx0.idiom.com (HELO idiom.com) (216.240.32.160) by out.internet-mail-service.net (qpsmtpd/0.32) with ESMTP; Fri, 06 Jul 2007 09:56:52 -0700 Received: from julian-mac.elischer.org (home.elischer.org [216.240.48.38]) by idiom.com (Postfix) with ESMTP id 63FBB125B6C; Fri, 6 Jul 2007 09:56:52 -0700 (PDT) Message-ID: <468E7463.8020803@elischer.org> Date: Fri, 06 Jul 2007 09:57:07 -0700 From: Julian Elischer User-Agent: Thunderbird 2.0.0.4 (Macintosh/20070604) MIME-Version: 1.0 To: Robert Watson References: <20070705122650.GE1302@britannica.bec.de> <468E16E6.6030608@delphij.net> <20070706112453.GA3217@hoeg.nl> <468E7007.5050607@elischer.org> <20070706174321.M17956@fledge.watson.org> In-Reply-To: <20070706174321.M17956@fledge.watson.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: FreeBSD Hackers , d@delphij.net, Ed Schouten Subject: Re: add closefrom() call X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Jul 2007 16:56:53 -0000 Robert Watson wrote: > > On Fri, 6 Jul 2007, Julian Elischer wrote: > >> Ed Schouten wrote: >>> * LI Xin wrote: >>>> Here is my implementation for FreeBSD. Some difference between my >>>> and DragonFly's implementation: >>>> >>>> - closefrom(-1) would be no-op on DragonFly, my version would close >>>> all open files (From my understanding of OpenSolaris's userland >>>> implementation, this is Solaris's behavior). >>>> - my version closefrom(very_big_fd) would result in EBADF. I am >>>> not very sure whether this is correct, but it does not hurt for >>>> applications that thinks closefrom() would return void. >>> >>> Wouldn't it be better to just implement it through fcntl() and >>> implement closefrom() in libc? >> >> that's a possibility but I personally thing the huge difference in >> efficiency makes it worth putting it in the kernel. Quite a few >> programs I know of could really help their startup time with this as >> the first thing they do is "close the first 2000 file descriptors. > > The Solaris implementation appears to implement two strategies: > > (1) If procfs is mounted, list the fd directory to get a list of open fds, > then close those by number. > > (2) If procfs is not mounted, query the number of open fds using the > resource > limit interface, then sequentially close until the right number close. > > Hence my question as to whether there's actually a big benefit or not -- > do we think closefrom() is a performance-critical function? It's one of those things where it's so simple to do it that it hardly seems worth arguing about the colour, or even whether colour is spelled color or colour. > > Robert N M Watson > Computer Laboratory > University of Cambridge