svn commit: r332870 - head/sys/kern
Mateusz Guzik
mjg at FreeBSD.org
Sun Apr 22 09:30:08 UTC 2018
Author: mjg
Date: Sun Apr 22 09:30:07 2018
New Revision: 332870
URL: https://svnweb.freebsd.org/changeset/base/332870
Log:
lockf: slightly depessimize
1. check if P_ADVLOCK is already set and if so, don't lock to set it
(stolen from DragonFly)
2. when trying for fast path unlock, check that we are doing unlock
first instead of taking the interlock for no reason (e.g. if we want
to *lock*). whilere make it more likely that falling fast path will
not take the interlock either by checking for state
Note the code is severely pessimized both single- and multithreaded.
Modified:
head/sys/kern/kern_descrip.c
head/sys/kern/kern_lockf.c
Modified: head/sys/kern/kern_descrip.c
==============================================================================
--- head/sys/kern/kern_descrip.c Sun Apr 22 06:11:46 2018 (r332869)
+++ head/sys/kern/kern_descrip.c Sun Apr 22 09:30:07 2018 (r332870)
@@ -648,9 +648,11 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_
error = EBADF;
break;
}
- PROC_LOCK(p->p_leader);
- p->p_leader->p_flag |= P_ADVLOCK;
- PROC_UNLOCK(p->p_leader);
+ if ((p->p_leader->p_flag & P_ADVLOCK) == 0) {
+ PROC_LOCK(p->p_leader);
+ p->p_leader->p_flag |= P_ADVLOCK;
+ PROC_UNLOCK(p->p_leader);
+ }
error = VOP_ADVLOCK(vp, (caddr_t)p->p_leader, F_SETLK,
flp, flg);
break;
@@ -659,9 +661,11 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_
error = EBADF;
break;
}
- PROC_LOCK(p->p_leader);
- p->p_leader->p_flag |= P_ADVLOCK;
- PROC_UNLOCK(p->p_leader);
+ if ((p->p_leader->p_flag & P_ADVLOCK) == 0) {
+ PROC_LOCK(p->p_leader);
+ p->p_leader->p_flag |= P_ADVLOCK;
+ PROC_UNLOCK(p->p_leader);
+ }
error = VOP_ADVLOCK(vp, (caddr_t)p->p_leader, F_SETLK,
flp, flg);
break;
Modified: head/sys/kern/kern_lockf.c
==============================================================================
--- head/sys/kern/kern_lockf.c Sun Apr 22 06:11:46 2018 (r332869)
+++ head/sys/kern/kern_lockf.c Sun Apr 22 09:30:07 2018 (r332870)
@@ -479,15 +479,15 @@ retry_setlock:
/*
* Avoid the common case of unlocking when inode has no locks.
*/
- VI_LOCK(vp);
- if ((*statep) == NULL) {
- if (ap->a_op != F_SETLK) {
+ if (ap->a_op != F_SETLK && (*statep) == NULL) {
+ VI_LOCK(vp);
+ if ((*statep) == NULL) {
fl->l_type = F_UNLCK;
VI_UNLOCK(vp);
return (0);
}
+ VI_UNLOCK(vp);
}
- VI_UNLOCK(vp);
/*
* Map our arguments to an existing lock owner or create one
More information about the svn-src-head
mailing list