Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/stdlib Fix atfork malloc handling to include all th...



details:   https://anonhg.NetBSD.org/src/rev/0d899646b43b
branches:  trunk
changeset: 1006404:0d899646b43b
user:      joerg <joerg%NetBSD.org@localhost>
date:      Mon Jan 13 19:14:37 2020 +0000

description:
Fix atfork malloc handling to include all the locks in old jemalloc.

diffstat:

 lib/libc/stdlib/jemalloc.c |  23 +++++++++++++----------
 1 files changed, 13 insertions(+), 10 deletions(-)

diffs (63 lines):

diff -r 55881e07a03e -r 0d899646b43b lib/libc/stdlib/jemalloc.c
--- a/lib/libc/stdlib/jemalloc.c        Mon Jan 13 19:14:02 2020 +0000
+++ b/lib/libc/stdlib/jemalloc.c        Mon Jan 13 19:14:37 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: jemalloc.c,v 1.47 2020/01/13 19:14:02 joerg Exp $      */
+/*     $NetBSD: jemalloc.c,v 1.48 2020/01/13 19:14:37 joerg Exp $      */
 
 /*-
  * Copyright (C) 2006,2007 Jason Evans <jasone%FreeBSD.org@localhost>.
@@ -118,7 +118,7 @@
 
 #include <sys/cdefs.h>
 /* __FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.147 2007/06/15 22:00:16 jasone Exp $"); */ 
-__RCSID("$NetBSD: jemalloc.c,v 1.47 2020/01/13 19:14:02 joerg Exp $");
+__RCSID("$NetBSD: jemalloc.c,v 1.48 2020/01/13 19:14:37 joerg Exp $");
 
 #ifdef __FreeBSD__
 #include "libc_private.h"
@@ -3986,16 +3986,17 @@
        unsigned i;
 
        /* Acquire all mutexes in a safe order. */
-
+       malloc_mutex_lock(&init_lock);
        malloc_mutex_lock(&arenas_mtx);
        for (i = 0; i < narenas; i++) {
                if (arenas[i] != NULL)
                        malloc_mutex_lock(&arenas[i]->mtx);
        }
-
+       malloc_mutex_lock(&chunks_mtx);
        malloc_mutex_lock(&base_mtx);
-
-       malloc_mutex_lock(&chunks_mtx);
+#ifdef USE_BRK
+       malloc_mutex_lock(&brk_mtx);
+#endif
 }
 
 void
@@ -4004,16 +4005,18 @@
        unsigned i;
 
        /* Release all mutexes, now that fork() has completed. */
-
+#ifdef USE_BRK
+       malloc_mutex_unlock(&brk_mtx);
+#endif
+       malloc_mutex_unlock(&base_mtx);
        malloc_mutex_unlock(&chunks_mtx);
 
-       malloc_mutex_unlock(&base_mtx);
-
-       for (i = 0; i < narenas; i++) {
+       for (i = narenas; i-- > 0; ) {
                if (arenas[i] != NULL)
                        malloc_mutex_unlock(&arenas[i]->mtx);
        }
        malloc_mutex_unlock(&arenas_mtx);
+       malloc_mutex_unlock(&init_lock);
 }
 
 /*



Home | Main Index | Thread Index | Old Index