aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMateusz Guzik <mjg@FreeBSD.org>2018-09-18 01:24:30 +0000
committerMateusz Guzik <mjg@FreeBSD.org>2018-09-18 01:24:30 +0000
commit2554f86a8d426f6280857d184019506827e328d1 (patch)
tree6d18832ff7055fe7776f343e73b1e6cb1660334e
parentaf734c774648e8374f97ad47be48dfc8cd37659f (diff)
downloadsrc-2554f86a8d426f6280857d184019506827e328d1.tar.gz
src-2554f86a8d426f6280857d184019506827e328d1.zip
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
Notes
Notes: svn path=/head/; revision=338743
-rw-r--r--sys/sys/racct.h12
-rw-r--r--sys/vm/vm_mmap.c22
2 files changed, 21 insertions, 13 deletions
diff --git a/sys/sys/racct.h b/sys/sys/racct.h
index ec3322bdfdf9..84de705f24af 100644
--- a/sys/sys/racct.h
+++ b/sys/sys/racct.h
@@ -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)
{
diff --git a/sys/vm/vm_mmap.c b/sys/vm/vm_mmap.c
index e184b8ff5c1f..e8772a1eadde 100644
--- a/sys/vm/vm_mmap.c
+++ b/sys/vm/vm_mmap.c
@@ -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);
}
/*