From owner-svn-src-head@freebsd.org Wed Nov 1 05:51:21 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E4565E5B733; Wed, 1 Nov 2017 05:51:21 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::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 AE0A0832CA; Wed, 1 Nov 2017 05:51:21 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id vA15pKwu031009; Wed, 1 Nov 2017 05:51:20 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id vA15pKSS031007; Wed, 1 Nov 2017 05:51:20 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <201711010551.vA15pKSS031007@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Wed, 1 Nov 2017 05:51:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r325263 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: mjg X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 325263 X-SVN-Commit-Repository: base 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.23 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 Nov 2017 05:51:22 -0000 Author: mjg Date: Wed Nov 1 05:51:20 2017 New Revision: 325263 URL: https://svnweb.freebsd.org/changeset/base/325263 Log: Save on uihash table locking by checking if the caller already uses the struct In particular with poudriere this saves about 90% of lookups. Modified: head/sys/kern/init_main.c head/sys/kern/kern_resource.c Modified: head/sys/kern/init_main.c ============================================================================== --- head/sys/kern/init_main.c Wed Nov 1 03:54:07 2017 (r325262) +++ head/sys/kern/init_main.c Wed Nov 1 05:51:20 2017 (r325263) @@ -420,6 +420,7 @@ proc0_init(void *dummy __unused) struct proc *p; struct thread *td; struct ucred *newcred; + struct uidinfo tmpuinfo; vm_paddr_t pageablemem; int i; @@ -502,8 +503,14 @@ proc0_init(void *dummy __unused) /* Create credentials. */ newcred = crget(); newcred->cr_ngroups = 1; /* group 0 */ + /* A hack to prevent uifind from tripping over NULL pointers. */ + curthread->td_ucred = newcred; + tmpuinfo.ui_uid = 1; + newcred->cr_uidinfo = newcred->cr_ruidinfo = &tmpuinfo; newcred->cr_uidinfo = uifind(0); newcred->cr_ruidinfo = uifind(0); + /* End hack. creds get properly set later with thread_cow_get_proc */ + curthread->td_ucred = NULL; newcred->cr_prison = &prison0; newcred->cr_loginclass = loginclass_find("default"); proc_set_cred_init(p, newcred); Modified: head/sys/kern/kern_resource.c ============================================================================== --- head/sys/kern/kern_resource.c Wed Nov 1 03:54:07 2017 (r325262) +++ head/sys/kern/kern_resource.c Wed Nov 1 05:51:20 2017 (r325263) @@ -1253,6 +1253,18 @@ struct uidinfo * uifind(uid_t uid) { struct uidinfo *new_uip, *uip; + struct ucred *cred; + + cred = curthread->td_ucred; + if (cred->cr_uidinfo->ui_uid == uid) { + uip = cred->cr_uidinfo; + uihold(uip); + return (uip); + } else if (cred->cr_ruidinfo->ui_uid == uid) { + uip = cred->cr_ruidinfo; + uihold(uip); + return (uip); + } rw_rlock(&uihashtbl_lock); uip = uilookup(uid);