summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhixiong Chi <zhixiong.chi@windriver.com>2017-11-26 22:53:59 -0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2018-01-04 12:57:43 +0000
commit3ab224951c3210e8a5a3a1f5995372b0f2501163 (patch)
treed87f81f5f097e70b712b084de021a0ee750abd7f
parentb894de417618c4a79df074dc22912466e2501ad5 (diff)
downloadpoky-3ab224951c3210e8a5a3a1f5995372b0f2501163.tar.gz
glibc: malloc: Add missing arena lock in malloc_info
There are the multiple process crashes seen while using malloc_info. Obtain the size information while the arena lock is acquired, and only print it later. Backport patch from https://sourceware.org/git/gitweb.cgi?p=glibc.git; h=7a9368a1174cb15b9f1d6342e0e10dd90dae238d (From OE-Core rev: 7ecbb31fbaf1d056c9301166700e2967bd623489) Signed-off-by: Zhixiong Chi <zhixiong.chi@windriver.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/recipes-core/glibc/glibc/0029-malloc-add-missing-arena-lock-in-malloc-info.patch172
-rw-r--r--meta/recipes-core/glibc/glibc_2.26.bb1
2 files changed, 173 insertions, 0 deletions
diff --git a/meta/recipes-core/glibc/glibc/0029-malloc-add-missing-arena-lock-in-malloc-info.patch b/meta/recipes-core/glibc/glibc/0029-malloc-add-missing-arena-lock-in-malloc-info.patch
new file mode 100644
index 0000000000..626e0e9039
--- /dev/null
+++ b/meta/recipes-core/glibc/glibc/0029-malloc-add-missing-arena-lock-in-malloc-info.patch
@@ -0,0 +1,172 @@
1From: Florian Weimer <fweimer@redhat.com>
2Date: Wed, 15 Nov 2017 11:39:01 +0100
3Subject: [PATCH] malloc: Add missing arena lock in malloc_info [BZ #22408]
4
5Obtain the size information while the arena lock is acquired, and only
6print it later.
7
8Upstream-Status: Backport
9
10Signed-off-by: Zhixiong Chi <zhixiong.chi@windriver.com>
11
12Index: git/malloc/Makefile
13===================================================================
14--- git.orig/malloc/Makefile 2017-09-04 17:34:06.758018978 +0800
15+++ git/malloc/Makefile 2017-11-20 14:57:43.440337572 +0800
16@@ -35,6 +35,7 @@
17 tst-interpose-thread \
18 tst-alloc_buffer \
19 tst-malloc-tcache-leak \
20+ tst-malloc_info \
21
22 tests-static := \
23 tst-interpose-static-nothread \
24@@ -245,3 +246,5 @@
25 $(evaluate-test)
26
27 $(objpfx)tst-malloc-tcache-leak: $(shared-thread-library)
28+
29+$(objpfx)tst-malloc_info: $(shared-thread-library)
30Index: git/malloc/malloc.c
31===================================================================
32--- git.orig/malloc/malloc.c 2017-09-04 17:34:06.758018978 +0800
33+++ git/malloc/malloc.c 2017-11-20 15:01:02.412338959 +0800
34@@ -5547,6 +5547,15 @@
35 avail += sizes[NFASTBINS - 1 + i].total;
36 }
37
38+ size_t heap_size = 0;
39+ size_t heap_mprotect_size = 0;
40+ if (ar_ptr != &main_arena)
41+ {
42+ heap_info *heap = heap_for_ptr (top (ar_ptr));
43+ heap_size = heap->size;
44+ heap_mprotect_size = heap->mprotect_size;
45+ }
46+
47 __libc_lock_unlock (ar_ptr->mutex);
48
49 total_nfastblocks += nfastblocks;
50@@ -5580,13 +5589,12 @@
51
52 if (ar_ptr != &main_arena)
53 {
54- heap_info *heap = heap_for_ptr (top (ar_ptr));
55 fprintf (fp,
56 "<aspace type=\"total\" size=\"%zu\"/>\n"
57 "<aspace type=\"mprotect\" size=\"%zu\"/>\n",
58- heap->size, heap->mprotect_size);
59- total_aspace += heap->size;
60- total_aspace_mprotect += heap->mprotect_size;
61+ heap_size, heap_mprotect_size);
62+ total_aspace += heap_size;
63+ total_aspace_mprotect += heap_mprotect_size;
64 }
65 else
66 {
67Index: git/malloc/tst-malloc_info.c
68===================================================================
69--- /dev/null 1970-01-01 00:00:00.000000000 +0000
70+++ git/malloc/tst-malloc_info.c 2017-11-20 15:02:03.208339383 +0800
71@@ -0,0 +1,101 @@
72+/* Smoke test for malloc_info.
73+ Copyright (C) 2017 Free Software Foundation, Inc.
74+ This file is part of the GNU C Library.
75+
76+ The GNU C Library is free software; you can redistribute it and/or
77+ modify it under the terms of the GNU Lesser General Public
78+ License as published by the Free Software Foundation; either
79+ version 2.1 of the License, or (at your option) any later version.
80+
81+ The GNU C Library is distributed in the hope that it will be useful,
82+ but WITHOUT ANY WARRANTY; without even the implied warranty of
83+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
84+ Lesser General Public License for more details.
85+
86+ You should have received a copy of the GNU Lesser General Public
87+ License along with the GNU C Library; if not, see
88+ <http://www.gnu.org/licenses/>. */
89+
90+/* The purpose of this test is to provide a quick way to run
91+ malloc_info in a multi-threaded process. */
92+
93+#include <array_length.h>
94+#include <malloc.h>
95+#include <stdlib.h>
96+#include <support/support.h>
97+#include <support/xthread.h>
98+
99+/* This barrier is used to have the main thread wait until the helper
100+ threads have performed their allocations. */
101+static pthread_barrier_t barrier;
102+
103+enum
104+ {
105+ /* Number of threads performing allocations. */
106+ thread_count = 4,
107+
108+ /* Amount of memory allocation per thread. This should be large
109+ enough to cause the allocation of multiple heaps per arena. */
110+ per_thread_allocations
111+ = sizeof (void *) == 4 ? 16 * 1024 * 1024 : 128 * 1024 * 1024,
112+ };
113+
114+static void *
115+allocation_thread_function (void *closure)
116+{
117+ struct list
118+ {
119+ struct list *next;
120+ long dummy[4];
121+ };
122+
123+ struct list *head = NULL;
124+ size_t allocated = 0;
125+ while (allocated < per_thread_allocations)
126+ {
127+ struct list *new_head = xmalloc (sizeof (*new_head));
128+ allocated += sizeof (*new_head);
129+ new_head->next = head;
130+ head = new_head;
131+ }
132+
133+ xpthread_barrier_wait (&barrier);
134+
135+ /* Main thread prints first statistics here. */
136+
137+ xpthread_barrier_wait (&barrier);
138+
139+ while (head != NULL)
140+ {
141+ struct list *next_head = head->next;
142+ free (head);
143+ head = next_head;
144+ }
145+
146+ return NULL;
147+}
148+
149+static int
150+do_test (void)
151+{
152+ xpthread_barrier_init (&barrier, NULL, thread_count + 1);
153+
154+ pthread_t threads[thread_count];
155+ for (size_t i = 0; i < array_length (threads); ++i)
156+ threads[i] = xpthread_create (NULL, allocation_thread_function, NULL);
157+
158+ xpthread_barrier_wait (&barrier);
159+ puts ("info: After allocation:");
160+ malloc_info (0, stdout);
161+
162+ xpthread_barrier_wait (&barrier);
163+ for (size_t i = 0; i < array_length (threads); ++i)
164+ xpthread_join (threads[i]);
165+
166+ puts ("\ninfo: After deallocation:");
167+ malloc_info (0, stdout);
168+
169+ return 0;
170+}
171+
172+#include <support/test-driver.c>
diff --git a/meta/recipes-core/glibc/glibc_2.26.bb b/meta/recipes-core/glibc/glibc_2.26.bb
index 5213a6a942..04d97734b3 100644
--- a/meta/recipes-core/glibc/glibc_2.26.bb
+++ b/meta/recipes-core/glibc/glibc_2.26.bb
@@ -42,6 +42,7 @@ SRC_URI = "${GLIBC_GIT_URI};branch=${SRCBRANCH};name=glibc \
42 file://0025-locale-fix-hard-coded-reference-to-gcc-E.patch \ 42 file://0025-locale-fix-hard-coded-reference-to-gcc-E.patch \
43 file://0027-glibc-reset-dl-load-write-lock-after-forking.patch \ 43 file://0027-glibc-reset-dl-load-write-lock-after-forking.patch \
44 file://0028-Bug-4578-add-ld.so-lock-while-fork.patch \ 44 file://0028-Bug-4578-add-ld.so-lock-while-fork.patch \
45 file://0029-malloc-add-missing-arena-lock-in-malloc-info.patch \
45" 46"
46 47
47NATIVESDKFIXES ?= "" 48NATIVESDKFIXES ?= ""