From 4605ea30638c6a2ccc6e0fd5264441148f55bc73 Mon Sep 17 00:00:00 2001 From: Diogo Netto <61364108+d-netto@users.noreply.github.com> Date: Sun, 29 Oct 2023 21:21:03 -0300 Subject: [PATCH] port pool stats to 1.10 (#102) * port pool stats to 1.10 * increment/decrement current_pg_count --------- Co-authored-by: K Pamnany --- src/gc-pages.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/gc-pages.c b/src/gc-pages.c index 7efffa853c8447..7a32a7f4bf9753 100644 --- a/src/gc-pages.c +++ b/src/gc-pages.c @@ -19,6 +19,31 @@ extern "C" { #define MIN_BLOCK_PG_ALLOC (1) // 16 KB static int block_pg_cnt = DEFAULT_BLOCK_PG_ALLOC; +static _Atomic(size_t) current_pg_count = 0; + +// Julia allocates large blocks (64M) with mmap. These are never +// released back but the underlying physical memory may be released +// with calls to madvise(MADV_DONTNEED). +// These large blocks are used to allocated jl_page_size sized +// pages, that are tracked by current_pg_count. +static uint64_t poolmem_bytes_allocated = 0; +static uint64_t poolmem_blocks_allocated_total = 0; + + +JL_DLLEXPORT uint64_t jl_poolmem_blocks_allocated_total(void) +{ + return poolmem_blocks_allocated_total; +} + +JL_DLLEXPORT uint64_t jl_poolmem_bytes_allocated(void) +{ + return poolmem_bytes_allocated; +} + +JL_DLLEXPORT uint64_t jl_current_pg_count(void) +{ + return (uint64_t)jl_atomic_load(¤t_pg_count); +} void jl_gc_init_page(void) { @@ -47,6 +72,8 @@ char *jl_gc_try_alloc_pages_(int pg_cnt) JL_NOTSAFEPOINT MAP_NORESERVE | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (mem == MAP_FAILED) return NULL; + poolmem_bytes_allocated += pages_sz; + poolmem_blocks_allocated_total++; #ifdef MADV_NOHUGEPAGE madvise(mem, pages_sz, MADV_NOHUGEPAGE); @@ -152,6 +179,7 @@ NOINLINE jl_gc_pagemeta_t *jl_gc_alloc_page(void) JL_NOTSAFEPOINT SetLastError(last_error); #endif errno = last_errno; + jl_atomic_fetch_add(¤t_pg_count, 1); return meta; } @@ -192,6 +220,7 @@ void jl_gc_free_page(jl_gc_pagemeta_t *pg) JL_NOTSAFEPOINT madvise(p, decommit_size, MADV_DONTNEED); #endif msan_unpoison(p, decommit_size); + jl_atomic_fetch_add(¤t_pg_count, -1); } #ifdef __cplusplus