summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos O'Donell <carlos@redhat.com>2014-05-26 09:54:59 -0400
committerCarlos O'Donell <carlos@redhat.com>2014-05-26 11:32:09 -0400
commitfdfd175d46ac6a810ebdeb2a2936e6d7d13995ab (patch)
tree3b38bb3eb1896805852d319d36b4f75e9a82ed17
parentd298c41635ce7f2dc7c3eccc842fe3aa754c0c8e (diff)
downloadglibc-fdfd175d46ac6a810ebdeb2a2936e6d7d13995ab.tar.gz
Remove nested function mi_arena from malloc_info.
The nested function mi_arena was removed from malloc_info and made into a non-nested static inline function of the same name with the correct set of arguments passed from malloc_info. This enables building glibc with compilers that don't support nested functions. Future work on malloc_info should remove these functions entirely to support JSON format output. Therefore we do the minimum required to remove the nested function.
-rw-r--r--ChangeLog6
-rw-r--r--malloc/malloc.c260
2 files changed, 141 insertions, 125 deletions
diff --git a/ChangeLog b/ChangeLog
index 8f74df1fbb..459042ac68 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2014-05-26 Carlos O'Donell <carlos@redhat.com>
+
+ * malloc/malloc.c (mi_arena): New function.
+ (malloc_info): Remove nested function mi_arena. Call non-nosted
+ function mi_arena.
+
2014-05-26 Adhemerval Zanella <azanella@linux.vnet.ibm.com>
* sysdeps/powerpc/powerpc32/power4/memset.S (memset): Replace insrdi
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 1120d4df84..92ad9f9ab3 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -4986,154 +4986,162 @@ __posix_memalign (void **memptr, size_t alignment, size_t size)
}
weak_alias (__posix_memalign, posix_memalign)
-
-int
-malloc_info (int options, FILE *fp)
+static inline void
+mi_arena (mstate ar_ptr,
+ FILE *fp,
+ size_t *total_nblocks,
+ size_t *total_nfastblocks,
+ size_t *total_avail,
+ size_t *total_fastavail,
+ size_t *total_system,
+ size_t *total_max_system,
+ size_t *total_aspace,
+ size_t *total_aspace_mprotect)
{
- /* For now, at least. */
- if (options != 0)
- return EINVAL;
-
int n = 0;
- size_t total_nblocks = 0;
- size_t total_nfastblocks = 0;
- size_t total_avail = 0;
- size_t total_fastavail = 0;
- size_t total_system = 0;
- size_t total_max_system = 0;
- size_t total_aspace = 0;
- size_t total_aspace_mprotect = 0;
- void
- mi_arena (mstate ar_ptr)
- {
- fprintf (fp, "<heap nr=\"%d\">\n<sizes>\n", n++);
+ fprintf (fp, "<heap nr=\"%d\">\n<sizes>\n", n++);
- size_t nblocks = 0;
- size_t nfastblocks = 0;
- size_t avail = 0;
- size_t fastavail = 0;
- struct
- {
- size_t from;
- size_t to;
- size_t total;
- size_t count;
- } sizes[NFASTBINS + NBINS - 1];
+ size_t nblocks = 0;
+ size_t nfastblocks = 0;
+ size_t avail = 0;
+ size_t fastavail = 0;
+ struct
+ {
+ size_t from;
+ size_t to;
+ size_t total;
+ size_t count;
+ } sizes[NFASTBINS + NBINS - 1];
#define nsizes (sizeof (sizes) / sizeof (sizes[0]))
- mutex_lock (&ar_ptr->mutex);
-
- for (size_t i = 0; i < NFASTBINS; ++i)
- {
- mchunkptr p = fastbin (ar_ptr, i);
- if (p != NULL)
- {
- size_t nthissize = 0;
- size_t thissize = chunksize (p);
+ mutex_lock (&ar_ptr->mutex);
+ for (size_t i = 0; i < NFASTBINS; ++i)
+ {
+ mchunkptr p = fastbin (ar_ptr, i);
+ if (p != NULL)
+ {
+ size_t nthissize = 0;
+ size_t thissize = chunksize (p);
- while (p != NULL)
- {
- ++nthissize;
- p = p->fd;
- }
+ while (p != NULL)
+ {
+ ++nthissize;
+ p = p->fd;
+ }
- fastavail += nthissize * thissize;
- nfastblocks += nthissize;
- sizes[i].from = thissize - (MALLOC_ALIGNMENT - 1);
- sizes[i].to = thissize;
- sizes[i].count = nthissize;
- }
- else
- sizes[i].from = sizes[i].to = sizes[i].count = 0;
+ fastavail += nthissize * thissize;
+ nfastblocks += nthissize;
+ sizes[i].from = thissize - (MALLOC_ALIGNMENT - 1);
+ sizes[i].to = thissize;
+ sizes[i].count = nthissize;
+ }
+ else
+ sizes[i].from = sizes[i].to = sizes[i].count = 0;
- sizes[i].total = sizes[i].count * sizes[i].to;
- }
+ sizes[i].total = sizes[i].count * sizes[i].to;
+ }
- mbinptr bin;
- struct malloc_chunk *r;
+ mbinptr bin;
+ struct malloc_chunk *r;
- for (size_t i = 1; i < NBINS; ++i)
- {
- bin = bin_at (ar_ptr, i);
- r = bin->fd;
- sizes[NFASTBINS - 1 + i].from = ~((size_t) 0);
- sizes[NFASTBINS - 1 + i].to = sizes[NFASTBINS - 1 + i].total
- = sizes[NFASTBINS - 1 + i].count = 0;
-
- if (r != NULL)
- while (r != bin)
- {
- ++sizes[NFASTBINS - 1 + i].count;
- sizes[NFASTBINS - 1 + i].total += r->size;
- sizes[NFASTBINS - 1 + i].from
- = MIN (sizes[NFASTBINS - 1 + i].from, r->size);
- sizes[NFASTBINS - 1 + i].to = MAX (sizes[NFASTBINS - 1 + i].to,
- r->size);
-
- r = r->fd;
- }
+ for (size_t i = 1; i < NBINS; ++i)
+ {
+ bin = bin_at (ar_ptr, i);
+ r = bin->fd;
+ sizes[NFASTBINS - 1 + i].from = ~((size_t) 0);
+ sizes[NFASTBINS - 1 + i].to = sizes[NFASTBINS - 1 + i].total
+ = sizes[NFASTBINS - 1 + i].count = 0;
+
+ if (r != NULL)
+ while (r != bin)
+ {
+ ++sizes[NFASTBINS - 1 + i].count;
+ sizes[NFASTBINS - 1 + i].total += r->size;
+ sizes[NFASTBINS - 1 + i].from
+ = MIN (sizes[NFASTBINS - 1 + i].from, r->size);
+ sizes[NFASTBINS - 1 + i].to = MAX (sizes[NFASTBINS - 1 + i].to,
+ r->size);
+
+ r = r->fd;
+ }
- if (sizes[NFASTBINS - 1 + i].count == 0)
- sizes[NFASTBINS - 1 + i].from = 0;
- nblocks += sizes[NFASTBINS - 1 + i].count;
- avail += sizes[NFASTBINS - 1 + i].total;
- }
+ if (sizes[NFASTBINS - 1 + i].count == 0)
+ sizes[NFASTBINS - 1 + i].from = 0;
+ nblocks += sizes[NFASTBINS - 1 + i].count;
+ avail += sizes[NFASTBINS - 1 + i].total;
+ }
- mutex_unlock (&ar_ptr->mutex);
+ mutex_unlock (&ar_ptr->mutex);
- total_nfastblocks += nfastblocks;
- total_fastavail += fastavail;
+ *total_nfastblocks += nfastblocks;
+ *total_fastavail += fastavail;
- total_nblocks += nblocks;
- total_avail += avail;
+ *total_nblocks += nblocks;
+ *total_avail += avail;
- for (size_t i = 0; i < nsizes; ++i)
- if (sizes[i].count != 0 && i != NFASTBINS)
- fprintf (fp, " \
+ for (size_t i = 0; i < nsizes; ++i)
+ if (sizes[i].count != 0 && i != NFASTBINS)
+ fprintf (fp, " \
<size from=\"%zu\" to=\"%zu\" total=\"%zu\" count=\"%zu\"/>\n",
- sizes[i].from, sizes[i].to, sizes[i].total, sizes[i].count);
+ sizes[i].from, sizes[i].to, sizes[i].total, sizes[i].count);
- if (sizes[NFASTBINS].count != 0)
- fprintf (fp, "\
+ if (sizes[NFASTBINS].count != 0)
+ fprintf (fp, "\
<unsorted from=\"%zu\" to=\"%zu\" total=\"%zu\" count=\"%zu\"/>\n",
- sizes[NFASTBINS].from, sizes[NFASTBINS].to,
- sizes[NFASTBINS].total, sizes[NFASTBINS].count);
+ sizes[NFASTBINS].from, sizes[NFASTBINS].to,
+ sizes[NFASTBINS].total, sizes[NFASTBINS].count);
- total_system += ar_ptr->system_mem;
- total_max_system += ar_ptr->max_system_mem;
+ *total_system += ar_ptr->system_mem;
+ *total_max_system += ar_ptr->max_system_mem;
- fprintf (fp,
- "</sizes>\n<total type=\"fast\" count=\"%zu\" size=\"%zu\"/>\n"
- "<total type=\"rest\" count=\"%zu\" size=\"%zu\"/>\n"
- "<system type=\"current\" size=\"%zu\"/>\n"
- "<system type=\"max\" size=\"%zu\"/>\n",
- nfastblocks, fastavail, nblocks, avail,
- ar_ptr->system_mem, ar_ptr->max_system_mem);
+ fprintf (fp,
+ "</sizes>\n<total type=\"fast\" count=\"%zu\" size=\"%zu\"/>\n"
+ "<total type=\"rest\" count=\"%zu\" size=\"%zu\"/>\n"
+ "<system type=\"current\" size=\"%zu\"/>\n"
+ "<system type=\"max\" size=\"%zu\"/>\n",
+ nfastblocks, fastavail, nblocks, avail,
+ ar_ptr->system_mem, ar_ptr->max_system_mem);
- if (ar_ptr != &main_arena)
- {
- heap_info *heap = heap_for_ptr (top (ar_ptr));
- fprintf (fp,
- "<aspace type=\"total\" size=\"%zu\"/>\n"
- "<aspace type=\"mprotect\" size=\"%zu\"/>\n",
- heap->size, heap->mprotect_size);
- total_aspace += heap->size;
- total_aspace_mprotect += heap->mprotect_size;
- }
- else
- {
- fprintf (fp,
- "<aspace type=\"total\" size=\"%zu\"/>\n"
- "<aspace type=\"mprotect\" size=\"%zu\"/>\n",
- ar_ptr->system_mem, ar_ptr->system_mem);
- total_aspace += ar_ptr->system_mem;
- total_aspace_mprotect += ar_ptr->system_mem;
- }
+ if (ar_ptr != &main_arena)
+ {
+ heap_info *heap = heap_for_ptr (top (ar_ptr));
+ fprintf (fp,
+ "<aspace type=\"total\" size=\"%zu\"/>\n"
+ "<aspace type=\"mprotect\" size=\"%zu\"/>\n",
+ heap->size, heap->mprotect_size);
+ *total_aspace += heap->size;
+ *total_aspace_mprotect += heap->mprotect_size;
+ }
+ else
+ {
+ fprintf (fp,
+ "<aspace type=\"total\" size=\"%zu\"/>\n"
+ "<aspace type=\"mprotect\" size=\"%zu\"/>\n",
+ ar_ptr->system_mem, ar_ptr->system_mem);
+ *total_aspace += ar_ptr->system_mem;
+ *total_aspace_mprotect += ar_ptr->system_mem;
+ }
- fputs ("</heap>\n", fp);
- }
+ fputs ("</heap>\n", fp);
+}
+
+int
+malloc_info (int options, FILE *fp)
+{
+ /* For now, at least. */
+ if (options != 0)
+ return EINVAL;
+
+ size_t total_nblocks = 0;
+ size_t total_nfastblocks = 0;
+ size_t total_avail = 0;
+ size_t total_fastavail = 0;
+ size_t total_system = 0;
+ size_t total_max_system = 0;
+ size_t total_aspace = 0;
+ size_t total_aspace_mprotect = 0;
if (__malloc_initialized < 0)
ptmalloc_init ();
@@ -5144,7 +5152,9 @@ malloc_info (int options, FILE *fp)
mstate ar_ptr = &main_arena;
do
{
- mi_arena (ar_ptr);
+ mi_arena (ar_ptr, fp, &total_nblocks, &total_nfastblocks, &total_avail,
+ &total_fastavail, &total_system, &total_max_system,
+ &total_aspace, &total_aspace_mprotect);
ar_ptr = ar_ptr->next;
}
while (ar_ptr != &main_arena);