Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 1 Nov 2017 05:51:20 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r325263 - head/sys/kern
Message-ID:  <201711010551.vA15pKSS031007@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201711010551.vA15pKSS031007>