The NET_LOCK() is currently what guarantees that accesses to PF data
structures are serialized.  So we can drop the KERNEL_LOCK() in the
pf_purge_thread() to reduce contention.

While here use rwsleep(9) instead of calling NET_LOCK()/NET_UNLOCK()
for every iteration.  This way the thread won't go to sleep twice per
iteration.

ok?

Index: net/pf.c
===================================================================
RCS file: /cvs/src/sys/net/pf.c,v
retrieving revision 1.1035
diff -u -p -r1.1035 pf.c
--- net/pf.c    21 Jun 2017 15:29:23 -0000      1.1035
+++ net/pf.c    22 Jun 2017 09:16:27 -0000
@@ -1204,10 +1204,12 @@ pf_purge_thread(void *v)
 {
        int nloops = 0, s;
 
+       KERNEL_UNLOCK();
+
+       NET_LOCK(s);
        for (;;) {
-               tsleep(pf_purge_thread, PWAIT, "pftm", 1 * hz);
+               rwsleep(pf_purge_thread, &netlock, PWAIT, "pftm", 1 * hz);
 
-               NET_LOCK(s);
 
                PF_LOCK();
                /* process a fraction of the state table every second */
@@ -1227,9 +1229,8 @@ pf_purge_thread(void *v)
                        pf_purge_expired_fragments();
                        nloops = 0;
                }
-
-               NET_UNLOCK(s);
        }
+       NET_UNLOCK(s);
 }
 
 int32_t

Reply via email to