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

JNI: Remove cleaned objects in memory cleaner #13378

Merged
merged 8 commits into from
May 30, 2023

Conversation

res-life
Copy link
Contributor

@res-life res-life commented May 18, 2023

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

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
    No need.
  • The documentation is up to date with these changes.
    No need.

@res-life res-life requested a review from a team as a code owner May 18, 2023 07:37
@github-actions github-actions bot added the Java Affects Java cuDF API. label May 18, 2023
@res-life
Copy link
Contributor Author

build

@res-life res-life added 3 - Ready for Review Ready for review by team 4 - Needs cuDF (Java) Reviewer non-breaking Non-breaking change improvement Improvement / enhancement to an existing function labels May 18, 2023
@@ -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
Copy link
Contributor

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

Copy link
Contributor Author

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());
Copy link
Member

@jlowe jlowe May 18, 2023

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.
Now proactively remove.

Copy link
Contributor Author

@res-life res-life May 26, 2023

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.

@res-life
Copy link
Contributor Author

build

@res-life
Copy link
Contributor Author

res-life commented May 26, 2023

The pipeline shows: Base branch is not under active development
Will retarget to branch-23.08

@res-life res-life changed the base branch from branch-23.06 to branch-23.08 May 26, 2023 09:40
@res-life
Copy link
Contributor Author

build

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

@revans2 revans2 left a 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.

@res-life
Copy link
Contributor Author

build

@res-life
Copy link
Contributor Author

build

@res-life
Copy link
Contributor Author

/merge

@rapids-bot rapids-bot bot merged commit 4384c3b into rapidsai:branch-23.08 May 30, 2023
@res-life res-life deleted the remove-cleaned-objects branch May 30, 2023 01:14
@vyasr vyasr added 4 - Needs Review Waiting for reviewer to review or respond and removed 4 - Needs cuDF (Java) Reviewer labels Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 - Ready for Review Ready for review by team 4 - Needs Review Waiting for reviewer to review or respond improvement Improvement / enhancement to an existing function Java Affects Java cuDF API. non-breaking Non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEA] Remove cleaned objects in memory cleaner
6 participants