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

[core] Fix a memory leak due to lineage counting #31488

Merged
merged 6 commits into from Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions python/ray/tests/test_reference_counting_2.py
Expand Up @@ -778,6 +778,27 @@ def remote_generator():
_fill_object_store_and_get(r_oid, succeed=False)


def test_lineage_leak(shutdown_only):
ray.init()

@ray.remote
def process(data):
return b"\0" * 100_000_000

data = ray.put(b"\0" * 100_000_000)
ref = process.remote(data)
ray.get(ref)
del data
del ref

def check_usage():
from ray._private.internal_api import memory_summary

return "Plasma memory usage 0 MiB" in memory_summary(stats_only=True)

wait_for_condition(check_usage)


if __name__ == "__main__":
import sys

Expand Down
3 changes: 1 addition & 2 deletions src/ray/core_worker/reference_count.cc
Expand Up @@ -478,10 +478,9 @@ int64_t ReferenceCounter::ReleaseLineageReferences(ReferenceTable::iterator ref)
RAY_LOG(DEBUG) << "Releasing lineage internal for argument " << argument_id;
arg_it->second.lineage_ref_count--;
if (arg_it->second.ShouldDelete(lineage_pinning_enabled_)) {
// We only decremented the lineage ref count, so the argument value
// should already be released.
RAY_CHECK(arg_it->second.on_ref_removed == nullptr);
lineage_bytes_evicted += ReleaseLineageReferences(arg_it);
ReleasePlasmaObject(arg_it);
Copy link
Contributor

Choose a reason for hiding this comment

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

The fix looks good to me! I think we just need to move this to go before the above line, though, because the previous line deletes arg_it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually I think you could also just call DeleteReferenceInternal instead of EraseReference and ReleasePlasmaObject.

EraseReference(arg_it);
}
}
Expand Down