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
This commit is contained in:
parent
82f4b82634
commit
448db4f761
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=341701
@ -725,6 +725,18 @@ racct_set_locked(struct proc *p, int resource, uint64_t amount, int force)
|
||||
* Note that decreasing the allocation always returns 0,
|
||||
* 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)
|
||||
{
|
||||
|
@ -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, uint64_t amount);
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user