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

Ensure UpstreamResourceAdaptor is not cleared by the Python GC #1170

Merged

Conversation

shwina
Copy link
Contributor

@shwina shwina commented Nov 30, 2022

Closes #1169.

Essentially, we are running into the situation described in https://cython.readthedocs.io/en/latest/src/userguide/extension_types.html#disabling-cycle-breaking-tp-clear with UpstreamResourceAdaptor.

The solution is to prevent clearing of UpstreamResourceAdaptor objects by decorating them with no_gc_clear.

Cython calls out the following:

If you use no_gc_clear, it is important that any given reference cycle contains at least one object without no_gc_clear. Otherwise, the cycle cannot be broken, which is a memory leak.

The other object in RMM that we mark @no_gc_clear is DeviceBuffer, and a DeviceBuffer can keep a reference to an UpstreamResourceAdaptor. But, an UpstreamResourceAdaptor cannot keep a reference to a DeviceBuffer, so instances of the two cannot form a reference cycle AFAICT.

@shwina shwina requested a review from a team as a code owner November 30, 2022 19:05
@github-actions github-actions bot added the Python Related to RMM Python API label Nov 30, 2022
@shwina shwina added non-breaking Non-breaking change bug Something isn't working labels Nov 30, 2022
python/rmm/tests/test_rmm.py Outdated Show resolved Hide resolved
Copy link
Contributor

@vyasr vyasr left a comment

Choose a reason for hiding this comment

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

The fix looks great to me. A couple of requests regarding comments (including one preexisting comment), but nothing blocking.

python/rmm/tests/test_rmm.py Show resolved Hide resolved
shwina and others added 4 commits December 2, 2022 16:02
Co-authored-by: Vyas Ramasubramani <vyas.ramasubramani@gmail.com>
…wina/rmm into upstream-resource-adaptor-no-gc-clear
@shwina
Copy link
Contributor Author

shwina commented Dec 13, 2022

@gpucibot merge

@rapids-bot rapids-bot bot merged commit c83a16f into rapidsai:branch-23.02 Dec 13, 2022
shwina added a commit to shwina/rmm that referenced this pull request Dec 19, 2022
…idsai#1170)

Closes rapidsai#1169.

Essentially, we are running into the situation described in https://cython.readthedocs.io/en/latest/src/userguide/extension_types.html#disabling-cycle-breaking-tp-clear with `UpstreamResourceAdaptor`.

The solution is to prevent clearing of `UpstreamResourceAdaptor` objects by decorating them with `no_gc_clear`.

Cython calls out the following:

> If you use no_gc_clear, it is important that any given reference cycle contains at least one object without no_gc_clear. Otherwise, the cycle cannot be broken, which is a memory leak.

The other object in RMM that we mark `@no_gc_clear` is `DeviceBuffer`, and a `DeviceBuffer` can keep a reference to an `UpstreamResourceAdaptor`. But, an `UpstreamResourceAdaptor` cannot keep a reference to a `DeviceBuffer`, so instances of the two cannot form a reference cycle AFAICT.

Authors:
  - Ashwin Srinath (https://github.com/shwina)

Approvers:
  - Vyas Ramasubramani (https://github.com/vyasr)
  - Mark Harris (https://github.com/harrism)

URL: rapidsai#1170
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working non-breaking Non-breaking change Python Related to RMM Python API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Segfault running pytest when a test fails
3 participants