* [PATCH v2 1/2] malloc: malloc_stats print all heaps except heaps of main_arena
@ 2019-10-26 7:13 liusirui
2019-10-26 7:13 ` [PATCH v2 2/2] malloc: malloc_stats now also print heap info " liusirui
0 siblings, 1 reply; 2+ messages in thread
From: liusirui @ 2019-10-26 7:13 UTC (permalink / raw)
To: libc-alpha; +Cc: hushiyuan
An arena may have several heaps, and only the last heap contains top chunk.
malloc_stats only print the heap which contains top chunk. Now the function
prints all heaps of an arena.
---
malloc/malloc.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 5d3e82a..351e95f 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -4965,6 +4965,7 @@ __malloc_stats (void)
{
int i;
mstate ar_ptr;
+ heap_info *heap_ptr;
unsigned int in_use_b = mp_.mmapped_mem, system_b = in_use_b;
if (__malloc_initialized < 0)
@@ -4984,7 +4985,13 @@ __malloc_stats (void)
fprintf (stderr, "in use bytes = %10u\n", (unsigned int) mi.uordblks);
#if MALLOC_DEBUG > 1
if (i > 0)
- dump_heap (heap_for_ptr (top (ar_ptr)));
+ {
+ for (heap_ptr = heap_for_ptr (top (ar_ptr)); heap_ptr->ar_ptr != (mstate) (heap_ptr + 1); heap_ptr = heap_ptr->prev)
+ {
+ dump_heap (heap_ptr);
+ }
+ dump_heap (heap_ptr);
+ }
#endif
system_b += mi.arena;
in_use_b += mi.uordblks;
--
2.7.4
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH v2 2/2] malloc: malloc_stats now also print heap info of main_arena
2019-10-26 7:13 [PATCH v2 1/2] malloc: malloc_stats print all heaps except heaps of main_arena liusirui
@ 2019-10-26 7:13 ` liusirui
0 siblings, 0 replies; 2+ messages in thread
From: liusirui @ 2019-10-26 7:13 UTC (permalink / raw)
To: libc-alpha; +Cc: hushiyuan
Before, malloc_stats only print heaps info of arenas except
main_arena, now it can alos prints heap info of main_arena.
---
malloc/arena.c | 28 ++++++++++++++++++++++------
malloc/malloc.c | 2 ++
2 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/malloc/arena.c b/malloc/arena.c
index be5c9f9..a9361c6 100644
--- a/malloc/arena.c
+++ b/malloc/arena.c
@@ -411,16 +411,32 @@ dump_heap (heap_info *heap)
{
char *ptr;
mchunkptr p;
+ mchunkptr top;
+
+ if ((mstate)(heap + 1) != &main_arena)
+ {
+ fprintf (stderr, "Heap %p, size %10lx:\n", heap, (long) heap->size);
+ ptr = (heap->ar_ptr != (mstate) (heap + 1)) ?
+ (char *) (heap + 1) : (char *) (heap + 1) + sizeof (struct malloc_state);
+ top = heap->ar_ptr->top;
+ p = (mchunkptr) (((unsigned long) ptr + MALLOC_ALIGN_MASK) &
+ ~MALLOC_ALIGN_MASK);
+ }
+ else
+ {
+ if (((mstate) (heap + 1))->max_system_mem == 0)
+ return;
+ top = ((mstate) (heap + 1))->top;
+ ptr = (char*)top - (((mstate) (heap + 1))->max_system_mem - chunksize(top));
+ p = (mchunkptr) (((unsigned long) ptr + MALLOC_ALIGN_MASK) &
+ ~MALLOC_ALIGN_MASK);
+ fprintf (stderr, "Heap %p, size %10lx:\n", p, (long)(((mstate) (heap + 1))->max_system_mem));
+ }
- fprintf (stderr, "Heap %p, size %10lx:\n", heap, (long) heap->size);
- ptr = (heap->ar_ptr != (mstate) (heap + 1)) ?
- (char *) (heap + 1) : (char *) (heap + 1) + sizeof (struct malloc_state);
- p = (mchunkptr) (((unsigned long) ptr + MALLOC_ALIGN_MASK) &
- ~MALLOC_ALIGN_MASK);
for (;; )
{
fprintf (stderr, "chunk %p size %10lx", p, (long) chunksize_nomask(p));
- if (p == top (heap->ar_ptr))
+ if (p == top)
{
fprintf (stderr, " (top)\n");
break;
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 351e95f..16a012e 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -4992,6 +4992,8 @@ __malloc_stats (void)
}
dump_heap (heap_ptr);
}
+ else
+ dump_heap (((heap_info*)ar_ptr) - 1);
#endif
system_b += mi.arena;
in_use_b += mi.uordblks;
--
2.7.4
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-10-26 7:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-26 7:13 [PATCH v2 1/2] malloc: malloc_stats print all heaps except heaps of main_arena liusirui
2019-10-26 7:13 ` [PATCH v2 2/2] malloc: malloc_stats now also print heap info " liusirui
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).