Skip to content

Commit 8f95c6b

Browse files
Adnan AlhomssiNHDaly
andauthored
Export num_stack_mappings to track the number of in-flight stack mappings 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 <[email protected]>
1 parent 8d05a22 commit 8f95c6b

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

src/gc-stacks.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ static void free_stack(void *stkbuf, size_t bufsz)
7373
}
7474
#endif
7575

76+
JL_DLLEXPORT uint32_t jl_get_num_stack_mappings(void)
77+
{
78+
return jl_atomic_load_relaxed(&num_stack_mappings);
79+
}
7680

7781
const unsigned pool_sizes[] = {
7882
128 * 1024,

src/gc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ void gc_count_pool(void);
654654
size_t jl_array_nbytes(jl_array_t *a) JL_NOTSAFEPOINT;
655655

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

659660
#ifdef __cplusplus

test/threads.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,9 @@ end
331331
@testset "rand_ptls underflow" begin
332332
@test Base.Partr.cong(UInt32(0)) == 0
333333
end
334+
335+
@testset "num_stack_mappings metric" begin
336+
@test @ccall(jl_get_num_stack_mappings()::Cint) >= 1
337+
# There must be at least two: one for the root test task and one for the async task:
338+
@test fetch(@async(@ccall(jl_get_num_stack_mappings()::Cint))) >= 2
339+
end

0 commit comments

Comments
 (0)