Skip to content

Commit

Permalink
port pool stats to 1.10 (#102)
Browse files Browse the repository at this point in the history
* port pool stats to 1.10

* increment/decrement current_pg_count

---------

Co-authored-by: K Pamnany <[email protected]>
  • Loading branch information
2 people authored and RAI CI (GitHub Action Automation) committed Oct 31, 2023
1 parent 8843265 commit e6e5f65
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/gc-pages.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(&current_pg_count);
}

void jl_gc_init_page(void)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(&current_pg_count, 1);
return meta;
}

Expand Down Expand Up @@ -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(&current_pg_count, -1);
}

#ifdef __cplusplus
Expand Down

0 comments on commit e6e5f65

Please sign in to comment.