This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC][PATCH 3/4] malloc_info: report sizes of top chunks in each arena


Augment the output of malloc_info() to report the size of the "top"
chunk of each arena as a new type category in the totals. A grand total
for the size and count of "top" blocks across all arenas is also added
for consistency with the other existing totals.

This change plugs a gap, whereby some of the information reported by the
older mallinfo() and malloc_stats() functions was not available from
malloc_info().

The total free space in any arena can now be determined by adding
together the reported totals for "fast", "rest" and "top".

	* malloc/malloc.c (__malloc_info): Report sizes of top chunks in
	each arena.
---
 malloc/malloc.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/malloc/malloc.c b/malloc/malloc.c
index dc0a96ed13..b65161c76a 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -5391,8 +5391,10 @@ __malloc_info (int options, FILE *fp)
   int n = 0;
   size_t total_nblocks = 0;
   size_t total_nfastblocks = 0;
+  size_t total_narenas = 0;
   size_t total_avail = 0;
   size_t total_fastavail = 0;
+  size_t total_topavail = 0;
   size_t total_system = 0;
   size_t total_max_system = 0;
   size_t total_aspace = 0;
@@ -5484,6 +5486,8 @@ __malloc_info (int options, FILE *fp)
 	  avail += sizes[NFASTBINS - 1 + i].total;
 	}
 
+      size_t topavail = chunksize (top (ar_ptr));
+
       size_t heap_size = 0;
       size_t heap_mprotect_size = 0;
       size_t heap_count = 0;
@@ -5509,6 +5513,9 @@ __malloc_info (int options, FILE *fp)
       total_nblocks += nblocks;
       total_avail += avail;
 
+      ++total_narenas;
+      total_topavail += topavail;
+
       for (size_t i = 0; i < nsizes; ++i)
 	if (sizes[i].count != 0 && i != NFASTBINS)
 	  fprintf (fp, "\
@@ -5527,9 +5534,10 @@ __malloc_info (int options, FILE *fp)
       fprintf (fp,
 	       "</sizes>\n<total type=\"fast\" count=\"%zu\" size=\"%zu\"/>\n"
 	       "<total type=\"rest\" count=\"%zu\" size=\"%zu\"/>\n"
+	       "<total type=\"top\" count=\"1\" size=\"%zu\"/>\n"
 	       "<system type=\"current\" size=\"%zu\"/>\n"
 	       "<system type=\"max\" size=\"%zu\"/>\n",
-	       nfastblocks, fastavail, nblocks, avail,
+	       nfastblocks, fastavail, nblocks, avail, topavail,
 	       ar_ptr->system_mem, ar_ptr->max_system_mem);
 
       if (ar_ptr != &main_arena)
@@ -5560,6 +5568,7 @@ __malloc_info (int options, FILE *fp)
   fprintf (fp,
 	   "<total type=\"fast\" count=\"%zu\" size=\"%zu\"/>\n"
 	   "<total type=\"rest\" count=\"%zu\" size=\"%zu\"/>\n"
+	   "<total type=\"top\" count=\"%zu\" size=\"%zu\"/>\n"
 	   "<total type=\"mmap\" count=\"%d\" size=\"%zu\"/>\n"
 	   "<system type=\"current\" size=\"%zu\"/>\n"
 	   "<system type=\"max\" size=\"%zu\"/>\n"
@@ -5567,6 +5576,7 @@ __malloc_info (int options, FILE *fp)
 	   "<aspace type=\"mprotect\" size=\"%zu\"/>\n"
 	   "</malloc>\n",
 	   total_nfastblocks, total_fastavail, total_nblocks, total_avail,
+	   total_narenas, total_topavail,
 	   mp_.n_mmaps, mp_.mmapped_mem,
 	   total_system, total_max_system,
 	   total_aspace, total_aspace_mprotect);
-- 
2.11.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]