From owner-svn-src-head@FreeBSD.ORG Wed Jul 1 20:43:46 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7AF5B1065676; Wed, 1 Jul 2009 20:43:46 +0000 (UTC) (envelope-from jeff@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 4E4668FC08; Wed, 1 Jul 2009 20:43:46 +0000 (UTC) (envelope-from jeff@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n61Khk5q023450; Wed, 1 Jul 2009 20:43:46 GMT (envelope-from jeff@svn.freebsd.org) Received: (from jeff@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n61Khkb2023448; Wed, 1 Jul 2009 20:43:46 GMT (envelope-from jeff@svn.freebsd.org) Message-Id: <200907012043.n61Khkb2023448@svn.freebsd.org> From: Jeff Roberson Date: Wed, 1 Jul 2009 20:43:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195259 - head/sys/kern X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 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: Wed, 01 Jul 2009 20:43:47 -0000 Author: jeff Date: Wed Jul 1 20:43:46 2009 New Revision: 195259 URL: http://svn.freebsd.org/changeset/base/195259 Log: - Use fd_lastfile + 1 as the upper bound on nd. This is more correct than using the size of the descriptor array. - A lock is not needed to fetch fd_lastfile. The results are stale the instant it is dropped. - Use a private mutex pool for select since the pool mutex is not used as a leaf. - Fetch the si_mtx pointer first before resorting to hashing to compute the mutex address. Reviewed by: McKusick Approved by: re (kib) Modified: head/sys/kern/sys_generic.c Modified: head/sys/kern/sys_generic.c ============================================================================== --- head/sys/kern/sys_generic.c Wed Jul 1 20:42:17 2009 (r195258) +++ head/sys/kern/sys_generic.c Wed Jul 1 20:43:46 2009 (r195259) @@ -124,6 +124,7 @@ struct selfd { }; static uma_zone_t selfd_zone; +static struct mtx_pool *mtxpool_select; #ifndef _SYS_SYSPROTO_H_ struct read_args { @@ -794,11 +795,8 @@ kern_select(struct thread *td, int nd, f if (nd < 0) return (EINVAL); fdp = td->td_proc->p_fd; - - FILEDESC_SLOCK(fdp); - if (nd > td->td_proc->p_fd->fd_nfiles) - nd = td->td_proc->p_fd->fd_nfiles; /* forgiving; slightly wrong */ - FILEDESC_SUNLOCK(fdp); + if (nd > fdp->fd_lastfile + 1) + nd = fdp->fd_lastfile + 1; /* * Allocate just enough bits for the non-null fd_sets. Use the @@ -1373,7 +1371,9 @@ selrecord(selector, sip) stp->st_free2 = NULL; else panic("selrecord: No free selfd on selq"); - mtxp = mtx_pool_find(mtxpool_sleep, sip); + mtxp = sip->si_mtx; + if (mtxp == NULL) + mtxp = mtx_pool_find(mtxpool_select, sip); /* * Initialize the sfp and queue it in the thread. */ @@ -1529,6 +1529,8 @@ SYSINIT(select, SI_SUB_SYSCALLS, SI_ORDE static void selectinit(void *dummy __unused) { + selfd_zone = uma_zcreate("selfd", sizeof(struct selfd), NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0); + mtxpool_select = mtx_pool_create("select mtxpool", 128, MTX_DEF); }