From owner-svn-src-head@FreeBSD.ORG Thu Jul 10 20:59:54 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id E39455B9; Thu, 10 Jul 2014 20:59:54 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B7AA123CF; Thu, 10 Jul 2014 20:59:54 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6AKxsHc009279; Thu, 10 Jul 2014 20:59:54 GMT (envelope-from mjg@svn.freebsd.org) Received: (from mjg@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s6AKxs6M009278; Thu, 10 Jul 2014 20:59:54 GMT (envelope-from mjg@svn.freebsd.org) Message-Id: <201407102059.s6AKxs6M009278@svn.freebsd.org> From: Mateusz Guzik Date: Thu, 10 Jul 2014 20:59:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r268505 - head/sys/kern X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Jul 2014 20:59:55 -0000 Author: mjg Date: Thu Jul 10 20:59:54 2014 New Revision: 268505 URL: http://svnweb.freebsd.org/changeset/base/268505 Log: Avoid relocking filedesc lock when closing fds during fdp destruction. Don't call bzero nor fdunused from fdfree for such cases. It would do unnecessary work and complain that the lock is not taken. MFC after: 1 week Modified: head/sys/kern/kern_descrip.c Modified: head/sys/kern/kern_descrip.c ============================================================================== --- head/sys/kern/kern_descrip.c Thu Jul 10 20:55:38 2014 (r268504) +++ head/sys/kern/kern_descrip.c Thu Jul 10 20:59:54 2014 (r268505) @@ -294,18 +294,36 @@ fdunused(struct filedesc *fdp, int fd) /* * Free a file descriptor. + * + * Avoid some work if fdp is about to be destroyed. */ static inline void -fdfree(struct filedesc *fdp, int fd) +_fdfree(struct filedesc *fdp, int fd, int last) { struct filedescent *fde; fde = &fdp->fd_ofiles[fd]; filecaps_free(&fde->fde_caps); + if (last) + return; bzero(fde, sizeof(*fde)); fdunused(fdp, fd); } +static inline void +fdfree(struct filedesc *fdp, int fd) +{ + + _fdfree(fdp, fd, 0); +} + +static inline void +fdfree_last(struct filedesc *fdp, int fd) +{ + + _fdfree(fdp, fd, 1); +} + /* * System calls on descriptors. */ @@ -2011,36 +2029,34 @@ fdescfree(struct thread *td) FILEDESC_XLOCK(fdp); i = --fdp->fd_refcnt; - FILEDESC_XUNLOCK(fdp); - if (i > 0) + if (i > 0) { + FILEDESC_XUNLOCK(fdp); return; + } + + fdp->fd_nfiles = 0; + + cdir = fdp->fd_cdir; + fdp->fd_cdir = NULL; + rdir = fdp->fd_rdir; + fdp->fd_rdir = NULL; + jdir = fdp->fd_jdir; + fdp->fd_jdir = NULL; + FILEDESC_XUNLOCK(fdp); for (i = 0; i <= fdp->fd_lastfile; i++) { fp = fdp->fd_ofiles[i].fde_file; if (fp != NULL) { - FILEDESC_XLOCK(fdp); - fdfree(fdp, i); - FILEDESC_XUNLOCK(fdp); + fdfree_last(fdp, i); (void) closef(fp, td); } } - FILEDESC_XLOCK(fdp); if (fdp->fd_nfiles > NDFILE) free(fdp->fd_ofiles, M_FILEDESC); if (NDSLOTS(fdp->fd_nfiles) > NDSLOTS(NDFILE)) free(fdp->fd_map, M_FILEDESC); - fdp->fd_nfiles = 0; - - cdir = fdp->fd_cdir; - fdp->fd_cdir = NULL; - rdir = fdp->fd_rdir; - fdp->fd_rdir = NULL; - jdir = fdp->fd_jdir; - fdp->fd_jdir = NULL; - FILEDESC_XUNLOCK(fdp); - if (cdir != NULL) vrele(cdir); if (rdir != NULL)