]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
malloc: Account for all heaps in an arena in malloc_info [BZ #22439]
authorFlorian Weimer <fweimer@redhat.com>
Wed, 15 Nov 2017 10:40:41 +0000 (11:40 +0100)
committerFlorian Weimer <fweimer@redhat.com>
Wed, 15 Nov 2017 10:40:41 +0000 (11:40 +0100)
This commit adds a "subheaps" field to the malloc_info output that
shows the number of heaps that were allocated to extend a non-main
arena.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
ChangeLog
NEWS
malloc/malloc.c

index a0e0d077f43b07226c0a155f1387234c157b6103..703285008892e8456a115657c5656a96513ba75d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2017-11-15  Florian Weimer  <fweimer@redhat.com>
+
+       [BZ #22439]
+       * malloc/malloc.c (__malloc_info): Count all heaps in an arena,
+       not just the top one.  Output a new "subheaps" statistic.
+
 2017-11-15  Florian Weimer  <fweimer@redhat.com>
 
        [BZ #22408]
diff --git a/NEWS b/NEWS
index b7281621f4b47924416014213bd973fd095f30cc..520db40982f60a17077391375c297bb327b40805 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -63,6 +63,9 @@ Deprecated and removed features, and other changes affecting compatibility:
 * The res_hnok, res_dnok, res_mailok and res_ownok functions now check that
   the specified string can be parsed as a domain name.
 
+* In the malloc_info output, the <heap> element may contain another <aspace>
+  element, "subheaps", which contains the number of sub-heaps.
+
 Changes to build and runtime requirements:
 
   [Add changes to build and runtime requirements here]
index 0494e8c39fbefe6b86a51f25d3f0c6b77d4bdb44..2999ac4d2f883df355dc25d4da15f2563a25bbd0 100644 (file)
@@ -5457,11 +5457,19 @@ __malloc_info (int options, FILE *fp)
 
       size_t heap_size = 0;
       size_t heap_mprotect_size = 0;
+      size_t heap_count = 0;
       if (ar_ptr != &main_arena)
        {
+         /* Iterate over the arena heaps from back to front.  */
          heap_info *heap = heap_for_ptr (top (ar_ptr));
-         heap_size = heap->size;
-         heap_mprotect_size = heap->mprotect_size;
+         do
+           {
+             heap_size += heap->size;
+             heap_mprotect_size += heap->mprotect_size;
+             heap = heap->prev;
+             ++heap_count;
+           }
+         while (heap != NULL);
        }
 
       __libc_lock_unlock (ar_ptr->mutex);
@@ -5499,8 +5507,9 @@ __malloc_info (int options, FILE *fp)
        {
          fprintf (fp,
                   "<aspace type=\"total\" size=\"%zu\"/>\n"
-                  "<aspace type=\"mprotect\" size=\"%zu\"/>\n",
-                  heap_size, heap_mprotect_size);
+                  "<aspace type=\"mprotect\" size=\"%zu\"/>\n"
+                  "<aspace type=\"subheaps\" size=\"%zu\"/>\n",
+                  heap_size, heap_mprotect_size, heap_count);
          total_aspace += heap_size;
          total_aspace_mprotect += heap_mprotect_size;
        }