Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functions to manipulate the GC heap counters #55390

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

vchuravy
Copy link
Member

@vchuravy vchuravy commented Aug 6, 2024

jl_malloc and jl_free can be used to inform the GC about memory
pressure caused by external libraries. This PR adds two functions
that only do the accounting and not the memory allocation/freeing.

The intended audience is users of libraries that do their own memory
management, but still have establishes sizes and deallocation points.
An example of this is the unified memory API in CUDA.

`jl_malloc` and `jl_free` can be used to inform the GC about memory
pressure caused by external libraries. This PR adds two functions
that only do the accounting and not the memory allocation/freeing.

The intended audience is users of libraries that do their own memory
management, but still have establishes sizes and deallocation points.
An example of this is the unified memory API in CUDA.
@vchuravy vchuravy added the GC Garbage collector label Aug 6, 2024
@vchuravy vchuravy requested review from d-netto and gbaraldi August 6, 2024 08:53
src/gc-interface.h Outdated Show resolved Hide resolved
src/gc-interface.h Outdated Show resolved Hide resolved
{
jl_gcframe_t **pgcstack = jl_get_pgcstack();
jl_task_t *ct = jl_current_task;
if (pgcstack != NULL && ct->world_age) {
Copy link
Member

@gbaraldi gbaraldi Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does world_age matter here? or is that just a proxy to see if it's a valid task? We do this in other places but now that I look at it it's odd.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this code looked weird to me as well, but I assume it's a valid task check, maybe an artifact before thread-adoption?

Copy link
Member

@d-netto d-netto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation seems mostly fine.

Still, adding these calls to inform the GC about manually managed memory makes me a bit nervous.

We face a similar problem at RAI where we need to make sure that a database buffer cache (the source of manually managed memory in our case) and the Julia heap cooperate. We have been moving in the direction of trying to make the GC heuristics code more aware of this external memory by, for instance, polling for RSS periodically.

I'm not familiar with memory management on GPUs, but is making the GC heuristics code more aware of GPU memory something feasible in that domain?

@vchuravy
Copy link
Member Author

vchuravy commented Aug 15, 2024

but is making the GC heuristics code more aware of GPU memory something feasible in that domain?

We need to use a different allocator cudaMalloc/cudaFree, but for unified memory the address-space between host and device is shared. The alternative would be to extend gcext to have a jl_new_foreign_memory where we provide the GC a custom alloc and free function.

But this doesn't solve how to inform the GC about memory pressure stemming from allocations in a C++ library. RSS is a poor proxy since that starts to get all kinds of wonky in the presence of swap and multi-process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GC Garbage collector
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants