aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Pluzhnikov <ppluzhnikov@google.com>2012-05-16 16:46:10 -0700
committerPaul Pluzhnikov <ppluzhnikov@google.com>2012-05-16 16:46:10 -0700
commitbedee953d820c79f704c6e17f778ede94eb95fc4 (patch)
tree5979418f9cade0b3199d0e7854a207e5ec875f3e
parent30b99d798f9728a96d4766dd3f7fcfe5daae8945 (diff)
downloadglibc-bedee953d820c79f704c6e17f778ede94eb95fc4.tar
glibc-bedee953d820c79f704c6e17f778ede94eb95fc4.tar.gz
glibc-bedee953d820c79f704c6e17f778ede94eb95fc4.tar.bz2
glibc-bedee953d820c79f704c6e17f778ede94eb95fc4.zip
For [BZ #208], accumulate malloc stats over all arenas.
-rw-r--r--ChangeLog8
-rw-r--r--NEWS38
-rw-r--r--malloc/malloc.c51
3 files changed, 59 insertions, 38 deletions
diff --git a/ChangeLog b/ChangeLog
index ecfdebcc13..e24512d7ff 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2012-05-16 Paul Pluzhnikov <ppluzhnikov@google.com>
+
+ [BZ #208]
+ * malloc.c (int_mallinfo): Add parameter to accumulate statistics
+ in instead of returning them. Return void.
+ (__libc_mallinfo): Accumulate over all arenas.
+ (__malloc_stats): Adjust for change in int_mallinfo interface.
+
2012-05-16 Roland McGrath <roland@hack.frob.com>
[BZ #10375]
diff --git a/NEWS b/NEWS
index 8d98497032..2d2b6a8f14 100644
--- a/NEWS
+++ b/NEWS
@@ -9,25 +9,25 @@ Version 2.16
* The following bugs are resolved with this release:
- 174, 350, 369, 411, 706, 766, 887, 2074, 2541, 2547, 2548, 2550, 2551,
- 2552, 2553, 2554, 2562, 2563, 2565, 2566, 2570, 2576, 2636, 2678, 3335,
- 3440, 3748, 3768, 3866, 3868, 3906, 3976, 3992, 4026, 4108, 4596, 4822,
- 5077, 5461, 5805, 5993, 6471, 6486, 6578, 6649, 6730, 6770, 6794, 6884,
- 6890, 6894, 6895, 6907, 6911, 6959, 7064, 9739, 9902, 10110, 10135, 10140,
- 10153, 10210, 10254, 10346, 10375 10545, 10716, 11174, 11322, 11365,
- 11451, 11494, 11521, 11677, 11837, 11959, 12047, 12097, 12193, 12297,
- 12298, 12301, 12340, 12354, 13058, 13361, 13525, 13526, 13527, 13528,
- 13529, 13530, 13531, 13532, 13533, 13547, 13551, 13552, 13553, 13555,
- 13556, 13559, 13563, 13566, 13583, 13592, 13594, 13613, 13618, 13637,
- 13656, 13658, 13673, 13691, 13695, 13704, 13705, 13706, 13726, 13738,
- 13739, 13750, 13758, 13760, 13761, 13775, 13786, 13787, 13792, 13806,
- 13824, 13840, 13841, 13844, 13846, 13851, 13852, 13854, 13871, 13872,
- 13873, 13879, 13883, 13884, 13885, 13886, 13892, 13895, 13908, 13910,
- 13911, 13912, 13913, 13914, 13915, 13916, 13917, 13918, 13919, 13920,
- 13921, 13922, 13923, 13924, 13926, 13927, 13928, 13938, 13941, 13942,
- 13954, 13955, 13956, 13963, 13967, 13970, 13973, 13979, 13983, 13986,
- 14012, 14027, 14033, 14034, 14040, 14043, 14044, 14049, 14053, 14055,
- 14064, 14080, 14083, 14103, 14104, 14109
+ 174, 208, 350, 369, 411, 706, 766, 887, 2074, 2541, 2547, 2548, 2550,
+ 2551, 2552, 2553, 2554, 2562, 2563, 2565, 2566, 2570, 2576, 2636, 2678,
+ 3335, 3440, 3748, 3768, 3866, 3868, 3906, 3976, 3992, 4026, 4108, 4596,
+ 4822, 5077, 5461, 5805, 5993, 6471, 6486, 6578, 6649, 6730, 6770, 6794,
+ 6884, 6890, 6894, 6895, 6907, 6911, 6959, 7064, 9739, 9902, 10110,
+ 10135, 10140, 10153, 10210, 10254, 10346, 10375 10545, 10716, 11174,
+ 11322, 11365, 11451, 11494, 11521, 11677, 11837, 11959, 12047, 12097,
+ 12193, 12297, 12298, 12301, 12340, 12354, 13058, 13361, 13525, 13526,
+ 13527, 13528, 13529, 13530, 13531, 13532, 13533, 13547, 13551, 13552,
+ 13553, 13555, 13556, 13559, 13563, 13566, 13583, 13592, 13594, 13613,
+ 13618, 13637, 13656, 13658, 13673, 13691, 13695, 13704, 13705, 13706,
+ 13726, 13738, 13739, 13750, 13758, 13760, 13761, 13775, 13786, 13787,
+ 13792, 13806, 13824, 13840, 13841, 13844, 13846, 13851, 13852, 13854,
+ 13871, 13872, 13873, 13879, 13883, 13884, 13885, 13886, 13892, 13895,
+ 13908, 13910, 13911, 13912, 13913, 13914, 13915, 13916, 13917, 13918,
+ 13919, 13920, 13921, 13922, 13923, 13924, 13926, 13927, 13928, 13938,
+ 13941, 13942, 13954, 13955, 13956, 13963, 13967, 13970, 13973, 13979,
+ 13983, 13986, 14012, 14027, 14033, 14034, 14040, 14043, 14044, 14049,
+ 14053, 14055, 14064, 14080, 14083, 14103, 14104, 14109
* ISO C11 support:
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 79cdc52330..abe38723be 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -4513,12 +4513,12 @@ __malloc_usable_size(void* m)
/*
------------------------------ mallinfo ------------------------------
+ Accumulate malloc statistics for arena AV into M.
*/
-static struct mallinfo
-int_mallinfo(mstate av)
+static void
+int_mallinfo(mstate av, struct mallinfo *m)
{
- struct mallinfo mi;
size_t i;
mbinptr b;
mchunkptr p;
@@ -4558,29 +4558,40 @@ int_mallinfo(mstate av)
}
}
- mi.smblks = nfastblocks;
- mi.ordblks = nblocks;
- mi.fordblks = avail;
- mi.uordblks = av->system_mem - avail;
- mi.arena = av->system_mem;
- mi.hblks = mp_.n_mmaps;
- mi.hblkhd = mp_.mmapped_mem;
- mi.fsmblks = fastavail;
- mi.keepcost = chunksize(av->top);
- mi.usmblks = mp_.max_total_mem;
- return mi;
+ m->smblks += nfastblocks;
+ m->ordblks += nblocks;
+ m->fordblks += avail;
+ m->uordblks += av->system_mem - avail;
+ m->arena += av->system_mem;
+ m->fsmblks += fastavail;
+ if (av == &main_arena)
+ {
+ m->hblks = mp_.n_mmaps;
+ m->hblkhd = mp_.mmapped_mem;
+ m->usmblks = mp_.max_total_mem;
+ m->keepcost = chunksize(av->top);
+ }
}
struct mallinfo __libc_mallinfo()
{
struct mallinfo m;
+ mstate ar_ptr;
if(__malloc_initialized < 0)
ptmalloc_init ();
- (void)mutex_lock(&main_arena.mutex);
- m = int_mallinfo(&main_arena);
- (void)mutex_unlock(&main_arena.mutex);
+
+ memset(&m, 0, sizeof (m));
+ ar_ptr = &main_arena;
+ do {
+ (void)mutex_lock(&ar_ptr->mutex);
+ int_mallinfo(ar_ptr, &m);
+ (void)mutex_unlock(&ar_ptr->mutex);
+
+ ar_ptr = ar_ptr->next;
+ } while (ar_ptr != &main_arena);
+
return m;
}
@@ -4593,7 +4604,6 @@ __malloc_stats()
{
int i;
mstate ar_ptr;
- struct mallinfo mi;
unsigned int in_use_b = mp_.mmapped_mem, system_b = in_use_b;
#if THREAD_STATS
long stat_lock_direct = 0, stat_lock_loop = 0, stat_lock_wait = 0;
@@ -4605,8 +4615,11 @@ __malloc_stats()
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
for (i=0, ar_ptr = &main_arena;; i++) {
+ struct mallinfo mi;
+
+ memset(&mi, 0, sizeof(mi));
(void)mutex_lock(&ar_ptr->mutex);
- mi = int_mallinfo(ar_ptr);
+ int_mallinfo(ar_ptr, &mi);
fprintf(stderr, "Arena %d:\n", i);
fprintf(stderr, "system bytes = %10u\n", (unsigned int)mi.arena);
fprintf(stderr, "in use bytes = %10u\n", (unsigned int)mi.uordblks);