-
Notifications
You must be signed in to change notification settings - Fork 889
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
JNI: Remove cleaned objects in memory cleaner #13378
JNI: Remove cleaned objects in memory cleaner #13378
Conversation
Signed-off-by: Chong Gao <[email protected]>
build |
@@ -199,6 +200,12 @@ static void setDefaultGpu(int defaultGpuId) { | |||
log.error("CAUGHT EXCEPTION WHILE TRYING TO CLEAN " + next, t); | |||
} | |||
all.remove(next); | |||
} else { | |||
long currentTime = System.currentTimeMillis(); | |||
if (currentTime - lastRemoveCleanedObjectsTime > 10 * 1000L) { // every 10 seconds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could future-proof it by adding a system property with the default the PR suggests so the value can be changed in situations 10s is not optimal one way or another
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now proactively remove.
} else { | ||
long currentTime = System.currentTimeMillis(); | ||
if (currentTime - lastRemoveCleanedObjectsTime > 10 * 1000L) { // every 10 seconds | ||
all.removeIf(e -> e.cleaner.isClean()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we polling to clean objects when we can proactively remove things from all
when they are properly closed? Saves from doing a full scan of potentially very many live objects in all
and should be more efficient.
There's a couple of ways to do this. One is to implement equals and hashcode for CleanerWeakReference
so we can remove our cleaner from all
(by building a temporary instance to do the remove). Those methods would simply delegate to the cleaner instance, ignoring everything else. Not ideal, but it should allow us to build a helper instance to lookup the cleaner to remove from all
.
More efficiently would be to rework the all
and Cleaner setups so instead of CleanerWeakReference
pointing to Cleaner
, we remove CleanerWeakReference
entirely and have Cleaner
have the isRmmBlocker
field and a normal WeakReference
to the object it is associated with. all
would simply be a hash set of the cleaner instances, and then it's trivial for a cleaner to remove itself from all
when it cleans.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Now proactively remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put the weak references into a Map, use cleaner id as the key of the Map. The id is unique and can represent a unique resource.
Signed-off-by: Chong Gao <[email protected]>
build |
The pipeline shows: Base branch is not under active development |
build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copyrights need to be updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me.
build |
build |
/merge |
Description
closes #13412
Remove weak references of cleaned resources when a resource is cleaned.
The cleaned objects are never leaked, it's safe to remove the weak references.
This is to reduce the memory usage.
Checklist
No need.
No need.