summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_malloc.c
diff options
context:
space:
mode:
authorbluhm <bluhm@openbsd.org>2018-07-10 10:17:42 +0000
committerbluhm <bluhm@openbsd.org>2018-07-10 10:17:42 +0000
commit4120fcf020f61857e7a04e965b4dc1885dbe3a8b (patch)
tree669776dfe4033c453887e3a0909c4c366cff337c /sys/kern/kern_malloc.c
parentAfter removing raw_usrreq() from route and pfkey, the global sockaddr (diff)
downloadwireguard-openbsd-4120fcf020f61857e7a04e965b4dc1885dbe3a8b.tar.xz
wireguard-openbsd-4120fcf020f61857e7a04e965b4dc1885dbe3a8b.zip
In free(9) call wakeup() after mtx_leave() consistently.
OK kettenis@ visa@ mpi@
Diffstat (limited to 'sys/kern/kern_malloc.c')
-rw-r--r--sys/kern/kern_malloc.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
index ac48383baa1..f39b17942b4 100644
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_malloc.c,v 1.135 2018/07/09 20:02:18 bluhm Exp $ */
+/* $OpenBSD: kern_malloc.c,v 1.136 2018/07/10 10:17:42 bluhm Exp $ */
/* $NetBSD: kern_malloc.c,v 1.15.4.2 1996/06/13 17:10:56 cgd Exp $ */
/*
@@ -373,6 +373,7 @@ free(void *addr, int type, size_t freedsize)
#endif
#ifdef KMEMSTATS
struct kmemstats *ksp = &kmemstats[type];
+ int wake;
#endif
if (addr == NULL)
@@ -421,12 +422,13 @@ free(void *addr, int type, size_t freedsize)
#ifdef KMEMSTATS
mtx_enter(&malloc_mtx);
ksp->ks_memuse -= size;
- if (ksp->ks_memuse + size >= ksp->ks_limit &&
- ksp->ks_memuse < ksp->ks_limit)
- wakeup(ksp);
+ wake = ksp->ks_memuse + size >= ksp->ks_limit &&
+ ksp->ks_memuse < ksp->ks_limit;
ksp->ks_inuse--;
kbp->kb_total -= 1;
mtx_leave(&malloc_mtx);
+ if (wake)
+ wakeup(ksp);
#endif
return;
}
@@ -466,13 +468,16 @@ free(void *addr, int type, size_t freedsize)
}
kbp->kb_totalfree++;
ksp->ks_memuse -= size;
- if (ksp->ks_memuse + size >= ksp->ks_limit &&
- ksp->ks_memuse < ksp->ks_limit)
- wakeup(ksp);
+ wake = ksp->ks_memuse + size >= ksp->ks_limit &&
+ ksp->ks_memuse < ksp->ks_limit;
ksp->ks_inuse--;
#endif
XSIMPLEQ_INSERT_TAIL(&kbp->kb_freelist, freep, kf_flist);
mtx_leave(&malloc_mtx);
+#ifdef KMEMSTATS
+ if (wake)
+ wakeup(ksp);
+#endif
}
/*