summaryrefslogtreecommitdiffstats
path: root/jemalloc/src
diff options
context:
space:
mode:
authorJason Evans <je@facebook.com>2010-03-04 01:45:38 (GMT)
committerJason Evans <je@facebook.com>2010-03-04 01:45:38 (GMT)
commit698805c5252465ddbdcf7048e5ccf16d02533877 (patch)
treeeb6a93dfead69108007951c62f051b38ae2bdb20 /jemalloc/src
parentcfeccd34a37a83804ed56e4562103a6e6f6cabec (diff)
downloadjemalloc-698805c5252465ddbdcf7048e5ccf16d02533877.zip
jemalloc-698805c5252465ddbdcf7048e5ccf16d02533877.tar.gz
jemalloc-698805c5252465ddbdcf7048e5ccf16d02533877.tar.bz2
Simplify malloc_message().
Rather than passing four strings to malloc_message(), malloc_write4(), and all the functions that use them, only pass one string.
Diffstat (limited to 'jemalloc/src')
-rw-r--r--jemalloc/src/arena.c5
-rw-r--r--jemalloc/src/chunk_mmap.c9
-rw-r--r--jemalloc/src/chunk_swap.c12
-rw-r--r--jemalloc/src/jemalloc.c81
-rw-r--r--jemalloc/src/mutex.c5
-rw-r--r--jemalloc/src/prof.c37
-rw-r--r--jemalloc/src/stats.c293
-rw-r--r--jemalloc/src/tcache.c4
8 files changed, 234 insertions, 212 deletions
diff --git a/jemalloc/src/arena.c b/jemalloc/src/arena.c
index a2f2bb1..cd187db 100644
--- a/jemalloc/src/arena.c
+++ b/jemalloc/src/arena.c
@@ -2326,8 +2326,9 @@ arena_boot(void)
*/
if (mbin0 > 256) {
char line_buf[UMAX2S_BUFSIZE];
- malloc_write4("<jemalloc>: Too many small size classes (",
- umax2s(mbin0, 10, line_buf), " > max 256)\n", "");
+ malloc_write("<jemalloc>: Too many small size classes (");
+ malloc_write(umax2s(mbin0, 10, line_buf));
+ malloc_write(" > max 256)\n");
abort();
}
diff --git a/jemalloc/src/chunk_mmap.c b/jemalloc/src/chunk_mmap.c
index 4ab9f3d..8f07113 100644
--- a/jemalloc/src/chunk_mmap.c
+++ b/jemalloc/src/chunk_mmap.c
@@ -52,8 +52,9 @@ pages_map(void *addr, size_t size)
char buf[STRERROR_BUF];
strerror_r(errno, buf, sizeof(buf));
- malloc_write4("<jemalloc>", ": Error in munmap(): ",
- buf, "\n");
+ malloc_write("<jemalloc>: Error in munmap(): ");
+ malloc_write(buf);
+ malloc_write("\n");
if (opt_abort)
abort();
}
@@ -73,7 +74,9 @@ pages_unmap(void *addr, size_t size)
char buf[STRERROR_BUF];
strerror_r(errno, buf, sizeof(buf));
- malloc_write4("<jemalloc>", ": Error in munmap(): ", buf, "\n");
+ malloc_write("<jemalloc>: Error in munmap(): ");
+ malloc_write(buf);
+ malloc_write("\n");
if (opt_abort)
abort();
}
diff --git a/jemalloc/src/chunk_swap.c b/jemalloc/src/chunk_swap.c
index 679633c..b8c880f 100644
--- a/jemalloc/src/chunk_swap.c
+++ b/jemalloc/src/chunk_swap.c
@@ -297,15 +297,17 @@ chunk_swap_enable(const int *fds, unsigned nfds, bool prezeroed)
char buf[STRERROR_BUF];
strerror_r(errno, buf, sizeof(buf));
- malloc_write4("<jemalloc>",
- ": Error in mmap(..., MAP_FIXED, ...): ",
- buf, "\n");
+ malloc_write(
+ "<jemalloc>: Error in mmap(..., MAP_FIXED, ...): ");
+ malloc_write(buf);
+ malloc_write("\n");
if (opt_abort)
abort();
if (munmap(vaddr, voff) == -1) {
strerror_r(errno, buf, sizeof(buf));
- malloc_write4("<jemalloc>",
- ": Error in munmap(): ", buf, "\n");
+ malloc_write("<jemalloc>: Error in munmap(): ");
+ malloc_write(buf);
+ malloc_write("\n");
}
ret = true;
goto RETURN;
diff --git a/jemalloc/src/jemalloc.c b/jemalloc/src/jemalloc.c
index 4d51e1a..dc7879f 100644
--- a/jemalloc/src/jemalloc.c
+++ b/jemalloc/src/jemalloc.c
@@ -151,8 +151,7 @@ static int opt_narenas_lshift = 0;
/******************************************************************************/
/* Function prototypes for non-inline static functions. */
-static void wrtmessage(void *w4opaque, const char *p1, const char *p2,
- const char *p3, const char *p4);
+static void wrtmessage(void *cbopaque, const char *s);
static void stats_print_atexit(void);
static unsigned malloc_ncpus(void);
static bool malloc_init_hard(void);
@@ -168,20 +167,14 @@ JEMALLOC_ATTR(visibility("hidden"))
static
#endif
void
-wrtmessage(void *w4opaque, const char *p1, const char *p2, const char *p3,
- const char *p4)
+wrtmessage(void *cbopaque, const char *s)
{
- if (write(STDERR_FILENO, p1, strlen(p1)) < 0
- || write(STDERR_FILENO, p2, strlen(p2)) < 0
- || write(STDERR_FILENO, p3, strlen(p3)) < 0
- || write(STDERR_FILENO, p4, strlen(p4)) < 0)
- return;
+ write(STDERR_FILENO, s, strlen(s));
}
-void (*JEMALLOC_P(malloc_message))(void *, const char *p1, const char *p2,
- const char *p3, const char *p4) JEMALLOC_ATTR(visibility("default")) =
- wrtmessage;
+void (*JEMALLOC_P(malloc_message))(void *, const char *s)
+ JEMALLOC_ATTR(visibility("default")) = wrtmessage;
/******************************************************************************/
/*
@@ -209,7 +202,7 @@ arenas_extend(unsigned ind)
* by using arenas[0]. In practice, this is an extremely unlikely
* failure.
*/
- malloc_write4("<jemalloc>", ": Error initializing arena\n", "", "");
+ malloc_write("<jemalloc>: Error initializing arena\n");
if (opt_abort)
abort();
@@ -627,10 +620,11 @@ MALLOC_OUT:
cbuf[0] = opts[j];
cbuf[1] = '\0';
- malloc_write4("<jemalloc>",
- ": Unsupported character "
- "in malloc options: '", cbuf,
- "'\n");
+ malloc_write(
+ "<jemalloc>: Unsupported character "
+ "in malloc options: '");
+ malloc_write(cbuf);
+ malloc_write("'\n");
}
}
}
@@ -640,8 +634,7 @@ MALLOC_OUT:
/* Register fork handlers. */
if (pthread_atfork(jemalloc_prefork, jemalloc_postfork,
jemalloc_postfork) != 0) {
- malloc_write4("<jemalloc>", ": Error in pthread_atfork()\n", "",
- "");
+ malloc_write("<jemalloc>: Error in pthread_atfork()\n");
if (opt_abort)
abort();
}
@@ -654,8 +647,7 @@ MALLOC_OUT:
if (opt_stats_print) {
/* Print statistics at exit. */
if (atexit(stats_print_atexit) != 0) {
- malloc_write4("<jemalloc>", ": Error in atexit()\n", "",
- "");
+ malloc_write("<jemalloc>: Error in atexit()\n");
if (opt_abort)
abort();
}
@@ -866,9 +858,8 @@ JEMALLOC_P(malloc)(size_t size)
else {
# ifdef JEMALLOC_XMALLOC
if (opt_xmalloc) {
- malloc_write4("<jemalloc>",
- ": Error in malloc(): invalid size 0\n", "",
- "");
+ malloc_write("<jemalloc>: Error in malloc(): "
+ "invalid size 0\n");
abort();
}
# endif
@@ -891,9 +882,8 @@ OOM:
if (ret == NULL) {
#ifdef JEMALLOC_XMALLOC
if (opt_xmalloc) {
- malloc_write4("<jemalloc>",
- ": Error in malloc(): out of memory\n", "",
- "");
+ malloc_write("<jemalloc>: Error in malloc(): "
+ "out of memory\n");
abort();
}
#endif
@@ -933,9 +923,9 @@ JEMALLOC_P(posix_memalign)(void **memptr, size_t alignment, size_t size)
else {
# ifdef JEMALLOC_XMALLOC
if (opt_xmalloc) {
- malloc_write4("<jemalloc>",
- ": Error in posix_memalign(): "
- "invalid size 0\n", "", "");
+ malloc_write("<jemalloc>: Error in "
+ "posix_memalign(): invalid size "
+ "0\n");
abort();
}
# endif
@@ -952,9 +942,8 @@ JEMALLOC_P(posix_memalign)(void **memptr, size_t alignment, size_t size)
|| alignment < sizeof(void *)) {
#ifdef JEMALLOC_XMALLOC
if (opt_xmalloc) {
- malloc_write4("<jemalloc>",
- ": Error in posix_memalign(): "
- "invalid alignment\n", "", "");
+ malloc_write("<jemalloc>: Error in "
+ "posix_memalign(): invalid alignment\n");
abort();
}
#endif
@@ -976,9 +965,8 @@ JEMALLOC_P(posix_memalign)(void **memptr, size_t alignment, size_t size)
if (result == NULL) {
#ifdef JEMALLOC_XMALLOC
if (opt_xmalloc) {
- malloc_write4("<jemalloc>",
- ": Error in posix_memalign(): out of memory\n",
- "", "");
+ malloc_write("<jemalloc>: Error in posix_memalign(): "
+ "out of memory\n");
abort();
}
#endif
@@ -1051,9 +1039,8 @@ RETURN:
if (ret == NULL) {
#ifdef JEMALLOC_XMALLOC
if (opt_xmalloc) {
- malloc_write4("<jemalloc>",
- ": Error in calloc(): out of memory\n", "",
- "");
+ malloc_write("<jemalloc>: Error in calloc(): out of "
+ "memory\n");
abort();
}
#endif
@@ -1130,9 +1117,8 @@ OOM:
if (ret == NULL) {
#ifdef JEMALLOC_XMALLOC
if (opt_xmalloc) {
- malloc_write4("<jemalloc>",
- ": Error in realloc(): out of "
- "memory\n", "", "");
+ malloc_write("<jemalloc>: Error in realloc(): "
+ "out of memory\n");
abort();
}
#endif
@@ -1163,9 +1149,8 @@ OOM:
if (ret == NULL) {
#ifdef JEMALLOC_XMALLOC
if (opt_xmalloc) {
- malloc_write4("<jemalloc>",
- ": Error in realloc(): out of "
- "memory\n", "", "");
+ malloc_write("<jemalloc>: Error in realloc(): "
+ "out of memory\n");
abort();
}
#endif
@@ -1239,11 +1224,11 @@ JEMALLOC_P(malloc_swap_enable)(const int *fds, unsigned nfds, int prezeroed)
JEMALLOC_ATTR(visibility("default"))
void
-JEMALLOC_P(malloc_stats_print)(void (*write4)(void *, const char *,
- const char *, const char *, const char *), void *w4opaque, const char *opts)
+JEMALLOC_P(malloc_stats_print)(void (*write_cb)(void *, const char *),
+ void *cbopaque, const char *opts)
{
- stats_print(write4, w4opaque, opts);
+ stats_print(write_cb, cbopaque, opts);
}
JEMALLOC_ATTR(visibility("default"))
diff --git a/jemalloc/src/mutex.c b/jemalloc/src/mutex.c
index 7425027..3b6081a 100644
--- a/jemalloc/src/mutex.c
+++ b/jemalloc/src/mutex.c
@@ -28,9 +28,8 @@ pthread_create_once(void)
pthread_create_fptr = dlsym(RTLD_NEXT, "pthread_create");
if (pthread_create_fptr == NULL) {
- malloc_write4("<jemalloc>",
- ": Error in dlsym(RTLD_NEXT, \"pthread_create\")\n", "",
- "");
+ malloc_write("<jemalloc>: Error in dlsym(RTLD_NEXT, "
+ "\"pthread_create\")\n");
abort();
}
diff --git a/jemalloc/src/prof.c b/jemalloc/src/prof.c
index 6686c96..1a667a9 100644
--- a/jemalloc/src/prof.c
+++ b/jemalloc/src/prof.c
@@ -738,9 +738,8 @@ prof_flush(bool propagate_err)
err = write(prof_dump_fd, prof_dump_buf, prof_dump_buf_end);
if (err == -1) {
if (propagate_err == false) {
- malloc_write4("<jemalloc>",
- ": write() failed during heap profile flush", "\n",
- "");
+ malloc_write("<jemalloc>: write() failed during heap "
+ "profile flush\n");
if (opt_abort)
abort();
}
@@ -924,8 +923,9 @@ prof_dump(const char *filename, bool leakcheck, bool propagate_err)
prof_dump_fd = creat(filename, 0644);
if (prof_dump_fd == -1) {
if (propagate_err == false) {
- malloc_write4("<jemalloc>",
- ": creat(\"", filename, "\", 0644) failed\n");
+ malloc_write("<jemalloc>: creat(\"");
+ malloc_write(filename);
+ malloc_write("\", 0644) failed\n");
if (opt_abort)
abort();
}
@@ -980,15 +980,17 @@ prof_dump(const char *filename, bool leakcheck, bool propagate_err)
prof_leave();
if (leakcheck && cnt_all.curbytes != 0) {
- malloc_write4("<jemalloc>: Leak summary: ",
- umax2s(cnt_all.curbytes, 10, buf),
- (cnt_all.curbytes != 1) ? " bytes" : " byte", ", ");
- malloc_write4(umax2s(cnt_all.curobjs, 10, buf),
- (cnt_all.curobjs != 1) ? " objects" : " object", ", ", "");
- malloc_write4(umax2s(leak_nctx, 10, buf),
- (leak_nctx != 1) ? " contexts" : " context", "\n", "");
- malloc_write4("<jemalloc>: Run pprof on \"",
- filename, "\" for leak detail\n", "");
+ malloc_write("<jemalloc>: Leak summary: ");
+ malloc_write(umax2s(cnt_all.curbytes, 10, buf));
+ malloc_write((cnt_all.curbytes != 1) ? " bytes, " : " byte, ");
+ malloc_write(umax2s(cnt_all.curobjs, 10, buf));
+ malloc_write((cnt_all.curobjs != 1) ? " objects, " :
+ " object, ");
+ malloc_write(umax2s(leak_nctx, 10, buf));
+ malloc_write((leak_nctx != 1) ? " contexts\n" : " context\n");
+ malloc_write("<jemalloc>: Run pprof on \"");
+ malloc_write(filename);
+ malloc_write("\" for leak detail\n");
}
return (false);
@@ -1284,8 +1286,8 @@ prof_boot1(void)
return (true);
if (pthread_key_create(&bt2cnt_tsd, bt2cnt_thread_cleanup)
!= 0) {
- malloc_write4("<jemalloc>",
- ": Error in pthread_key_create()\n", "", "");
+ malloc_write(
+ "<jemalloc>: Error in pthread_key_create()\n");
abort();
}
@@ -1300,8 +1302,7 @@ prof_boot1(void)
enq_udump = false;
if (atexit(prof_fdump) != 0) {
- malloc_write4("<jemalloc>", ": Error in atexit()\n", "",
- "");
+ malloc_write("<jemalloc>: Error in atexit()\n");
if (opt_abort)
abort();
}
diff --git a/jemalloc/src/stats.c b/jemalloc/src/stats.c
index f8c1731..dfc2f93 100644
--- a/jemalloc/src/stats.c
+++ b/jemalloc/src/stats.c
@@ -43,15 +43,14 @@ bool opt_stats_print = false;
/* Function prototypes for non-inline static functions. */
#ifdef JEMALLOC_STATS
-static void malloc_vcprintf(void (*write4)(void *, const char *,
- const char *, const char *, const char *), void *w4opaque,
- const char *format, va_list ap);
-static void stats_arena_bins_print(void (*write4)(void *, const char *,
- const char *, const char *, const char *), void *w4opaque, unsigned i);
-static void stats_arena_lruns_print(void (*write4)(void *, const char *,
- const char *, const char *, const char *), void *w4opaque, unsigned i);
-static void stats_arena_print(void (*write4)(void *, const char *,
- const char *, const char *, const char *), void *w4opaque, unsigned i);
+static void malloc_vcprintf(void (*write_cb)(void *, const char *),
+ void *cbopaque, const char *format, va_list ap);
+static void stats_arena_bins_print(void (*write_cb)(void *, const char *),
+ void *cbopaque, unsigned i);
+static void stats_arena_lruns_print(void (*write_cb)(void *, const char *),
+ void *cbopaque, unsigned i);
+static void stats_arena_print(void (*write_cb)(void *, const char *),
+ void *cbopaque, unsigned i);
#endif
/******************************************************************************/
@@ -97,23 +96,23 @@ umax2s(uintmax_t x, unsigned base, char *s)
#ifdef JEMALLOC_STATS
static void
-malloc_vcprintf(void (*write4)(void *, const char *, const char *, const char *,
- const char *), void *w4opaque, const char *format, va_list ap)
+malloc_vcprintf(void (*write_cb)(void *, const char *), void *cbopaque,
+ const char *format, va_list ap)
{
char buf[4096];
- if (write4 == NULL) {
+ if (write_cb == NULL) {
/*
- * The caller did not provide an alternate write4 callback
- * function, so use the default one. malloc_write4() is an
+ * The caller did not provide an alternate write_cb callback
+ * function, so use the default one. malloc_write() is an
* inline function, so use malloc_message() directly here.
*/
- write4 = JEMALLOC_P(malloc_message);
- w4opaque = NULL;
+ write_cb = JEMALLOC_P(malloc_message);
+ cbopaque = NULL;
}
vsnprintf(buf, sizeof(buf), format, ap);
- write4(w4opaque, buf, "", "", "");
+ write_cb(cbopaque, buf);
}
/*
@@ -122,13 +121,13 @@ malloc_vcprintf(void (*write4)(void *, const char *, const char *, const char *,
*/
JEMALLOC_ATTR(format(printf, 3, 4))
void
-malloc_cprintf(void (*write4)(void *, const char *, const char *, const char *,
- const char *), void *w4opaque, const char *format, ...)
+malloc_cprintf(void (*write_cb)(void *, const char *), void *cbopaque,
+ const char *format, ...)
{
va_list ap;
va_start(ap, format);
- malloc_vcprintf(write4, w4opaque, format, ap);
+ malloc_vcprintf(write_cb, cbopaque, format, ap);
va_end(ap);
}
@@ -149,8 +148,8 @@ malloc_printf(const char *format, ...)
#ifdef JEMALLOC_STATS
static void
-stats_arena_bins_print(void (*write4)(void *, const char *, const char *,
- const char *, const char *), void *w4opaque, unsigned i)
+stats_arena_bins_print(void (*write_cb)(void *, const char *), void *cbopaque,
+ unsigned i)
{
size_t pagesize;
bool config_tcache;
@@ -160,11 +159,11 @@ stats_arena_bins_print(void (*write4)(void *, const char *, const char *,
CTL_GET("config.tcache", &config_tcache, bool);
if (config_tcache) {
- malloc_cprintf(write4, w4opaque,
+ malloc_cprintf(write_cb, cbopaque,
"bins: bin size regs pgs nrequests "
"nfills nflushes newruns reruns maxruns curruns\n");
} else {
- malloc_cprintf(write4, w4opaque,
+ malloc_cprintf(write_cb, cbopaque,
"bins: bin size regs pgs nrequests "
"newruns reruns maxruns curruns\n");
}
@@ -186,12 +185,12 @@ stats_arena_bins_print(void (*write4)(void *, const char *, const char *,
if (gap_start != UINT_MAX) {
if (j > gap_start + 1) {
/* Gap of more than one size class. */
- malloc_cprintf(write4, w4opaque,
+ malloc_cprintf(write_cb, cbopaque,
"[%u..%u]\n", gap_start,
j - 1);
} else {
/* Gap of one size class. */
- malloc_cprintf(write4, w4opaque,
+ malloc_cprintf(write_cb, cbopaque,
"[%u]\n", gap_start);
}
gap_start = UINT_MAX;
@@ -218,7 +217,7 @@ stats_arena_bins_print(void (*write4)(void *, const char *, const char *,
CTL_IJ_GET("stats.arenas.0.bins.0.curruns", &curruns,
size_t);
if (config_tcache) {
- malloc_cprintf(write4, w4opaque,
+ malloc_cprintf(write_cb, cbopaque,
"%13u %1s %5zu %4u %3zu %10"PRIu64
" %9"PRIu64" %9"PRIu64" %9"PRIu64""
" %9"PRIu64" %7zu %7zu\n",
@@ -231,7 +230,7 @@ stats_arena_bins_print(void (*write4)(void *, const char *, const char *,
nrequests, nfills, nflushes, nruns, reruns,
highruns, curruns);
} else {
- malloc_cprintf(write4, w4opaque,
+ malloc_cprintf(write_cb, cbopaque,
"%13u %1s %5zu %4u %3zu %10"PRIu64
" %9"PRIu64" %9"PRIu64" %7zu %7zu\n",
j,
@@ -248,25 +247,25 @@ stats_arena_bins_print(void (*write4)(void *, const char *, const char *,
if (gap_start != UINT_MAX) {
if (j > gap_start + 1) {
/* Gap of more than one size class. */
- malloc_cprintf(write4, w4opaque, "[%u..%u]\n",
+ malloc_cprintf(write_cb, cbopaque, "[%u..%u]\n",
gap_start, j - 1);
} else {
/* Gap of one size class. */
- malloc_cprintf(write4, w4opaque, "[%u]\n", gap_start);
+ malloc_cprintf(write_cb, cbopaque, "[%u]\n", gap_start);
}
}
}
static void
-stats_arena_lruns_print(void (*write4)(void *, const char *, const char *,
- const char *, const char *), void *w4opaque, unsigned i)
+stats_arena_lruns_print(void (*write_cb)(void *, const char *), void *cbopaque,
+ unsigned i)
{
size_t pagesize, nlruns, j;
ssize_t gap_start;
CTL_GET("arenas.pagesize", &pagesize, size_t);
- malloc_cprintf(write4, w4opaque,
+ malloc_cprintf(write_cb, cbopaque,
"large: size pages nrequests maxruns curruns\n");
CTL_GET("arenas.nlruns", &nlruns, size_t);
for (j = 0, gap_start = -1; j < nlruns; j++) {
@@ -285,23 +284,23 @@ stats_arena_lruns_print(void (*write4)(void *, const char *, const char *,
CTL_IJ_GET("stats.arenas.0.lruns.0.curruns", &curruns,
size_t);
if (gap_start != -1) {
- malloc_cprintf(write4, w4opaque, "[%zu]\n",
+ malloc_cprintf(write_cb, cbopaque, "[%zu]\n",
j - gap_start);
gap_start = -1;
}
- malloc_cprintf(write4, w4opaque,
+ malloc_cprintf(write_cb, cbopaque,
"%13zu %5zu %9"PRIu64" %9zu %9zu\n",
run_size, run_size / pagesize, nrequests, highruns,
curruns);
}
}
if (gap_start != -1)
- malloc_cprintf(write4, w4opaque, "[%zu]\n", j - gap_start);
+ malloc_cprintf(write_cb, cbopaque, "[%zu]\n", j - gap_start);
}
static void
-stats_arena_print(void (*write4)(void *, const char *, const char *,
- const char *, const char *), void *w4opaque, unsigned i)
+stats_arena_print(void (*write_cb)(void *, const char *), void *cbopaque,
+ unsigned i)
{
size_t pagesize, pactive, pdirty, mapped;
uint64_t npurge, nmadvise, purged;
@@ -319,50 +318,50 @@ stats_arena_print(void (*write4)(void *, const char *, const char *,
CTL_I_GET("stats.arenas.0.npurge", &npurge, uint64_t);
CTL_I_GET("stats.arenas.0.nmadvise", &nmadvise, uint64_t);
CTL_I_GET("stats.arenas.0.purged", &purged, uint64_t);
- malloc_cprintf(write4, w4opaque,
+ malloc_cprintf(write_cb, cbopaque,
"dirty pages: %zu:%zu active:dirty, %"PRIu64" sweep%s,"
" %"PRIu64" madvise%s, %"PRIu64" purged\n",
pactive, pdirty, npurge, npurge == 1 ? "" : "s",
nmadvise, nmadvise == 1 ? "" : "s", purged);
- malloc_cprintf(write4, w4opaque,
+ malloc_cprintf(write_cb, cbopaque,
" allocated nmalloc ndalloc\n");
CTL_I_GET("stats.arenas.0.small.allocated", &small_allocated, size_t);
CTL_I_GET("stats.arenas.0.small.nmalloc", &small_nmalloc, uint64_t);
CTL_I_GET("stats.arenas.0.small.ndalloc", &small_ndalloc, uint64_t);
- malloc_cprintf(write4, w4opaque,
+ malloc_cprintf(write_cb, cbopaque,
"small: %12zu %12"PRIu64" %12"PRIu64"\n",
small_allocated, small_nmalloc, small_ndalloc);
CTL_I_GET("stats.arenas.0.medium.allocated", &medium_allocated, size_t);
CTL_I_GET("stats.arenas.0.medium.nmalloc", &medium_nmalloc, uint64_t);
CTL_I_GET("stats.arenas.0.medium.ndalloc", &medium_ndalloc, uint64_t);
- malloc_cprintf(write4, w4opaque,
+ malloc_cprintf(write_cb, cbopaque,
"medium: %12zu %12"PRIu64" %12"PRIu64"\n",
medium_allocated, medium_nmalloc, medium_ndalloc);
CTL_I_GET("stats.arenas.0.large.allocated", &large_allocated, size_t);
CTL_I_GET("stats.arenas.0.large.nmalloc", &large_nmalloc, uint64_t);
CTL_I_GET("stats.arenas.0.large.ndalloc", &large_ndalloc, uint64_t);
- malloc_cprintf(write4, w4opaque,
+ malloc_cprintf(write_cb, cbopaque,
"large: %12zu %12"PRIu64" %12"PRIu64"\n",
large_allocated, large_nmalloc, large_ndalloc);
- malloc_cprintf(write4, w4opaque,
+ malloc_cprintf(write_cb, cbopaque,
"total: %12zu %12"PRIu64" %12"PRIu64"\n",
small_allocated + medium_allocated + large_allocated,
small_nmalloc + medium_nmalloc + large_nmalloc,
small_ndalloc + medium_ndalloc + large_ndalloc);
- malloc_cprintf(write4, w4opaque, "active: %12zu\n",
+ malloc_cprintf(write_cb, cbopaque, "active: %12zu\n",
pactive * pagesize );
CTL_I_GET("stats.arenas.0.mapped", &mapped, size_t);
- malloc_cprintf(write4, w4opaque, "mapped: %12zu\n", mapped);
+ malloc_cprintf(write_cb, cbopaque, "mapped: %12zu\n", mapped);
- stats_arena_bins_print(write4, w4opaque, i);
- stats_arena_lruns_print(write4, w4opaque, i);
+ stats_arena_bins_print(write_cb, cbopaque, i);
+ stats_arena_lruns_print(write_cb, cbopaque, i);
}
#endif
void
-stats_print(void (*write4)(void *, const char *, const char *, const char *,
- const char *), void *w4opaque, const char *opts)
+stats_print(void (*write_cb)(void *, const char *), void *cbopaque,
+ const char *opts)
{
uint64_t epoch;
size_t u64sz;
@@ -378,14 +377,14 @@ stats_print(void (*write4)(void *, const char *, const char *, const char *,
u64sz = sizeof(uint64_t);
xmallctl("epoch", &epoch, &u64sz, &epoch, sizeof(uint64_t));
- if (write4 == NULL) {
+ if (write_cb == NULL) {
/*
- * The caller did not provide an alternate write4 callback
- * function, so use the default one. malloc_write4() is an
+ * The caller did not provide an alternate write_cb callback
+ * function, so use the default one. malloc_write() is an
* inline function, so use malloc_message() directly here.
*/
- write4 = JEMALLOC_P(malloc_message);
- w4opaque = NULL;
+ write_cb = JEMALLOC_P(malloc_message);
+ cbopaque = NULL;
}
if (opts != NULL) {
@@ -413,7 +412,7 @@ stats_print(void (*write4)(void *, const char *, const char *, const char *,
}
}
- write4(w4opaque, "___ Begin jemalloc statistics ___\n", "", "", "");
+ write_cb(cbopaque, "___ Begin jemalloc statistics ___\n");
if (general) {
int err;
bool bv;
@@ -425,141 +424,173 @@ stats_print(void (*write4)(void *, const char *, const char *, const char *,
ssz = sizeof(size_t);
CTL_GET("config.debug", &bv, bool);
- write4(w4opaque, "Assertions ", bv ? "enabled" : "disabled",
- "\n", "");
+ write_cb(cbopaque, "Assertions ");
+ write_cb(cbopaque, bv ? "enabled" : "disabled");
+ write_cb(cbopaque, "\n");
- write4(w4opaque, "Boolean JEMALLOC_OPTIONS: ", "", "", "");
+ write_cb(cbopaque, "Boolean JEMALLOC_OPTIONS: ");
if ((err = JEMALLOC_P(mallctl)("opt.abort", &bv, &bsz, NULL, 0))
== 0)
- write4(w4opaque, bv ? "A" : "a", "", "", "");
+ write_cb(cbopaque, bv ? "A" : "a");
if ((err = JEMALLOC_P(mallctl)("opt.prof", &bv, &bsz, NULL, 0))
== 0)
- write4(w4opaque, bv ? "F" : "f", "", "", "");
+ write_cb(cbopaque, bv ? "F" : "f");
if ((err = JEMALLOC_P(mallctl)("opt.junk", &bv, &bsz, NULL, 0))
== 0)
- write4(w4opaque, bv ? "J" : "j", "", "", "");
+ write_cb(cbopaque, bv ? "J" : "j");
if ((err = JEMALLOC_P(mallctl)("opt.prof_leak", &bv, &bsz, NULL,
0)) == 0)
- write4(w4opaque, bv ? "L" : "l", "", "", "");
+ write_cb(cbopaque, bv ? "L" : "l");
if ((err = JEMALLOC_P(mallctl)("opt.overcommit", &bv, &bsz,
NULL, 0)) == 0)
- write4(w4opaque, bv ? "O" : "o", "", "", "");
- write4(w4opaque, "P", "", "", "");
+ write_cb(cbopaque, bv ? "O" : "o");
+ write_cb(cbopaque, "P");
if ((err = JEMALLOC_P(mallctl)("opt.prof_udump", &bv, &bsz,
NULL, 0)) == 0)
- write4(w4opaque, bv ? "U" : "u", "", "", "");
+ write_cb(cbopaque, bv ? "U" : "u");
if ((err = JEMALLOC_P(mallctl)("opt.sysv", &bv, &bsz, NULL, 0))
== 0)
- write4(w4opaque, bv ? "V" : "v", "", "", "");
+ write_cb(cbopaque, bv ? "V" : "v");
if ((err = JEMALLOC_P(mallctl)("opt.xmalloc", &bv, &bsz, NULL,
0)) == 0)
- write4(w4opaque, bv ? "X" : "x", "", "", "");
+ write_cb(cbopaque, bv ? "X" : "x");
if ((err = JEMALLOC_P(mallctl)("opt.zero", &bv, &bsz, NULL, 0))
== 0)
- write4(w4opaque, bv ? "Z" : "z", "", "", "");
- write4(w4opaque, "\n", "", "", "");
+ write_cb(cbopaque, bv ? "Z" : "z");
+ write_cb(cbopaque, "\n");
- write4(w4opaque, "CPUs: ", umax2s(ncpus, 10, s), "\n", "");
+ write_cb(cbopaque, "CPUs: ");
+ write_cb(cbopaque, umax2s(ncpus, 10, s));
+ write_cb(cbopaque, "\n");
CTL_GET("arenas.narenas", &uv, unsigned);
- write4(w4opaque, "Max arenas: ", umax2s(uv, 10, s), "\n", "");
+ write_cb(cbopaque, "Max arenas: ");
+ write_cb(cbopaque, umax2s(uv, 10, s));
+ write_cb(cbopaque, "\n");
- write4(w4opaque, "Pointer size: ", umax2s(sizeof(void *), 10,
- s), "\n", "");
+ write_cb(cbopaque, "Pointer size: ");
+ write_cb(cbopaque, umax2s(sizeof(void *), 10, s));
+ write_cb(cbopaque, "\n");
CTL_GET("arenas.quantum", &sv, size_t);
- write4(w4opaque, "Quantum size: ", umax2s(sv, 10, s), "\n", "");
+ write_cb(cbopaque, "Quantum size: ");
+ write_cb(cbopaque, umax2s(sv, 10, s));
+ write_cb(cbopaque, "\n");
CTL_GET("arenas.cacheline", &sv, size_t);
- write4(w4opaque, "Cacheline size (assumed): ", umax2s(sv, 10,
- s), "\n", "");
+ write_cb(cbopaque, "Cacheline size (assumed): ");
+ write_cb(cbopaque, umax2s(sv, 10, s));
+ write_cb(cbopaque, "\n");
CTL_GET("arenas.subpage", &sv, size_t);
- write4(w4opaque, "Subpage spacing: ", umax2s(sv, 10, s), "\n",
- "");
+ write_cb(cbopaque, "Subpage spacing: ");
+ write_cb(cbopaque, umax2s(sv, 10, s));
+ write_cb(cbopaque, "\n");
CTL_GET("arenas.medium", &sv, size_t);
- write4(w4opaque, "Medium spacing: ", umax2s(sv, 10, s), "\n",
- "");
+ write_cb(cbopaque, "Medium spacing: ");
+ write_cb(cbopaque, umax2s(sv, 10, s));
+ write_cb(cbopaque, "\n");
if ((err = JEMALLOC_P(mallctl)("arenas.tspace_min", &sv, &ssz,
NULL, 0)) == 0) {
- write4(w4opaque, "Tiny 2^n-spaced sizes: [", umax2s(sv,
- 10, s), "..", "");
+ write_cb(cbopaque, "Tiny 2^n-spaced sizes: [");
+ write_cb(cbopaque, umax2s(sv, 10, s));
+ write_cb(cbopaque, "..");
CTL_GET("arenas.tspace_max", &sv, size_t);
- write4(w4opaque, umax2s(sv, 10, s), "]\n", "", "");
+ write_cb(cbopaque, umax2s(sv, 10, s));
+ write_cb(cbopaque, "]\n");
}
CTL_GET("arenas.qspace_min", &sv, size_t);
- write4(w4opaque, "Quantum-spaced sizes: [", umax2s(sv, 10, s),
- "..", "");
+ write_cb(cbopaque, "Quantum-spaced sizes: [");
+ write_cb(cbopaque, umax2s(sv, 10, s));
+ write_cb(cbopaque, "..");
CTL_GET("arenas.qspace_max", &sv, size_t);
- write4(w4opaque, umax2s(sv, 10, s), "]\n", "", "");
+ write_cb(cbopaque, umax2s(sv, 10, s));
+ write_cb(cbopaque, "]\n");
CTL_GET("arenas.cspace_min", &sv, size_t);
- write4(w4opaque, "Cacheline-spaced sizes: [", umax2s(sv, 10, s),
- "..", "");
+ write_cb(cbopaque, "Cacheline-spaced sizes: [");
+ write_cb(cbopaque, umax2s(sv, 10, s));
+ write_cb(cbopaque, "..");
CTL_GET("arenas.cspace_max", &sv, size_t);
- write4(w4opaque, umax2s(sv, 10, s), "]\n", "", "");
+ write_cb(cbopaque, umax2s(sv, 10, s));
+ write_cb(cbopaque, "]\n");
CTL_GET("arenas.sspace_min", &sv, size_t);
- write4(w4opaque, "Subpage-spaced sizes: [", umax2s(sv, 10, s),
- "..", "");
+ write_cb(cbopaque, "Subpage-spaced sizes: [");
+ write_cb(cbopaque, umax2s(sv, 10, s));
+ write_cb(cbopaque, "..");
CTL_GET("arenas.sspace_max", &sv, size_t);
- write4(w4opaque, umax2s(sv, 10, s), "]\n", "", "");
+ write_cb(cbopaque, umax2s(sv, 10, s));
+ write_cb(cbopaque, "]\n");
CTL_GET("arenas.medium_min", &sv, size_t);
- write4(w4opaque, "Medium sizes: [", umax2s(sv, 10, s), "..",
- "");
+ write_cb(cbopaque, "Medium sizes: [");
+ write_cb(cbopaque, umax2s(sv, 10, s));
+ write_cb(cbopaque, "..");
CTL_GET("arenas.medium_max", &sv, size_t);
- write4(w4opaque, umax2s(sv, 10, s), "]\n", "", "");
+ write_cb(cbopaque, umax2s(sv, 10, s));
+ write_cb(cbopaque, "]\n");
CTL_GET("opt.lg_dirty_mult", &ssv, ssize_t);
if (ssv >= 0) {
- write4(w4opaque,
- "Min active:dirty page ratio per arena: ",
- umax2s((1U << ssv), 10, s), ":1\n", "");
+ write_cb(cbopaque,
+ "Min active:dirty page ratio per arena: ");
+ write_cb(cbopaque, umax2s((1U << ssv), 10, s));
+ write_cb(cbopaque, ":1\n");
} else {
- write4(w4opaque,
- "Min active:dirty page ratio per arena: N/A\n", "",
- "", "");
+ write_cb(cbopaque,
+ "Min active:dirty page ratio per arena: N/A\n");
}
if ((err = JEMALLOC_P(mallctl)("opt.lg_tcache_nslots", &sv,
&ssz, NULL, 0)) == 0) {
size_t tcache_nslots, tcache_gc_sweep;
tcache_nslots = (1U << sv);
- write4(w4opaque, "Thread cache slots per size class: ",
- tcache_nslots ? umax2s(tcache_nslots, 10, s) :
- "N/A", "\n", "");
+ write_cb(cbopaque,
+ "Thread cache slots per size class: ");
+ write_cb(cbopaque, tcache_nslots ?
+ umax2s(tcache_nslots, 10, s) : "N/A");
+ write_cb(cbopaque, "\n");
CTL_GET("opt.lg_tcache_gc_sweep", &ssv, ssize_t);
tcache_gc_sweep = (1U << ssv);
- write4(w4opaque, "Thread cache GC sweep interval: ",
- tcache_nslots && ssv >= 0 ? umax2s(tcache_gc_sweep,
- 10, s) : "N/A", "\n", "");
+ write_cb(cbopaque, "Thread cache GC sweep interval: ");
+ write_cb(cbopaque, tcache_nslots && ssv >= 0 ?
+ umax2s(tcache_gc_sweep, 10, s) : "N/A");
+ write_cb(cbopaque, "\n");
}
if ((err = JEMALLOC_P(mallctl)("opt.prof", &bv, &bsz, NULL, 0))
== 0 && bv) {
xmallctl("opt.lg_prof_bt_max", &sv, &ssz, NULL, 0);
- write4(w4opaque, "Maximum profile backtrace depth: ",
- umax2s((1U << sv), 10, s), "\n", "");
+ write_cb(cbopaque, "Maximum profile backtrace depth: ");
+ write_cb(cbopaque, umax2s((1U << sv), 10, s));
+ write_cb(cbopaque, "\n");
xmallctl("opt.lg_prof_sample", &sv, &ssz, NULL, 0);
- write4(w4opaque, "Average profile sample interval: ",
- umax2s((1U << sv), 10, s), "", "");
- write4(w4opaque, " (2^", umax2s(sv, 10, s), ")\n", "");
+ write_cb(cbopaque, "Average profile sample interval: ");
+ write_cb(cbopaque, umax2s((1U << sv), 10, s));
+ write_cb(cbopaque, " (2^");
+ write_cb(cbopaque, umax2s(sv, 10, s));
+ write_cb(cbopaque, ")\n");
xmallctl("opt.lg_prof_interval", &sv, &ssz, NULL, 0);
- write4(w4opaque, "Average profile dump interval: ",
- umax2s((1U << sv), 10, s), "", "");
- write4(w4opaque, " (2^", umax2s(sv, 10, s), ")\n", "");
+ write_cb(cbopaque, "Average profile dump interval: ");
+ write_cb(cbopaque, umax2s((1U << sv), 10, s));
+ write_cb(cbopaque, " (2^");
+ write_cb(cbopaque, umax2s(sv, 10, s));
+ write_cb(cbopaque, ")\n");
}
CTL_GET("arenas.chunksize", &sv, size_t);
- write4(w4opaque, "Chunk size: ", umax2s(sv, 10, s), "", "");
+ write_cb(cbopaque, "Chunk size: ");
+ write_cb(cbopaque, umax2s(sv, 10, s));
CTL_GET("opt.lg_chunk", &sv, size_t);
- write4(w4opaque, " (2^", umax2s(sv, 10, s), ")\n", "");
+ write_cb(cbopaque, " (2^");
+ write_cb(cbopaque, umax2s(sv, 10, s));
+ write_cb(cbopaque, ")\n");
}
#ifdef JEMALLOC_STATS
@@ -577,7 +608,7 @@ stats_print(void (*write4)(void *, const char *, const char *, const char *,
CTL_GET("stats.allocated", &allocated, size_t);
CTL_GET("stats.active", &active, size_t);
CTL_GET("stats.mapped", &mapped, size_t);
- malloc_cprintf(write4, w4opaque,
+ malloc_cprintf(write_cb, cbopaque,
"Allocated: %zu, active: %zu, mapped: %zu\n", allocated,
active, mapped);
@@ -589,17 +620,17 @@ stats_print(void (*write4)(void *, const char *, const char *, const char *,
NULL, 0)) == 0) {
size_t lg_chunk;
- malloc_cprintf(write4, w4opaque, "chunks: nchunks "
+ malloc_cprintf(write_cb, cbopaque, "chunks: nchunks "
"highchunks curchunks swap_avail\n");
CTL_GET("opt.lg_chunk", &lg_chunk, size_t);
- malloc_cprintf(write4, w4opaque,
+ malloc_cprintf(write_cb, cbopaque,
" %13"PRIu64"%13zu%13zu%13zu\n",
chunks_total, chunks_high, chunks_current,
swap_avail << lg_chunk);
} else {
- malloc_cprintf(write4, w4opaque, "chunks: nchunks "
+ malloc_cprintf(write_cb, cbopaque, "chunks: nchunks "
"highchunks curchunks\n");
- malloc_cprintf(write4, w4opaque,
+ malloc_cprintf(write_cb, cbopaque,
" %13"PRIu64"%13zu%13zu\n",
chunks_total, chunks_high, chunks_current);
}
@@ -608,9 +639,9 @@ stats_print(void (*write4)(void *, const char *, const char *, const char *,
CTL_GET("stats.huge.nmalloc", &huge_nmalloc, uint64_t);
CTL_GET("stats.huge.ndalloc", &huge_ndalloc, uint64_t);
CTL_GET("stats.huge.allocated", &huge_allocated, size_t);
- malloc_cprintf(write4, w4opaque,
+ malloc_cprintf(write_cb, cbopaque,
"huge: nmalloc ndalloc allocated\n");
- malloc_cprintf(write4, w4opaque,
+ malloc_cprintf(write_cb, cbopaque,
" %12"PRIu64" %12"PRIu64" %12zu\n",
huge_nmalloc, huge_ndalloc, huge_allocated);
@@ -633,9 +664,9 @@ stats_print(void (*write4)(void *, const char *, const char *, const char *,
if (ninitialized > 1) {
/* Print merged arena stats. */
- malloc_cprintf(write4, w4opaque,
+ malloc_cprintf(write_cb, cbopaque,
"\nMerged arenas stats:\n");
- stats_arena_print(write4, w4opaque,
+ stats_arena_print(write_cb, cbopaque,
narenas);
}
}
@@ -658,15 +689,15 @@ stats_print(void (*write4)(void *, const char *, const char *, const char *,
for (i = 0; i < narenas; i++) {
if (initialized[i]) {
- malloc_cprintf(write4, w4opaque,
+ malloc_cprintf(write_cb, cbopaque,
"\narenas[%u]:\n", i);
- stats_arena_print(write4,
- w4opaque, i);
+ stats_arena_print(write_cb,
+ cbopaque, i);
}
}
}
}
}
#endif /* #ifdef JEMALLOC_STATS */
- write4(w4opaque, "--- End jemalloc statistics ---\n", "", "", "");
+ write_cb(cbopaque, "--- End jemalloc statistics ---\n");
}
diff --git a/jemalloc/src/tcache.c b/jemalloc/src/tcache.c
index d64ebac..e1b1031 100644
--- a/jemalloc/src/tcache.c
+++ b/jemalloc/src/tcache.c
@@ -325,8 +325,8 @@ tcache_boot(void)
if (tcache_nslots != 0) {
if (pthread_key_create(&tcache_tsd, tcache_thread_cleanup) !=
0) {
- malloc_write4("<jemalloc>",
- ": Error in pthread_key_create()\n", "", "");
+ malloc_write(
+ "<jemalloc>: Error in pthread_key_create()\n");
abort();
}
}