Skip to content

Commit

Permalink
[core] Fix a memory leak due to lineage counting (#31488)
Browse files Browse the repository at this point in the history
Assume two objects A and B and B depends on A. If A got delete first, it's won't be released because we need to preserve it for B.

The bug here is that even B is released, A won't be released and thus memory leak.

This PR fixed this issue by force delete the object when the ref goes to 0.
  • Loading branch information
fishbone authored Jan 11, 2023
1 parent 30f8187 commit 037806a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
21 changes: 21 additions & 0 deletions python/ray/tests/test_reference_counting_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,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
Original file line number Diff line number Diff line change
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);
EraseReference(arg_it);
}
}
Expand Down

0 comments on commit 037806a

Please sign in to comment.