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

Support for fine-grained selection of the GC collection type. #33448

Merged
merged 2 commits into from
Oct 4, 2019

Conversation

maleadt
Copy link
Member

@maleadt maleadt commented Oct 2, 2019

This makes it possible to force an incremental collection, ignoring full collection heuristics.

Motivation: from the GPU allocator, we routinely call into the Julia GC to free GPU buffer objects. If GPU memory pressure is high, we do this quite regularly (e.g. twice a second). An incremental collection is often enough to free up sufficient GPU memory, and this initially takes about 40~50ms (for a Flux model I'm profiling), but after a while the collection time drops off a cliff to about 500ms for all calls to gc(false). This is due to the GC heuristics forcing a full collection since the incremental ones "fail" to collect enough memory (GPU buffer objects are tiny, and do not reflect actual GPU memory freed).

This PR adds the (non-breaking) ability to force an incremental collection, ignoring all heuristics.

TODO:

  • tests
  • Julia API

@maleadt maleadt added GC Garbage collector gpu Affects running Julia on a GPU labels Oct 2, 2019
@maleadt maleadt requested a review from yuyichao October 2, 2019 07:56
Copy link
Contributor

@yuyichao yuyichao left a comment

Choose a reason for hiding this comment

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

LGTM.

src/julia.h Show resolved Hide resolved
This makes it possible to force an incremental collection, ignoring heuristics.
@maleadt maleadt changed the title RFC: Support for fine-grained selection of the GC collection type. Support for fine-grained selection of the GC collection type. Oct 3, 2019
@@ -49,15 +49,29 @@ Module with garbage collection utilities.
"""
module GC

# @enum-like structure
struct CollectionType
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Out of curiosity, what is the reason for not using an actual @enum?

Copy link
Member Author

Choose a reason for hiding this comment

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

gcutils.jl is included very early in the system image, before Enums.jl and having @enum.

@Keno Keno merged commit 9d98131 into master Oct 4, 2019
@Keno Keno deleted the tb/gc_collection branch October 4, 2019 01:48
@StefanKarpinski
Copy link
Sponsor Member

Are we intending this to be an official API for choosing the collection type? If so I think we should probably discuss the API a bit more... having a type that wraps an integer like this is not how I would prefer to have people interact with this. This would be fairly simple:

gc()      # auto
gc(true)  # full
gc(false) # incremental

@StefanKarpinski StefanKarpinski added the triage This should be discussed on a triage call label Oct 4, 2019
@StefanKarpinski
Copy link
Sponsor Member

Marking with triage to discuss the API.

@maleadt
Copy link
Member Author

maleadt commented Oct 14, 2019

@StefanKarpinski Was anything discussed during triage? I don't have strong feelings about the interface, so I'd be happy to put up a PR with your proposed API.

@KristofferC
Copy link
Sponsor Member

There hasn't been a triage since that comment.

@Keno Keno removed the triage This should be discussed on a triage call label Feb 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GC Garbage collector gpu Affects running Julia on a GPU
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants