From 46b692e3d51f88cf0ed3235c7162dd4ab0a837a1 Mon Sep 17 00:00:00 2001 From: Pete Vilter <7341+vilterp@users.noreply.github.com> Date: Mon, 7 Feb 2022 12:16:48 -0500 Subject: [PATCH] allocation profiler: get stacks for pool allocs via wrapper function (#43868) --- src/gc.c | 8 +++++--- src/julia_internal.h | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/gc.c b/src/gc.c index 8208df6007ca3..67867952dd1c9 100644 --- a/src/gc.c +++ b/src/gc.c @@ -1195,7 +1195,7 @@ static NOINLINE jl_taggedvalue_t *add_page(jl_gc_pool_t *p) JL_NOTSAFEPOINT } // Size includes the tag and the tag is not cleared!! -JL_DLLEXPORT jl_value_t *jl_gc_pool_alloc_inner(jl_ptls_t ptls, int pool_offset, +static inline jl_value_t *jl_gc_pool_alloc_inner(jl_ptls_t ptls, int pool_offset, int osize) { // Use the pool offset instead of the pool address as the argument @@ -1264,7 +1264,7 @@ JL_DLLEXPORT jl_value_t *jl_gc_pool_alloc(jl_ptls_t ptls, int pool_offset, // This wrapper exists only to prevent `jl_gc_pool_alloc_inner` from being inlined into // its callers. We provide an external-facing interface for callers, and inline `jl_gc_pool_alloc_inner` // into this. (See https://github.com/JuliaLang/julia/pull/43868 for more details.) -jl_value_t *jl_gc_pool_alloc_wrapper(jl_ptls_t ptls, int pool_offset, int osize) { +jl_value_t *jl_gc_pool_alloc_noinline(jl_ptls_t ptls, int pool_offset, int osize) { return jl_gc_pool_alloc_inner(ptls, pool_offset, osize); } @@ -3522,6 +3522,8 @@ JL_DLLEXPORT void *jl_gc_managed_malloc(size_t sz) SetLastError(last_error); #endif errno = last_errno; + // jl_gc_managed_malloc is currently always used for allocating array buffers. + maybe_record_alloc_to_profile(b, sz, (jl_datatype_t*)jl_buff_tag); return b; } @@ -3563,7 +3565,7 @@ static void *gc_managed_realloc_(jl_ptls_t ptls, void *d, size_t sz, size_t olds SetLastError(last_error); #endif errno = last_errno; - + maybe_record_alloc_to_profile(b, sz, jl_gc_unknown_type_tag); return b; } diff --git a/src/julia_internal.h b/src/julia_internal.h index efb615d29c2cf..7041df82507e5 100644 --- a/src/julia_internal.h +++ b/src/julia_internal.h @@ -226,7 +226,7 @@ extern jl_array_t *jl_all_methods JL_GLOBALLY_ROOTED; JL_DLLEXPORT extern int jl_lineno; JL_DLLEXPORT extern const char *jl_filename; -jl_value_t *jl_gc_pool_alloc_wrapper(jl_ptls_t ptls, int pool_offset, +jl_value_t *jl_gc_pool_alloc_noinline(jl_ptls_t ptls, int pool_offset, int osize); JL_DLLEXPORT jl_value_t *jl_gc_big_alloc(jl_ptls_t ptls, size_t allocsz); int jl_gc_classify_pools(size_t sz, int *osize); @@ -337,7 +337,9 @@ STATIC_INLINE jl_value_t *jl_gc_alloc_(jl_ptls_t ptls, size_t sz, void *ty) int pool_id = jl_gc_szclass(allocsz); jl_gc_pool_t *p = &ptls->heap.norm_pools[pool_id]; int osize = jl_gc_sizeclasses[pool_id]; - v = jl_gc_pool_alloc_wrapper(ptls, (char*)p - (char*)ptls, osize); + // We call `jl_gc_pool_alloc_noinline` instead of `jl_gc_pool_alloc` to avoid double-counting in + // the Allocations Profiler. (See https://github.com/JuliaLang/julia/pull/43868 for more details.) + v = jl_gc_pool_alloc_noinline(ptls, (char*)p - (char*)ptls, osize); } else { if (allocsz < sz) // overflow in adding offs, size was "negative"