Repository navigation
Datadeps: free copies of identity-less arguments again, and give each its own slot - #833
Merged
jpsamaroo merged 5 commits intoNov 30, 2026
Merged
Conversation
Since JuliaParallel#792, aliased_object! returned early for NoAliasing, so the copy made for another memory space never entered the object cache and region teardown (which frees the cache's non-original entries) no longer freed it. And an identity-less aliasing that is not NoAliasing itself, such as the empty CombinedAliasing of a struct whose fields are all NoAliasing, still shared one cache key, so a distinct argument could get another one's slot. Add aliasing_has_identity (false for NoAliasing, wrappers of it, and empty CombinedAliasing; dispatchable for user aliasing types). Such values bypass the keyed lookup, and a copy made for another space is recorded under a fresh CopyKey, so teardown frees it while originals stay untouched. Fixes JuliaParallel#822.
…d its slot Review finding 1 on PR JuliaParallel#833 (blocker): Copies of NoAliasing arguments are freed at region end without waiting for the tasks reading them (use-after-free) Requested: Make the region-end free of each CopyKey copy wait for every task that used that slot, by porting PR JuliaParallel#834's per-slot user list (UnkeyedSlot / add_unkeyed_user! / free_unkeyed_copies!, branch jps/review/pr792 commit af59cd7) or an equivalent wait attached to the CopyKey free. Keep it rank-uniform under MPI. The region-end free loops take a buffer's syncdeps from dependency tracking, which orders nothing on bare NoAliasing (get_write_deps! returns at once). So the unsafe_free! of a CopyKey copy waited for nothing and ran while the copy's readers were still running. This ports JuliaParallel#834's per-slot user list onto this PR's CopyKey design, rather than adding a second free loop: - generate_slot! attributes each CopyKey copy made while building a slot to that slot (a leaf argument's slot, or a wrapper slot's children), by scanning the cache keys appended during the call. - add_reader!, which every task touching a slot passes through (writers and copy tasks included), records the task as a user of such a slot. - Both planners' existing free loops add the slot's users to a CopyKey copy's syncdeps (push_copy_users_syncdeps!). The hierarchical planner's shared-owner syncdep, the free-once check and the sorted order still apply. A CopyKey copy with no recorded slot is an error, not a free with no syncdeps. CopyKey ids, slots and users are all recorded in planning order, which is the same on every rank, so the free syncdeps are rank-uniform. The bookkeeping (UnkeyedSlots) is created lazily, on a region's first CopyKey copy. DataDepsState holds its (always local) cache store directly, so generate_slot! checks it without a MemPool lookup. The common path pays a length read and a short isa scan per slot, and a `nothing` check per reader. One region over plain Vectors (8 InOut and 7 two-In tasks; -t1, 15 warmup regions, minimum of 12, 3 fresh processes, Julia 1.12.6): 4600-4602 allocations / 175,440-175,632 bytes with this commit, 4695-4697 / 178,224-178,416 on the PR head. No increase. Verified: - The next commit's test fails in all 6 slow-read rounds (both planners) without this commit, and passes 12/12 with it. - --test datadeps (1555 pass, 2 broken) and --test allocations (25/25) pass, Julia 1.13.1, 3 workers. - The 2-rank MPI CPU suite (test/mpi/cpu.jl, including test/mpi/noaliasing_args.jl) passes: 1143 and 1146 per rank. - A 2-rank MPI probe with uniformity checks on (a NoAliasing isbits Vector built on rank 0, read by two slow tasks on rank 1, both planners, 3 rounds each) sees every copy allocated throughout its reads and freed after the region. Written by an AI agent on jpsamaroo's review feedback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TRNkMLrH1mZo3YmkaHP8Jr
Review finding 2 on PR JuliaParallel#833 (should-fix): The new free test cannot detect an early free: it counts free tasks for payloads whose free does nothing Requested: As reported: make the free test detect an early free, using a payload whose free is observable (Libc-backed isbits array) read by a deliberately slow task on another worker; it must fail without the F1 fix. The existing free test counts unsafe_free! tasks for plain-struct payloads, whose free is a no-op, and its tasks read without waiting. So it passes while the free runs under the reader. The new testset's payload has an observable free: a Vector of an isbits struct declared NoAliasing. It is built on the driver and read (In) by two tasks on another worker. Each task checks Dagger.is_libc_allocated before and after a 0.5 s sleep. Datadeps' copy on the worker is Libc-backed, so an early unsafe_free! makes is_libc_allocated false. After the region, the test checks that every copy was freed. It runs under both planners, 3 rounds each. Verified (Julia 1.12.6, 3 workers, only this testset): with the previous commit's src changes reverted locally (not committed), the reader assertion fails in all 6 rounds (6 passed, 6 failed). With them, 12/12 pass. It also passes in the full --test datadeps run. Written by an AI agent on jpsamaroo's review feedback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TRNkMLrH1mZo3YmkaHP8Jr
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #833 +/- ##
==========================================
+ Coverage 63.91% 64.28% +0.37%
==========================================
Files 126 126
Lines 20119 20153 +34
==========================================
+ Hits 12859 12956 +97
+ Misses 7260 7197 -63 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Use master's ownership check before recording an identity-less slot for region-end freeing. Keep both sets of Datadeps tests and exercise a cross-space identity move alongside a genuine copy. Written by an AI agent on jpsamaroo's review feedback.
Keep the regression tests for identity-less copy ownership and lifetime alongside the wrapper and sparse-container tests added by JuliaParallel#840. Written by an AI agent on jpsamaroo's review feedback.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Category 1 (bug fix), regression repair: This fixes two defects in how Datadeps' aliased-object cache treats arguments whose aliasing carries no identity. It changes no public API.
Fixes #822. This is a regression of our own PR #792 (merged in #804), and I am sorry for it.
Problem
#792 made
aliased_object!return early forNoAliasing, so that two distinctNoAliasingarguments no longer share one cache slot. Two consequences, both reported in #822:unsafe_free!does something (isbits-element CPU arrays moved throughlibc_backed, and GPU arrays), as noted in the discussion on the issue; those copies now wait for GC.NoAliasingitself still shared one cache key. The defaultaliasingofstruct Outer; x::NoAliasVal; endis an emptyCombinedAliasing, and all of those compare and hash equal, so a distinctOuterargument could receive another one's slot (wrong data, no error).Change
aliasing_has_identity(::AbstractAliasing):trueby default,falseforNoAliasing, forwarded byAliasingWrapper, and forCombinedAliasingtrue only if some sub-aliasing has identity (so an empty one has none). User-defined aliasing types can add a method.aliased_object!sends identity-less values to a separate path. It does not look anything up by aliasing. It calls the mover, and if the result is a new copy in another space (not the argument itself, and not data already in the destination space) it records it under a freshCopyKey(a counter on the cache store). Copies are therefore freed at region end like every other copy, originals are never freed, and distinct values never share a slot. The same object used twice in a region still shares its copy, because the slot is already memoized per argument and space before the cache is reached.resolve_pending!does not addderivedentries forCopyKeycopies, since nothing looks them up by aliasing.Testing
What I ran, locally:
test/datadeps.jl("Identity-less aliasing: own slot per value, copies freed"), run as a standalone script with two Distributed workers: three distinctNoAliasingvalues and three distinctOuterwrappers are moved to another worker in onespawn_datadepsregion; each task sees its own value, and the number ofunsafe_free!tasks in the logs equals the number of copies (it was 3 of 6 without the fix's registration). Plus unit checks for the predicate. It passes.CombinedAliasingcount as having identity again makes theOuterdata checks fail ([3,3,3] instead of [1,2,3]).test/mpi/noaliasing_args.jl): passes on MPICH, 2 ranks x 2 threads (7 assertions).--test mutation --test memory-spacesat-p 1 -t 2(71 and 22 pass), and the full--test datadepsat-p 2 -t 2(2142 pass, 2 known broken).AI disclosure: I prepared this change with the help of Claude (Anthropic) and reviewed it myself.
🤖 Generated with Claude Code