From owner-svn-src-head@FreeBSD.ORG Fri Oct 31 09:19:47 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id D89F26C7; Fri, 31 Oct 2014 09:19:47 +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 AAB25100; Fri, 31 Oct 2014 09:19:47 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s9V9JlXx002154; Fri, 31 Oct 2014 09:19:47 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s9V9JlOd002153; Fri, 31 Oct 2014 09:19:47 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <201410310919.s9V9JlOd002153@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Fri, 31 Oct 2014 09:19:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r273894 - 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-1 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: Fri, 31 Oct 2014 09:19:48 -0000 Author: mjg Date: Fri Oct 31 09:19:46 2014 New Revision: 273894 URL: https://svnweb.freebsd.org/changeset/base/273894 Log: filedesc: iterate over fd table only once in fdcopy While here add 'fdused_init' which does not perform unnecessary work. Drop FILEDESC_LOCK_ASSERT from fdisused and rely on callers to hold it when appropriate. This function is only used with INVARIANTS. No functional changes intended. Modified: head/sys/kern/kern_descrip.c Modified: head/sys/kern/kern_descrip.c ============================================================================== --- head/sys/kern/kern_descrip.c Fri Oct 31 09:15:59 2014 (r273893) +++ head/sys/kern/kern_descrip.c Fri Oct 31 09:19:46 2014 (r273894) @@ -238,8 +238,6 @@ static int fdisused(struct filedesc *fdp, int fd) { - FILEDESC_LOCK_ASSERT(fdp); - KASSERT(fd >= 0 && fd < fdp->fd_nfiles, ("file descriptor %d out of range (0, %d)", fd, fdp->fd_nfiles)); @@ -251,14 +249,21 @@ fdisused(struct filedesc *fdp, int fd) * Mark a file descriptor as used. */ static void -fdused(struct filedesc *fdp, int fd) +fdused_init(struct filedesc *fdp, int fd) { - FILEDESC_XLOCK_ASSERT(fdp); - KASSERT(!fdisused(fdp, fd), ("fd=%d is already used", fd)); fdp->fd_map[NDSLOT(fd)] |= NDBIT(fd); +} + +static void +fdused(struct filedesc *fdp, int fd) +{ + + FILEDESC_XLOCK_ASSERT(fdp); + + fdused_init(fdp, fd); if (fd > fdp->fd_lastfile) fdp->fd_lastfile = fd; if (fd == fdp->fd_freefile) @@ -1912,28 +1917,23 @@ fdcopy(struct filedesc *fdp) newfdp->fd_freefile = -1; for (i = 0; i <= fdp->fd_lastfile; ++i) { ofde = &fdp->fd_ofiles[i]; - if (ofde->fde_file != NULL && - ofde->fde_file->f_ops->fo_flags & DFLAG_PASSABLE) { - nfde = &newfdp->fd_ofiles[i]; - *nfde = *ofde; - filecaps_copy(&ofde->fde_caps, &nfde->fde_caps); - fhold(nfde->fde_file); - newfdp->fd_lastfile = i; - } else { + if (ofde->fde_file == NULL || + (ofde->fde_file->f_ops->fo_flags & DFLAG_PASSABLE) == 0) { if (newfdp->fd_freefile == -1) newfdp->fd_freefile = i; + continue; } - } - newfdp->fd_cmask = fdp->fd_cmask; - FILEDESC_SUNLOCK(fdp); - FILEDESC_XLOCK(newfdp); - for (i = 0; i <= newfdp->fd_lastfile; ++i) { - if (newfdp->fd_ofiles[i].fde_file != NULL) - fdused(newfdp, i); + nfde = &newfdp->fd_ofiles[i]; + *nfde = *ofde; + filecaps_copy(&ofde->fde_caps, &nfde->fde_caps); + fhold(nfde->fde_file); + fdused_init(newfdp, i); + newfdp->fd_lastfile = i; } if (newfdp->fd_freefile == -1) newfdp->fd_freefile = i; - FILEDESC_XUNLOCK(newfdp); + newfdp->fd_cmask = fdp->fd_cmask; + FILEDESC_SUNLOCK(fdp); return (newfdp); }