Various minor cleanups.

Clean up whitespace.

Lock access of swap_avail when printing stats.

Use inttypes.h for portable printf() format specifiers, specifically for
uint64_t (PRIu64).

Change highchunks and curchunks stats from (unsigned long) to (size_t).
This commit is contained in:
Jason Evans 2010-01-24 16:41:01 -08:00
parent 4201af0542
commit bc25a47ee0
5 changed files with 32 additions and 17 deletions

View File

@ -289,7 +289,7 @@ struct arena_s {
arena_chunk_t *spare; arena_chunk_t *spare;
/* Number of pages in active runs. */ /* Number of pages in active runs. */
size_t nactive; size_t nactive;
/* /*
* Current count of pages within unused runs that are potentially * Current count of pages within unused runs that are potentially
@ -299,7 +299,6 @@ struct arena_s {
*/ */
size_t ndirty; size_t ndirty;
/* /*
* Size/address-ordered tree of this arena's available runs. This tree * Size/address-ordered tree of this arena's available runs. This tree
* is used for first-best-fit run allocation. * is used for first-best-fit run allocation.

View File

@ -17,6 +17,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <inttypes.h>
#include <string.h> #include <string.h>
#include <strings.h> #include <strings.h>
#include <unistd.h> #include <unistd.h>

View File

@ -110,14 +110,14 @@ struct chunk_stats_s {
uint64_t nchunks; uint64_t nchunks;
/* High-water mark for number of chunks allocated. */ /* High-water mark for number of chunks allocated. */
unsigned long highchunks; size_t highchunks;
/* /*
* Current number of chunks allocated. This value isn't maintained for * Current number of chunks allocated. This value isn't maintained for
* any other purpose, so keep track of it in order to be able to set * any other purpose, so keep track of it in order to be able to set
* highchunks. * highchunks.
*/ */
unsigned long curchunks; size_t curchunks;
}; };
#endif /* JEMALLOC_H_STRUCTS */ #endif /* JEMALLOC_H_STRUCTS */

View File

