<div dir="ltr">What glibc release is this in?  We&#39;ve an upgrade patch pending that bumps it to 77f921dac17c5fa99bd9e926d926c327982895f7.<div><br></div><div>Ross</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 20 November 2017 at 07:44, Zhixiong Chi <span dir="ltr">&lt;<a href="mailto:zhixiong.chi@windriver.com" target="_blank">zhixiong.chi@windriver.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">There are the multiple process crashes seen while using malloc_info.<br>
Obtain the size information while the arena lock is acquired, and only<br>
print it later.<br>
<br>
Backport patch from <a href="https://sourceware.org/git/gitweb.cgi?p=glibc.git" rel="noreferrer" target="_blank">https://sourceware.org/git/<wbr>gitweb.cgi?p=glibc.git</a>;<br>
h=<wbr>7a9368a1174cb15b9f1d6342e0e10d<wbr>d90dae238d<br>
<br>
Signed-off-by: Zhixiong Chi &lt;<a href="mailto:zhixiong.chi@windriver.com">zhixiong.chi@windriver.com</a>&gt;<br>
---<br>
 ...loc-add-missing-arena-lock-<wbr>in-malloc-info.patch | 172 +++++++++++++++++++++<br>
 meta/recipes-core/glibc/<a href="http://glibc_2.26.bb" rel="noreferrer" target="_blank">glibc_<wbr>2.26.bb</a>              |   1 +<br>
 2 files changed, 173 insertions(+)<br>
 create mode 100644 meta/recipes-core/glibc/glibc/<wbr>0029-malloc-add-missing-arena-<wbr>lock-in-malloc-info.patch<br>
