Author: mjg
Date: Fri Dec  7 16:47:34 2018
New Revision: 341701
URL: https://svnweb.freebsd.org/changeset/base/341701

Log:
  racct: add RACCT_ENABLED macro and racct_set_unlocked
  
  This allows to remove PROC_LOCK/UNLOCK pairs spread thorought the kernel
  only used to appease racct_set.
  
  Sponsored by: The FreeBSD Foundation

Modified:
  head/sys/kern/kern_racct.c
  head/sys/sys/racct.h

Modified: head/sys/kern/kern_racct.c
==============================================================================
--- head/sys/kern/kern_racct.c  Fri Dec  7 16:44:52 2018        (r341700)
+++ head/sys/kern/kern_racct.c  Fri Dec  7 16:47:34 2018        (r341701)
@@ -726,6 +726,18 @@ racct_set_locked(struct proc *p, int resource, uint64_
  * even if it's above the limit.
  */
 int
+racct_set_unlocked(struct proc *p, int resource, uint64_t amount)
+{
+       int error;
+
+       ASSERT_RACCT_ENABLED();
+       PROC_LOCK(p);
+       error = racct_set(p, resource, amount);
+       PROC_UNLOCK(p);
+       return (error);
+}
+
+int
 racct_set(struct proc *p, int resource, uint64_t amount)
 {
        int error;

Modified: head/sys/sys/racct.h
==============================================================================
--- head/sys/sys/racct.h        Fri Dec  7 16:44:52 2018        (r341700)
+++ head/sys/sys/racct.h        Fri Dec  7 16:47:34 2018        (r341701)
@@ -164,12 +164,14 @@ extern struct mtx racct_lock;
 #define RACCT_UNLOCK()         mtx_unlock(&racct_lock)
 #define RACCT_LOCK_ASSERT()    mtx_assert(&racct_lock, MA_OWNED)
 
+#define RACCT_ENABLED()                __predict_false(racct_enable)
+
 #define        RACCT_PROC_LOCK(p)      do {            \
-       if (__predict_false(racct_enable))      \
+       if (RACCT_ENABLED())                    \
                PROC_LOCK(p);                   \
 } while (0)
 #define        RACCT_PROC_UNLOCK(p)    do {            \
-       if (__predict_false(racct_enable))      \
+       if (RACCT_ENABLED())                    \
                PROC_UNLOCK(p);                 \
 } while (0)
 
@@ -178,6 +180,7 @@ void        racct_add_cred(struct ucred *cred, int 
resource, 
 void   racct_add_force(struct proc *p, int resource, uint64_t amount);
 void   racct_add_buf(struct proc *p, const struct buf *bufp, int is_write);
 int    racct_set(struct proc *p, int resource, uint64_t amount);
+int    racct_set_unlocked(struct proc *p, int resource, uint64_t amount);
 void   racct_set_force(struct proc *p, int resource, uint64_t amount);
 void   racct_sub(struct proc *p, int resource, uint64_t amount);
 void   racct_sub_cred(struct ucred *cred, int resource, uint64_t amount);
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to