From: bluhm Date: Tue, 10 Jul 2018 10:17:42 +0000 (+0000) Subject: In free(9) call wakeup() after mtx_leave() consistently. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=4120fcf020f61857e7a04e965b4dc1885dbe3a8b;p=openbsd In free(9) call wakeup() after mtx_leave() consistently. OK kettenis@ visa@ mpi@ --- 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 } /*