mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-04-17 08:01:49 +03:00
Add lock to protect prof last-N dumping
This commit is contained in:
parent
a835d9cf85
commit
3e19ebd2ea
4 changed files with 33 additions and 17 deletions
|
|
@ -1116,6 +1116,7 @@ prof_prefork0(tsdn_t *tsdn) {
|
|||
for (i = 0; i < PROF_NCTX_LOCKS; i++) {
|
||||
malloc_mutex_prefork(tsdn, &gctx_locks[i]);
|
||||
}
|
||||
malloc_mutex_prefork(tsdn, &prof_recent_dump_mtx);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1145,6 +1146,7 @@ prof_postfork_parent(tsdn_t *tsdn) {
|
|||
malloc_mutex_postfork_parent(tsdn, &prof_dump_filename_mtx);
|
||||
malloc_mutex_postfork_parent(tsdn, &prof_active_mtx);
|
||||
counter_postfork_parent(tsdn, &prof_idump_accumulated);
|
||||
malloc_mutex_postfork_parent(tsdn, &prof_recent_dump_mtx);
|
||||
for (i = 0; i < PROF_NCTX_LOCKS; i++) {
|
||||
malloc_mutex_postfork_parent(tsdn, &gctx_locks[i]);
|
||||
}
|
||||
|
|
@ -1170,6 +1172,7 @@ prof_postfork_child(tsdn_t *tsdn) {
|
|||
malloc_mutex_postfork_child(tsdn, &prof_dump_filename_mtx);
|
||||
malloc_mutex_postfork_child(tsdn, &prof_active_mtx);
|
||||
counter_postfork_child(tsdn, &prof_idump_accumulated);
|
||||
malloc_mutex_postfork_child(tsdn, &prof_recent_dump_mtx);
|
||||
for (i = 0; i < PROF_NCTX_LOCKS; i++) {
|
||||
malloc_mutex_postfork_child(tsdn, &gctx_locks[i]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ static
|
|||
#endif
|
||||
prof_recent_list_t prof_recent_alloc_list;
|
||||
|
||||
malloc_mutex_t prof_recent_dump_mtx; /* Protects dumping. */
|
||||
|
||||
static void
|
||||
prof_recent_alloc_max_init() {
|
||||
atomic_store_zd(&prof_recent_alloc_max, opt_prof_recent_alloc_max,
|
||||
|
|
@ -433,6 +435,7 @@ prof_recent_alloc_restore_locked(tsd_t *tsd, prof_recent_list_t *to_delete) {
|
|||
|
||||
static void
|
||||
prof_recent_alloc_async_cleanup(tsd_t *tsd, prof_recent_list_t *to_delete) {
|
||||
malloc_mutex_assert_not_owner(tsd_tsdn(tsd), &prof_recent_dump_mtx);
|
||||
malloc_mutex_assert_not_owner(tsd_tsdn(tsd), &prof_recent_alloc_mtx);
|
||||
while (!ql_empty(to_delete)) {
|
||||
prof_recent_t *node = ql_first(to_delete);
|
||||
|
|
@ -507,6 +510,7 @@ prof_recent_alloc_dump_node(emitter_t *emitter, prof_recent_t *node) {
|
|||
#define PROF_RECENT_PRINT_BUFSIZE 65536
|
||||
void
|
||||
prof_recent_alloc_dump(tsd_t *tsd, write_cb_t *write_cb, void *cbopaque) {
|
||||
malloc_mutex_lock(tsd_tsdn(tsd), &prof_recent_dump_mtx);
|
||||
buf_writer_t buf_writer;
|
||||
buf_writer_init(tsd_tsdn(tsd), &buf_writer, write_cb, cbopaque, NULL,
|
||||
PROF_RECENT_PRINT_BUFSIZE);
|
||||
|
|
@ -543,8 +547,10 @@ prof_recent_alloc_dump(tsd_t *tsd, write_cb_t *write_cb, void *cbopaque) {
|
|||
prof_recent_alloc_restore_locked(tsd, &temp_list);
|
||||
malloc_mutex_unlock(tsd_tsdn(tsd), &prof_recent_alloc_mtx);
|
||||
|
||||
prof_recent_alloc_async_cleanup(tsd, &temp_list);
|
||||
buf_writer_terminate(tsd_tsdn(tsd), &buf_writer);
|
||||
malloc_mutex_unlock(tsd_tsdn(tsd), &prof_recent_dump_mtx);
|
||||
|
||||
prof_recent_alloc_async_cleanup(tsd, &temp_list);
|
||||
}
|
||||
#undef PROF_RECENT_PRINT_BUFSIZE
|
||||
|
||||
|
|
@ -552,9 +558,13 @@ bool
|
|||
prof_recent_init() {
|
||||
prof_recent_alloc_max_init();
|
||||
|
||||
if (malloc_mutex_init(&prof_recent_alloc_mtx,
|
||||
"prof_recent_alloc", WITNESS_RANK_PROF_RECENT_ALLOC,
|
||||
malloc_mutex_rank_exclusive)) {
|
||||
if (malloc_mutex_init(&prof_recent_alloc_mtx, "prof_recent_alloc",
|
||||
WITNESS_RANK_PROF_RECENT_ALLOC, malloc_mutex_rank_exclusive)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (malloc_mutex_init(&prof_recent_dump_mtx, "prof_recent_dump",
|
||||
WITNESS_RANK_PROF_RECENT_DUMP, malloc_mutex_rank_exclusive)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue