vm: stop taking proc lock in mmap to satisfy racct if it is disabled
Limits can be safely obtained with lim_cur from the thread. racct is compiled in but disabled by default. Note that racct enablement is a boot-only tunable. This eliminates second most common place of taking the lock while pkg building. While here don't take the lock in mlockall either. Reviewed by: kib Approved by: re (gjb) Differential Revision: https://reviews.freebsd.org/D17210
This commit is contained in:
parent
af734c7746
commit
2554f86a8d
@ -164,6 +164,15 @@ extern struct mtx racct_lock;
|
||||
#define RACCT_UNLOCK() mtx_unlock(&racct_lock)
|
||||
#define RACCT_LOCK_ASSERT() mtx_assert(&racct_lock, MA_OWNED)
|
||||
|
||||
#define RACCT_PROC_LOCK(p) do { \
|
||||
if (__predict_false(racct_enable)) \
|
||||
PROC_LOCK(p); \
|
||||
} while (0)
|
||||
#define RACCT_PROC_UNLOCK(p) do { \
|
||||
if (__predict_false(racct_enable)) \
|
||||
PROC_UNLOCK(p); \
|
||||
} while (0)
|
||||
|
||||
int racct_add(struct proc *p, int resource, uint64_t amount);
|
||||
void racct_add_cred(struct ucred *cred, int resource, uint64_t amount);
|
||||
void racct_add_force(struct proc *p, int resource, uint64_t amount);
|
||||
@ -189,6 +198,9 @@ void racct_proc_throttle(struct proc *p, int timeout);
|
||||
|
||||
#else
|
||||
|
||||
#define RACCT_PROC_LOCK(p) do { } while (0)
|
||||
#define RACCT_PROC_UNLOCK(p) do { } while (0)
|
||||
|
||||
static inline int
|
||||
racct_add(struct proc *p, int resource, uint64_t amount)
|
||||
{
|
||||
|
@ -1055,12 +1055,8 @@ sys_mlockall(struct thread *td, struct mlockall_args *uap)
|
||||
* a hard resource limit, return ENOMEM.
|
||||
*/
|
||||
if (!old_mlock && uap->how & MCL_CURRENT) {
|
||||
PROC_LOCK(td->td_proc);
|
||||
if (map->size > lim_cur(td, RLIMIT_MEMLOCK)) {
|
||||
PROC_UNLOCK(td->td_proc);
|
||||
if (map->size > lim_cur(td, RLIMIT_MEMLOCK))
|
||||
return (ENOMEM);
|
||||
}
|
||||
PROC_UNLOCK(td->td_proc);
|
||||
}
|
||||
#ifdef RACCT
|
||||
if (racct_enable) {
|
||||
@ -1445,21 +1441,21 @@ vm_mmap_object(vm_map_t map, vm_offset_t *addr, vm_size_t size, vm_prot_t prot,
|
||||
|
||||
curmap = map == &td->td_proc->p_vmspace->vm_map;
|
||||
if (curmap) {
|
||||
PROC_LOCK(td->td_proc);
|
||||
if (map->size + size > lim_cur_proc(td->td_proc, RLIMIT_VMEM)) {
|
||||
PROC_UNLOCK(td->td_proc);
|
||||
RACCT_PROC_LOCK(td->td_proc);
|
||||
if (map->size + size > lim_cur(td, RLIMIT_VMEM)) {
|
||||
RACCT_PROC_UNLOCK(td->td_proc);
|
||||
return (ENOMEM);
|
||||
}
|
||||
if (racct_set(td->td_proc, RACCT_VMEM, map->size + size)) {
|
||||
PROC_UNLOCK(td->td_proc);
|
||||
RACCT_PROC_UNLOCK(td->td_proc);
|
||||
return (ENOMEM);
|
||||
}
|
||||
if (!old_mlock && map->flags & MAP_WIREFUTURE) {
|
||||
if (ptoa(pmap_wired_count(map->pmap)) + size >
|
||||
lim_cur_proc(td->td_proc, RLIMIT_MEMLOCK)) {
|
||||
lim_cur(td, RLIMIT_MEMLOCK)) {
|
||||
racct_set_force(td->td_proc, RACCT_VMEM,
|
||||
map->size);
|
||||
PROC_UNLOCK(td->td_proc);
|
||||
RACCT_PROC_UNLOCK(td->td_proc);
|
||||
return (ENOMEM);
|
||||
}
|
||||
error = racct_set(td->td_proc, RACCT_MEMLOCK,
|
||||
@ -1467,11 +1463,11 @@ vm_mmap_object(vm_map_t map, vm_offset_t *addr, vm_size_t size, vm_prot_t prot,
|
||||
if (error != 0) {
|
||||
racct_set_force(td->td_proc, RACCT_VMEM,
|
||||
map->size);
|
||||
PROC_UNLOCK(td->td_proc);
|
||||
RACCT_PROC_UNLOCK(td->td_proc);
|
||||
return (error);
|
||||
}
|
||||
}
|
||||
PROC_UNLOCK(td->td_proc);
|
||||
RACCT_PROC_UNLOCK(td->td_proc);
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user