svn commit: r338743 - in head/sys: sys vm
Mateusz Guzik
mjg at FreeBSD.org
Tue Sep 18 01:24:32 UTC 2018
Author: mjg
Date: Tue Sep 18 01:24:30 2018
New Revision: 338743
URL: https://svnweb.freebsd.org/changeset/base/338743
Log:
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
Modified:
head/sys/sys/racct.h
head/sys/vm/vm_mmap.c
Modified: head/sys/sys/racct.h
==============================================================================
--- head/sys/sys/racct.h Tue Sep 18 00:32:10 2018 (r338742)
+++ head/sys/sys/racct.h Tue Sep 18 01:24:30 2018 (r338743)
@@ -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);
@@ -188,6 +197,9 @@ void racct_move(struct racct *dest, struct racct *src)
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)
Modified: head/sys/vm/vm_mmap.c
==============================================================================
--- head/sys/vm/vm_mmap.c Tue Sep 18 00:32:10 2018 (r338742)
+++ head/sys/vm/vm_mmap.c Tue Sep 18 01:24:30 2018 (r338743)
@@ -1055,12 +1055,8 @@ sys_mlockall(struct thread *td, struct mlockall_args *
* 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_siz
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_siz
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);
}
/*
More information about the svn-src-head
mailing list