From owner-svn-src-all@FreeBSD.ORG Tue Jun 12 10:47:59 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 78D82106564A; Tue, 12 Jun 2012 10:47:59 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: from mail-yx0-f182.google.com (mail-yx0-f182.google.com [209.85.213.182]) by mx1.freebsd.org (Postfix) with ESMTP id D68C08FC1A; Tue, 12 Jun 2012 10:47:58 +0000 (UTC) Received: by yenl8 with SMTP id l8so3715303yen.13 for ; Tue, 12 Jun 2012 03:47:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=RX9d/y3TyMBU602XhWcCQuyMwBvcewMlhz5raU2j1J8=; b=yUBhYcJz2m/AqwMBBododzsIlQhLfWuF3Ak4baC92HOESWDBrKpmNdqHS43kT1Pvog SEoL1LacS7OfkaH7uI+JHkjao5W0x2qupqClB/H4wq0SYF7Zi0qh5AiAVxjXjRIxN/Wj wSMBAaaxZrFpXidrtMDCM597lpGsghOS46DvISkCaMiKzS5G7F7UGe7YoKMXtqblNIm7 a1cFASJJw6APrIVQy8Rk+HkNJF/u07o4kwQz6Dle+wuof9GycOW+Lhrb7NQb9MTGyPKh vycoPjrPubquARq1ouLTplUmdHxxo1sZQioQGL1nlhd3ptGRk9PkIHRRDrysmM63ywR7 +OKw== Received: by 10.236.190.138 with SMTP id e10mr26118764yhn.131.1339498078437; Tue, 12 Jun 2012 03:47:58 -0700 (PDT) Received: from dft-labs.eu (n1x0n-1-pt.tunnel.tserv5.lon1.ipv6.he.net. [2001:470:1f08:1f7::2]) by mx.google.com with ESMTPS id p29sm66231577yhl.19.2012.06.12.03.47.56 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 12 Jun 2012 03:47:57 -0700 (PDT) Date: Tue, 12 Jun 2012 12:47:49 +0200 From: Mateusz Guzik To: davidxu@FreeBSD.org Message-ID: <20120612104749.GB20749@dft-labs.eu> References: <201206112205.q5BM5QIv013266@svn.freebsd.org> <4FD6FD39.5090800@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <4FD6FD39.5090800@gmail.com> User-Agent: Mutt/1.5.20 (2009-06-14) Cc: svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org, Pawel Jakub Dawidek Subject: Re: svn commit: r236935 - head/sys/kern X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Jun 2012 10:47:59 -0000 On Tue, Jun 12, 2012 at 04:26:33PM +0800, David Xu wrote: > On 2012/6/12 6:05, Pawel Jakub Dawidek wrote: > >Author: pjd > >Date: Mon Jun 11 22:05:26 2012 > >New Revision: 236935 > >URL: http://svn.freebsd.org/changeset/base/236935 > > > >Log: > > fdgrowtable() no longer drops the filedesc lock so it is enough to > > retry finding free file descriptor only once after fdgrowtable(). > > > > Spotted by: pluknet > > MFC after: 1 month > > > >Modified: > > head/sys/kern/kern_descrip.c > > > >Modified: head/sys/kern/kern_descrip.c > >============================================================================== > >--- head/sys/kern/kern_descrip.c Mon Jun 11 21:56:37 2012 (r236934) > >+++ head/sys/kern/kern_descrip.c Mon Jun 11 22:05:26 2012 (r236935) > >@@ -1478,29 +1478,33 @@ fdalloc(struct thread *td, int minfd, in > > /* > > * Search the bitmap for a free descriptor. If none is found, try > > * to grow the file table. Keep at it until we either get a file > >- * descriptor or run into process or system limits; fdgrowtable() > >- * may drop the filedesc lock, so we're in a race. > >+ * descriptor or run into process or system limits. > > */ > >- for (;;) { > >- fd = fd_first_free(fdp, minfd, fdp->fd_nfiles); > >- if (fd>= maxfd) > >- return (EMFILE); > >- if (fd< fdp->fd_nfiles) > >- break; > >+ fd = fd_first_free(fdp, minfd, fdp->fd_nfiles); > >+ if (fd>= maxfd) > >+ return (EMFILE); > >+ if (fd>= fdp->fd_nfiles) { > > #ifdef RACCT > > PROC_LOCK(p); > >- error = racct_set(p, RACCT_NOFILE, min(fdp->fd_nfiles * 2, maxfd)); > >+ error = racct_set(p, RACCT_NOFILE, > >+ min(fdp->fd_nfiles * 2, maxfd)); > > PROC_UNLOCK(p); > > if (error != 0) > > return (EMFILE); > > #endif > > fdgrowtable(fdp, min(fdp->fd_nfiles * 2, maxfd)); > >+ /* Retry... */ > >+ fd = fd_first_free(fdp, minfd, fdp->fd_nfiles); > >+ if (fd>= maxfd) > >+ return (EMFILE); > > } > > > > /* > > * Perform some sanity checks, then mark the file descriptor as > > * used and return it to the caller. > > */ > >+ KASSERT((unsigned int)fd< min(maxfd, fdp->fd_nfiles), > >+ ("invalid descriptor %d", fd)); > > KASSERT(!fdisused(fdp, fd), > > ("fd_first_free() returned non-free descriptor")); > > KASSERT(fdp->fd_ofiles[fd] == NULL, ("file descriptor isn't free")); > > > My machine crashed with this change. > http://people.freebsd.org/~davidxu/fdcrash.jpg > > The problem is that fdalloc grows to at most fdp->fd_nfiles * 2, which still may not be enough to have place for new fd with high number. This fixed the problem for me, although I'm not sure whether it's ok to grow the table like this: http://people.freebsd.org/~mjg/patches/fdalloc.patch -- Mateusz Guzik