@ -1612,8 +1612,8 @@ arena_stats_aprint(size_t nactive, size_t ndirty, const arena_stats_t *astats,
{ {
malloc_cprintf(write4, w4opaque, malloc_cprintf(write4, w4opaque,
"dirty pages: %zu:%zu active:dirty, %llu sweep%s," "dirty pages: %zu:%zu active:dirty, %"PRIu64" sweep%s,"
" %llu madvise%s, %llu purged\n", " %"PRIu64" madvise%s, %"PRIu64" purged\n",
nactive, ndirty, nactive, ndirty,
astats->npurge, astats->npurge == 1 ? "" : "s", astats->npurge, astats->npurge == 1 ? "" : "s",
astats->nmadvise, astats->nmadvise == 1 ? "" : "s", astats->nmadvise, astats->nmadvise == 1 ? "" : "s",
@ -1621,16 +1621,20 @@ arena_stats_aprint(size_t nactive, size_t ndirty, const arena_stats_t *astats,
malloc_cprintf(write4, w4opaque, malloc_cprintf(write4, w4opaque,
" allocated nmalloc ndalloc\n"); " allocated nmalloc ndalloc\n");
malloc_cprintf(write4, w4opaque, "small: %12zu %12llu %12llu\n", malloc_cprintf(write4, w4opaque,
"small: %12zu %12"PRIu64" %12"PRIu64"\n",
astats->allocated_small, astats->nmalloc_small, astats->allocated_small, astats->nmalloc_small,
astats->ndalloc_small); astats->ndalloc_small);
malloc_cprintf(write4, w4opaque, "medium: %12zu %12llu %12llu\n", malloc_cprintf(write4, w4opaque,
"medium: %12zu %12"PRIu64" %12"PRIu64"\n",
astats->allocated_medium, astats->nmalloc_medium, astats->allocated_medium, astats->nmalloc_medium,
astats->ndalloc_medium); astats->ndalloc_medium);
malloc_cprintf(write4, w4opaque, "large: %12zu %12llu %12llu\n", malloc_cprintf(write4, w4opaque,
"large: %12zu %12"PRIu64" %12"PRIu64"\n",
astats->allocated_large, astats->nmalloc_large, astats->allocated_large, astats->nmalloc_large,
astats->ndalloc_large); astats->ndalloc_large);
malloc_cprintf(write4, w4opaque, "total: %12zu %12llu %12llu\n", malloc_cprintf(write4, w4opaque,
"total: %12zu %12"PRIu64" %12"PRIu64"\n",
astats->allocated_small + astats->allocated_medium + astats->allocated_small + astats->allocated_medium +
astats->allocated_large, astats->nmalloc_small + astats->allocated_large, astats->nmalloc_small +
astats->nmalloc_medium + astats->nmalloc_large, astats->nmalloc_medium + astats->nmalloc_large,
@ -1674,11 +1678,11 @@ arena_stats_bprint(arena_t *arena, const malloc_bin_stats_t *bstats,
gap_start = UINT_MAX; gap_start = UINT_MAX;
} }
malloc_cprintf(write4, w4opaque, malloc_cprintf(write4, w4opaque,
"%13u %1s %5u %4u %3u %9llu %9llu" "%13u %1s %5u %4u %3u %9"PRIu64" %9"PRIu64
#ifdef JEMALLOC_TCACHE #ifdef JEMALLOC_TCACHE
" %9llu %9llu" " %9"PRIu64" %9"PRIu64""
#endif #endif
" %9llu %7zu %7zu\n", " %9"PRIu64" %7zu %7zu\n",
i, i,
i < ntbins ? "T" : i < ntbins + nqbins ? i < ntbins ? "T" : i < ntbins + nqbins ?
"Q" : i < ntbins + nqbins + ncbins ? "C" : "Q" : i < ntbins + nqbins + ncbins ? "C" :
@ -1733,7 +1737,7 @@ arena_stats_lprint(const malloc_large_stats_t *lstats,
gap_start = -1; gap_start = -1;
} }
malloc_cprintf(write4, w4opaque, malloc_cprintf(write4, w4opaque,
"%13zu %5zu %9llu %9zu %9zu\n", "%13zu %5zu %9"PRIu64" %9zu %9zu\n",
(i+1) << PAGE_SHIFT, i+1, (i+1) << PAGE_SHIFT, i+1,
lstats[i].nrequests, lstats[i].nrequests,
lstats[i].highruns, lstats[i].highruns,

View File

@ -278,18 +278,28 @@ stats_print(void (*write4)(void *, const char *, const char *, const char *,
/* Print chunk stats. */ /* Print chunk stats. */
{ {
chunk_stats_t chunks_stats; chunk_stats_t chunks_stats;
#ifdef JEMALLOC_SWAP
size_t swap_avail_chunks;
#endif
malloc_mutex_lock(&huge_mtx); malloc_mutex_lock(&huge_mtx);
chunks_stats = stats_chunks; chunks_stats = stats_chunks;
malloc_mutex_unlock(&huge_mtx); malloc_mutex_unlock(&huge_mtx);
#ifdef JEMALLOC_SWAP
malloc_mutex_lock(&swap_mtx);
swap_avail_chunks = swap_avail >> opt_lg_chunk;
malloc_mutex_unlock(&swap_mtx);
#endif
malloc_cprintf(write4, w4opaque, "chunks: nchunks " malloc_cprintf(write4, w4opaque, "chunks: nchunks "
"highchunks curchunks" "highchunks curchunks"
#ifdef JEMALLOC_SWAP #ifdef JEMALLOC_SWAP
" swap_avail" " swap_avail"
#endif #endif
"\n"); "\n");
malloc_cprintf(write4, w4opaque, " %13llu%13lu%13lu" malloc_cprintf(write4, w4opaque,
" %13"PRIu64"%13zu%13zu"
#ifdef JEMALLOC_SWAP #ifdef JEMALLOC_SWAP
"%13zu" "%13zu"
#endif #endif
@ -297,7 +307,7 @@ stats_print(void (*write4)(void *, const char *, const char *, const char *,
chunks_stats.nchunks, chunks_stats.highchunks, chunks_stats.nchunks, chunks_stats.highchunks,
chunks_stats.curchunks chunks_stats.curchunks
#ifdef JEMALLOC_SWAP #ifdef JEMALLOC_SWAP
, (swap_avail >> opt_lg_chunk) , swap_avail_chunks
#endif #endif
); );
} }
@ -305,7 +315,8 @@ stats_print(void (*write4)(void *, const char *, const char *, const char *,
/* Print chunk stats. */ /* Print chunk stats. */
malloc_cprintf(write4, w4opaque, malloc_cprintf(write4, w4opaque,
"huge: nmalloc ndalloc allocated\n"); "huge: nmalloc ndalloc allocated\n");
malloc_cprintf(write4, w4opaque, " %12llu %12llu %12zu\n", malloc_cprintf(write4, w4opaque,
" %12"PRIu64" %12"PRIu64" %12zu\n",
huge_nmalloc, huge_ndalloc, huge_allocated); huge_nmalloc, huge_ndalloc, huge_allocated);
if (merged) { if (merged) {