mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-07-23 17:17:19 +03:00
Track per size class internal fragmentation
This commit is contained in:
parent
afa489c3c5
commit
40fa4d29d3
15 changed files with 203 additions and 6 deletions
|
|
@ -136,6 +136,7 @@ CTL_PROTO(opt_prof_final)
|
|||
CTL_PROTO(opt_prof_leak)
|
||||
CTL_PROTO(opt_prof_accum)
|
||||
CTL_PROTO(opt_prof_recent_alloc_max)
|
||||
CTL_PROTO(opt_prof_stats)
|
||||
CTL_PROTO(opt_prof_sys_thread_name)
|
||||
CTL_PROTO(opt_prof_time_res)
|
||||
CTL_PROTO(opt_zero_realloc)
|
||||
|
|
@ -415,6 +416,7 @@ static const ctl_named_node_t opt_node[] = {
|
|||
{NAME("prof_leak"), CTL(opt_prof_leak)},
|
||||
{NAME("prof_accum"), CTL(opt_prof_accum)},
|
||||
{NAME("prof_recent_alloc_max"), CTL(opt_prof_recent_alloc_max)},
|
||||
{NAME("prof_stats"), CTL(opt_prof_stats)},
|
||||
{NAME("prof_sys_thread_name"), CTL(opt_prof_sys_thread_name)},
|
||||
{NAME("prof_time_resolution"), CTL(opt_prof_time_res)},
|
||||
{NAME("zero_realloc"), CTL(opt_zero_realloc)}
|
||||
|
|
@ -2057,6 +2059,7 @@ CTL_RO_NL_CGEN(config_prof, opt_prof_final, opt_prof_final, bool)
|
|||
CTL_RO_NL_CGEN(config_prof, opt_prof_leak, opt_prof_leak, bool)
|
||||
CTL_RO_NL_CGEN(config_prof, opt_prof_recent_alloc_max,
|
||||
opt_prof_recent_alloc_max, ssize_t)
|
||||
CTL_RO_NL_CGEN(config_prof, opt_prof_stats, opt_prof_stats, bool)
|
||||
CTL_RO_NL_CGEN(config_prof, opt_prof_sys_thread_name, opt_prof_sys_thread_name,
|
||||
bool)
|
||||
CTL_RO_NL_CGEN(config_prof, opt_prof_time_res,
|
||||
|
|
|
|||
|
|
@ -1552,6 +1552,7 @@ malloc_conf_init_helper(sc_data_t *sc_data, unsigned bin_shard_sizes[SC_NBINS],
|
|||
CONF_HANDLE_BOOL(opt_prof_log, "prof_log")
|
||||
CONF_HANDLE_SSIZE_T(opt_prof_recent_alloc_max,
|
||||
"prof_recent_alloc_max", -1, SSIZE_MAX)
|
||||
CONF_HANDLE_BOOL(opt_prof_stats, "prof_stats")
|
||||
CONF_HANDLE_BOOL(opt_prof_sys_thread_name,
|
||||
"prof_sys_thread_name")
|
||||
if (CONF_MATCH("prof_time_resolution")) {
|
||||
|
|
|
|||
31
src/prof.c
31
src/prof.c
|
|
@ -8,6 +8,7 @@
|
|||
#include "jemalloc/internal/prof_data.h"
|
||||
#include "jemalloc/internal/prof_log.h"
|
||||
#include "jemalloc/internal/prof_recent.h"
|
||||
#include "jemalloc/internal/prof_stats.h"
|
||||
#include "jemalloc/internal/prof_sys.h"
|
||||
#include "jemalloc/internal/thread_event.h"
|
||||
|
||||
|
|
@ -131,6 +132,10 @@ prof_malloc_sample_object(tsd_t *tsd, const void *ptr, size_t size,
|
|||
assert(tctx == edata_prof_tctx_get(edata));
|
||||
prof_recent_alloc(tsd, edata, size, usize);
|
||||
}
|
||||
|
||||
if (opt_prof_stats) {
|
||||
prof_stats_inc(tsd, szind, size);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -160,6 +165,10 @@ prof_free_sampled_object(tsd_t *tsd, size_t usize, prof_info_t *prof_info) {
|
|||
prof_try_log(tsd, usize, prof_info);
|
||||
|
||||
prof_tctx_try_destroy(tsd, tctx);
|
||||
|
||||
if (opt_prof_stats) {
|
||||
prof_stats_dec(tsd, szind, prof_info->alloc_size);
|
||||
}
|
||||
}
|
||||
|
||||
prof_tctx_t *
|
||||
|
|
@ -587,7 +596,13 @@ prof_boot2(tsd_t *tsd, base_t *base) {
|
|||
|
||||
next_thr_uid = 0;
|
||||
if (malloc_mutex_init(&next_thr_uid_mtx, "prof_next_thr_uid",
|
||||
WITNESS_RANK_PROF_NEXT_THR_UID, malloc_mutex_rank_exclusive)) {
|
||||
WITNESS_RANK_PROF_NEXT_THR_UID,
|
||||
malloc_mutex_rank_exclusive)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (malloc_mutex_init(&prof_stats_mtx, "prof_stats",
|
||||
WITNESS_RANK_PROF_STATS, malloc_mutex_rank_exclusive)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -595,8 +610,9 @@ prof_boot2(tsd_t *tsd, base_t *base) {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (malloc_mutex_init(&prof_dump_filename_mtx, "prof_dump_filename",
|
||||
WITNESS_RANK_PROF_DUMP_FILENAME, malloc_mutex_rank_exclusive)) {
|
||||
if (malloc_mutex_init(&prof_dump_filename_mtx,
|
||||
"prof_dump_filename", WITNESS_RANK_PROF_DUMP_FILENAME,
|
||||
malloc_mutex_rank_exclusive)) {
|
||||
return true;
|
||||
}
|
||||
if (malloc_mutex_init(&prof_dump_mtx, "prof_dump",
|
||||
|
|
@ -681,9 +697,10 @@ prof_prefork1(tsdn_t *tsdn) {
|
|||
malloc_mutex_prefork(tsdn, &prof_active_mtx);
|
||||
malloc_mutex_prefork(tsdn, &prof_dump_filename_mtx);
|
||||
malloc_mutex_prefork(tsdn, &prof_gdump_mtx);
|
||||
malloc_mutex_prefork(tsdn, &prof_recent_alloc_mtx);
|
||||
malloc_mutex_prefork(tsdn, &prof_stats_mtx);
|
||||
malloc_mutex_prefork(tsdn, &next_thr_uid_mtx);
|
||||
malloc_mutex_prefork(tsdn, &prof_thread_active_init_mtx);
|
||||
malloc_mutex_prefork(tsdn, &prof_recent_alloc_mtx);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -692,10 +709,11 @@ prof_postfork_parent(tsdn_t *tsdn) {
|
|||
if (config_prof && opt_prof) {
|
||||
unsigned i;
|
||||
|
||||
malloc_mutex_postfork_parent(tsdn, &prof_recent_alloc_mtx);
|
||||
malloc_mutex_postfork_parent(tsdn,
|
||||
&prof_thread_active_init_mtx);
|
||||
malloc_mutex_postfork_parent(tsdn, &next_thr_uid_mtx);
|
||||
malloc_mutex_postfork_parent(tsdn, &prof_stats_mtx);
|
||||
malloc_mutex_postfork_parent(tsdn, &prof_recent_alloc_mtx);
|
||||
malloc_mutex_postfork_parent(tsdn, &prof_gdump_mtx);
|
||||
malloc_mutex_postfork_parent(tsdn, &prof_dump_filename_mtx);
|
||||
malloc_mutex_postfork_parent(tsdn, &prof_active_mtx);
|
||||
|
|
@ -719,9 +737,10 @@ prof_postfork_child(tsdn_t *tsdn) {
|
|||
if (config_prof && opt_prof) {
|
||||
unsigned i;
|
||||
|
||||
malloc_mutex_postfork_child(tsdn, &prof_recent_alloc_mtx);
|
||||
malloc_mutex_postfork_child(tsdn, &prof_thread_active_init_mtx);
|
||||
malloc_mutex_postfork_child(tsdn, &next_thr_uid_mtx);
|
||||
malloc_mutex_postfork_child(tsdn, &prof_stats_mtx);
|
||||
malloc_mutex_postfork_child(tsdn, &prof_recent_alloc_mtx);
|
||||
malloc_mutex_postfork_child(tsdn, &prof_gdump_mtx);
|
||||
malloc_mutex_postfork_child(tsdn, &prof_dump_filename_mtx);
|
||||
malloc_mutex_postfork_child(tsdn, &prof_active_mtx);
|
||||
|
|
|
|||
57
src/prof_stats.c
Normal file
57
src/prof_stats.c
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
#include "jemalloc/internal/jemalloc_preamble.h"
|
||||
#include "jemalloc/internal/jemalloc_internal_includes.h"
|
||||
|
||||
#include "jemalloc/internal/prof_stats.h"
|
||||
|
||||
bool opt_prof_stats = false;
|
||||
malloc_mutex_t prof_stats_mtx;
|
||||
static prof_stats_t prof_stats_live[PROF_SC_NSIZES];
|
||||
static prof_stats_t prof_stats_accum[PROF_SC_NSIZES];
|
||||
|
||||
static void
|
||||
prof_stats_enter(tsd_t *tsd, szind_t ind) {
|
||||
assert(opt_prof && opt_prof_stats);
|
||||
assert(ind < SC_NSIZES);
|
||||
malloc_mutex_lock(tsd_tsdn(tsd), &prof_stats_mtx);
|
||||
}
|
||||
|
||||
static void
|
||||
prof_stats_leave(tsd_t *tsd) {
|
||||
malloc_mutex_unlock(tsd_tsdn(tsd), &prof_stats_mtx);
|
||||
}
|
||||
|
||||
void
|
||||
prof_stats_inc(tsd_t *tsd, szind_t ind, size_t size) {
|
||||
cassert(config_prof);
|
||||
prof_stats_enter(tsd, ind);
|
||||
prof_stats_live[ind].req_sum += size;
|
||||
prof_stats_live[ind].count++;
|
||||
prof_stats_accum[ind].req_sum += size;
|
||||
prof_stats_accum[ind].count++;
|
||||
prof_stats_leave(tsd);
|
||||
}
|
||||
|
||||
void
|
||||
prof_stats_dec(tsd_t *tsd, szind_t ind, size_t size) {
|
||||
cassert(config_prof);
|
||||
prof_stats_enter(tsd, ind);
|
||||
prof_stats_live[ind].req_sum -= size;
|
||||
prof_stats_live[ind].count--;
|
||||
prof_stats_leave(tsd);
|
||||
}
|
||||
|
||||
void
|
||||
prof_stats_get_live(tsd_t *tsd, szind_t ind, prof_stats_t *stats) {
|
||||
cassert(config_prof);
|
||||
prof_stats_enter(tsd, ind);
|
||||
memcpy(stats, &prof_stats_live[ind], sizeof(prof_stats_t));
|
||||
prof_stats_leave(tsd);
|
||||
}
|
||||
|
||||
void
|
||||
prof_stats_get_accum(tsd_t *tsd, szind_t ind, prof_stats_t *stats) {
|
||||
cassert(config_prof);
|
||||
prof_stats_enter(tsd, ind);
|
||||
memcpy(stats, &prof_stats_accum[ind], sizeof(prof_stats_t));
|
||||
prof_stats_leave(tsd);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue