Save on uihash table locking by checking if the caller already uses the struct

In particular with poudriere this saves about 90% of lookups.
This commit is contained in:
Mateusz Guzik 2017-11-01 05:51:20 +00:00
parent 140db60323
commit 5949c7e504
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=325263
2 changed files with 19 additions and 0 deletions

View File

@ -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);

View File

@ -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);