@@ -19,6 +19,31 @@ extern "C" {
1919#define MIN_BLOCK_PG_ALLOC (1) // 16 KB
2020
2121static int block_pg_cnt = DEFAULT_BLOCK_PG_ALLOC ;
22+ static _Atomic (size_t ) current_pg_count = 0 ;
23+
24+ // Julia allocates large blocks (64M) with mmap. These are never
25+ // released back but the underlying physical memory may be released
26+ // with calls to madvise(MADV_DONTNEED).
27+ // These large blocks are used to allocated jl_page_size sized
28+ // pages, that are tracked by current_pg_count.
29+ static uint64_t poolmem_bytes_allocated = 0 ;
30+ static uint64_t poolmem_blocks_allocated_total = 0 ;
31+
32+
33+ JL_DLLEXPORT uint64_t jl_poolmem_blocks_allocated_total (void )
34+ {
35+ return poolmem_blocks_allocated_total ;
36+ }
37+
38+ JL_DLLEXPORT uint64_t jl_poolmem_bytes_allocated (void )
39+ {
40+ return poolmem_bytes_allocated ;
41+ }
42+
43+ JL_DLLEXPORT uint64_t jl_current_pg_count (void )
44+ {
45+ return (uint64_t )jl_atomic_load (& current_pg_count );
46+ }
2247
2348void jl_gc_init_page (void )
2449{
@@ -47,6 +72,8 @@ char *jl_gc_try_alloc_pages_(int pg_cnt) JL_NOTSAFEPOINT
4772 MAP_NORESERVE | MAP_PRIVATE | MAP_ANONYMOUS , -1 , 0 );
4873 if (mem == MAP_FAILED )
4974 return NULL ;
75+ poolmem_bytes_allocated += pages_sz ;
76+ poolmem_blocks_allocated_total ++ ;
5077
5178#ifdef MADV_NOHUGEPAGE
5279 madvise (mem , pages_sz , MADV_NOHUGEPAGE );
@@ -152,6 +179,7 @@ NOINLINE jl_gc_pagemeta_t *jl_gc_alloc_page(void) JL_NOTSAFEPOINT
152179 SetLastError (last_error );
153180#endif
154181 errno = last_errno ;
182+ jl_atomic_fetch_add (& current_pg_count , 1 );
155183 return meta ;
156184}
157185
@@ -192,6 +220,7 @@ void jl_gc_free_page(jl_gc_pagemeta_t *pg) JL_NOTSAFEPOINT
192220 madvise (p , decommit_size , MADV_DONTNEED );
193221#endif
194222 msan_unpoison (p , decommit_size );
223+ jl_atomic_fetch_add (& current_pg_count , -1 );
195224}
196225
197226#ifdef __cplusplus
0 commit comments