about summary refs log tree commit diff
path: root/malloc
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2017-11-15 11:40:41 +0100
committerFlorian Weimer <fweimer@redhat.com>2017-11-15 11:40:41 +0100
commit34eb41579c6c34fa60ec6f1aac7b70ba6e1bebcc (patch)
treed6b42f67cca44928b1d4eb83547212f9b250a45f /malloc
parent7a9368a1174cb15b9f1d6342e0e10dd90dae238d (diff)
downloadglibc-34eb41579c6c34fa60ec6f1aac7b70ba6e1bebcc.tar.gz
glibc-34eb41579c6c34fa60ec6f1aac7b70ba6e1bebcc.tar.xz
glibc-34eb41579c6c34fa60ec6f1aac7b70ba6e1bebcc.zip
malloc: Account for all heaps in an arena in malloc_info [BZ #22439]
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>
Diffstat (limited to 'malloc')
-rw-r--r--malloc/malloc.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 0494e8c39f..2999ac4d2f 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -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;
 	}