Skip to content

Commit

Permalink
Export num_stack_mappings to track the number of in-flight stack mapp…
Browse files Browse the repository at this point in the history
…ings and tasks in application (#51301)

Julia already tracks the number of mapped stacks for Julia tasks in a
local atomic.
Exporting this atomic will allow applications to estimate the memory
consumption by the stacks and also the number of in-flight tasks.

---------

Co-authored-by: Nathan Daly <nathan.daly@relational.ai>
  • Loading branch information
adnan-alhomssi and NHDaly authored Sep 20, 2023
1 parent 8d05a22 commit 8f95c6b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/gc-stacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ static void free_stack(void *stkbuf, size_t bufsz)
}
#endif

JL_DLLEXPORT uint32_t jl_get_num_stack_mappings(void)
{
return jl_atomic_load_relaxed(&num_stack_mappings);
}

const unsigned pool_sizes[] = {
128 * 1024,
Expand Down
1 change: 1 addition & 0 deletions src/gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ void gc_count_pool(void);
size_t jl_array_nbytes(jl_array_t *a) JL_NOTSAFEPOINT;

JL_DLLEXPORT void jl_enable_gc_logging(int enable);
JL_DLLEXPORT uint32_t jl_get_num_stack_mappings(void);
void _report_gc_finished(uint64_t pause, uint64_t freed, int full, int recollect, int64_t live_bytes) JL_NOTSAFEPOINT;

#ifdef __cplusplus
Expand Down
6 changes: 6 additions & 0 deletions test/threads.jl
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,9 @@ end
@testset "rand_ptls underflow" begin
@test Base.Partr.cong(UInt32(0)) == 0
end

@testset "num_stack_mappings metric" begin
@test @ccall(jl_get_num_stack_mappings()::Cint) >= 1
# There must be at least two: one for the root test task and one for the async task:
@test fetch(@async(@ccall(jl_get_num_stack_mappings()::Cint))) >= 2
end

0 comments on commit 8f95c6b

Please sign in to comment.