<br>
diff --git a/meta/recipes-core/glibc/<wbr>glibc/0029-malloc-add-missing-<wbr>arena-lock-in-malloc-info.<wbr>patch b/meta/recipes-core/glibc/<wbr>glibc/0029-malloc-add-missing-<wbr>arena-lock-in-malloc-info.<wbr>patch<br>
new file mode 100644<br>
index 0000000..e12400d<br>
--- /dev/null<br>
+++ b/meta/recipes-core/glibc/<wbr>glibc/0029-malloc-add-missing-<wbr>arena-lock-in-malloc-info.<wbr>patch<br>
@@ -0,0 +1,172 @@<br>
+From: Florian Weimer &lt;<a href="mailto:fweimer@redhat.com">fweimer@redhat.com</a>&gt;<br>
+Date: Wed, 15 Nov 2017 11:39:01 +0100<br>
+Subject: [PATCH] malloc: Add missing arena lock in malloc_info [BZ #22408]<br>
+<br>
+Obtain the size information while the arena lock is acquired, and only<br>
+print it later.<br>
+<br>
+Upstream-Status: Backport<br>
+<br>
+Signed-off-by: Zhixiong Chi &lt;<a href="mailto:zhixiong.chi@windriver.com">zhixiong.chi@windriver.com</a>&gt;<br>
+<br>
+Index: git/malloc/Makefile<br>
+=============================<wbr>==============================<wbr>========<br>
+--- git.orig/malloc/Makefile   2017-09-04 17:34:06.758018978 +0800<br>
++++ git/malloc/Makefile        2017-11-20 14:57:43.440337572 +0800<br>
+@@ -34,6 +34,7 @@<br>
+        tst-interpose-nothread \<br>
+        tst-interpose-thread \<br>
+        tst-alloc_buffer \<br>
++       tst-malloc_info \<br>
+<br>
+ tests-static := \<br>
+        tst-interpose-static-nothread \<br>
+@@ -242,3 +243,5 @@<br>
+ $(objpfx)tst-dynarray-fail-<wbr>mem.out: $(objpfx)tst-dynarray-fail.out<br>
+       $(common-objpfx)malloc/mtrace $(objpfx)tst-dynarray-fail.<wbr>mtrace &gt; $@; \<br>
+       $(evaluate-test)<br>
++<br>
++$(objpfx)tst-malloc_info: $(shared-thread-library)<br>
+Index: git/malloc/malloc.c<br>
+=============================<wbr>==============================<wbr>========<br>
+--- git.orig/malloc/malloc.c   2017-09-04 17:34:06.758018978 +0800<br>
++++ git/malloc/malloc.c        2017-11-20 15:01:02.412338959 +0800<br>
+@@ -5547,6 +5547,15 @@<br>
+         avail += sizes[NFASTBINS - 1 + i].total;<br>
+       }<br>
+<br>
++      size_t heap_size = 0;<br>
++      size_t heap_mprotect_size = 0;<br>
++      if (ar_ptr != &amp;main_arena)<br>
++      {<br>
++        heap_info *heap = heap_for_ptr (top (ar_ptr));<br>
++        heap_size = heap-&gt;size;<br>
++        heap_mprotect_size = heap-&gt;mprotect_size;<br>
++      }<br>
++<br>
+       __libc_lock_unlock (ar_ptr-&gt;mutex);<br>
+<br>
+       total_nfastblocks += nfastblocks;<br>
+@@ -5580,13 +5589,12 @@<br>
+<br>
+       if (ar_ptr != &amp;main_arena)<br>
+       {<br>
+-        heap_info *heap = heap_for_ptr (top (ar_ptr));<br>
+         fprintf (fp,<br>
+                  &quot;&lt;aspace type=\&quot;total\&quot; size=\&quot;%zu\&quot;/&gt;\n&quot;<br>
+                  &quot;&lt;aspace type=\&quot;mprotect\&quot; size=\&quot;%zu\&quot;/&gt;\n&quot;,<br>
+-                 heap-&gt;size, heap-&gt;mprotect_size);<br>
+-        total_aspace += heap-&gt;size;<br>
+-        total_aspace_mprotect += heap-&gt;mprotect_size;<br>
++                 heap_size, heap_mprotect_size);<br>
++        total_aspace += heap_size;<br>
++        total_aspace_mprotect += heap_mprotect_size;<br>
+       }<br>
+       else<br>
+       {<br>
+Index: git/malloc/tst-malloc_info.c<br>
+=============================<wbr>==============================<wbr>========<br>
+--- /dev/null  1970-01-01 00:00:00.000000000 +0000<br>
++++ git/malloc/tst-malloc_info.c       2017-11-20 15:02:03.208339383 +0800<br>
+@@ -0,0 +1,101 @@<br>
++/* Smoke test for malloc_info.<br>
++   Copyright (C) 2017 Free Software Foundation, Inc.<br>
++   This file is part of the GNU C Library.<br>
++<br>
++   The GNU C Library is free software; you can redistribute it and/or<br>
++   modify it under the terms of the GNU Lesser General Public<br>
++   License as published by the Free Software Foundation; either<br>
++   version 2.1 of the License, or (at your option) any later version.<br>
++<br>
++   The GNU C Library is distributed in the hope that it will be useful,<br>
++   but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU<br>
++   Lesser General Public License for more details.<br>
++<br>
++   You should have received a copy of the GNU Lesser General Public<br>
++   License along with the GNU C Library; if not, see<br>
++   &lt;<a href="http://www.gnu.org/licenses/" rel="noreferrer" target="_blank">http://www.gnu.org/licenses/</a>&gt;<wbr>.  */<br>
++<br>
++/* The purpose of this test is to provide a quick way to run<br>
++   malloc_info in a multi-threaded process.  */<br>
++<br>
++#include &lt;array_length.h&gt;<br>
++#include &lt;malloc.h&gt;<br>
++#include &lt;stdlib.h&gt;<br>
++#include &lt;support/support.h&gt;<br>
++#include &lt;support/xthread.h&gt;<br>
++<br>
++/* This barrier is used to have the main thread wait until the helper<br>
++   threads have performed their allocations.  */<br>
++static pthread_barrier_t barrier;<br>
++<br>
++enum<br>
++  {<br>
++    /* Number of threads performing allocations.  */<br>
++    thread_count  = 4,<br>
++<br>
++    /* Amount of memory allocation per thread.  This should be large<br>
++       enough to cause the allocation of multiple heaps per arena.  */<br>
++    per_thread_allocations<br>
++      = sizeof (void *) == 4 ? 16 * 1024 * 1024 : 128 * 1024 * 1024,<br>
++  };<br>
++<br>
++static void *<br>
++allocation_thread_function (void *closure)<br>
++{<br>
++  struct list<br>
++  {<br>
++    struct list *next;<br>
++    long dummy[4];<br>
++  };<br>
++<br>
++  struct list *head = NULL;<br>
++  size_t allocated = 0;<br>
++  while (allocated &lt; per_thread_allocations)<br>
++    {<br>
++      struct list *new_head = xmalloc (sizeof (*new_head));<br>
++      allocated += sizeof (*new_head);<br>
++      new_head-&gt;next = head;<br>
++      head = new_head;<br>
++    }<br>
++<br>
++  xpthread_barrier_wait (&amp;barrier);<br>
++<br>
++  /* Main thread prints first statistics here.  */<br>
++<br>
++  xpthread_barrier_wait (&amp;barrier);<br>
++<br>
++  while (head != NULL)<br>
++    {<br>
++      struct list *next_head = head-&gt;next;<br>
++      free (head);<br>
++      head = next_head;<br>
++    }<br>
++<br>
++  return NULL;<br>
++}<br>
++<br>
++static int<br>
++do_test (void)<br>
++{<br>
++  xpthread_barrier_init (&amp;barrier, NULL, thread_count + 1);<br>
++<br>
++  pthread_t threads[thread_count];<br>
++  for (size_t i = 0; i &lt; array_length (threads); ++i)<br>
++    threads[i] = xpthread_create (NULL, allocation_thread_function, NULL);<br>
++<br>
++  xpthread_barrier_wait (&amp;barrier);<br>
++  puts (&quot;info: After allocation:&quot;);<br>
++  malloc_info (0, stdout);<br>
++<br>
++  xpthread_barrier_wait (&amp;barrier);<br>
++  for (size_t i = 0; i &lt; array_length (threads); ++i)<br>
++    xpthread_join (threads[i]);<br>
++<br>
++  puts (&quot;\ninfo: After deallocation:&quot;);<br>
++  malloc_info (0, stdout);<br>
++<br>
++  return 0;<br>
++}<br>
++<br>
++#include &lt;support/test-driver.c&gt;<br>
diff --git a/meta/recipes-core/glibc/<a href="http://glibc_2.26.bb" rel="noreferrer" target="_blank">glib<wbr>c_2.26.bb</a> b/meta/recipes-core/glibc/<a href="http://glibc_2.26.bb" rel="noreferrer" target="_blank">glib<wbr>c_2.26.bb</a><br>
index 135ec4f..05d1e2c 100644<br>
--- a/meta/recipes-core/glibc/<a href="http://glibc_2.26.bb" rel="noreferrer" target="_blank">glib<wbr>c_2.26.bb</a><br>
+++ b/meta/recipes-core/glibc/<a href="http://glibc_2.26.bb" rel="noreferrer" target="_blank">glib<wbr>c_2.26.bb</a><br>
@@ -43,6 +43,7 @@ SRC_URI = &quot;${GLIBC_GIT_URI};branch=${<wbr>SRCBRANCH};name=glibc \<br>
            file://0026-assert-Suppress-<wbr>pedantic-warning-caused-by-<wbr>statement.patch \<br>
            file://0027-glibc-reset-dl-<wbr>load-write-lock-after-forking.<wbr>patch \<br>
            file://0028-Bug-4578-add-ld.<wbr>so-lock-while-fork.patch \<br>
+           file://0029-malloc-add-<wbr>missing-arena-lock-in-malloc-<wbr>info.patch \<br>
 &quot;<br>
<br>
 NATIVESDKFIXES ?= &quot;&quot;<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.9.1<br>
<br>
--<br>
______________________________<wbr>_________________<br>
Openembedded-core mailing list<br>
<a href="mailto:Openembedded-core@lists.openembedded.org">Openembedded-core@lists.<wbr>openembedded.org</a><br>
<a href="http://lists.openembedded.org/mailman/listinfo/openembedded-core" rel="noreferrer" target="_blank">http://lists.openembedded.org/<wbr>mailman/listinfo/openembedded-<wbr>core</a><br>
</font></span></blockquote></div><br></div>