GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||
GeezerVison is showing github.com — engine/snapshots: one ancestry lease for dagql owners by vito · Pull Request #15232 · dagger/dagger Conversation
|
| before | after | |
|---|---|---|
| 200 results on a 200-deep chain | 20,100 lease resources, +4.5 MB (22.6 KB/result) | 399 resources, +393 KB (2.0 KB/result) |
| 200 results on one 50-deep snapshot | 10,000 resources, +2.2 MB | 249 resources, +264 KB |
Attaching 2,000 owner leases in parallel, as the boot re-attach does (chain depth 1 / 50 / 200): 26 / 116 / 323 ms on main, 32 / 33 / 36 ms here.
Dev engine, a 52-deep withExec chain with three results on its tip: 107 owner leases hold 110 resources, and the ancestry lease holds 54. Naming each chain in each owner lease would take an estimated ~1,400 resources.
hack/memory-soak (on memory-fixes-combined, 10 sessions, HeapAlloc after GC): no measurable difference. The last session ended at 203.4 MB before and 202.8 MB after. Snapshot and metadata heap is about 5 MB in both. The soak's chains are shallow, and its results are pruned between sessions. This change targets deep chains of retained results.
engine/snapshots (also with -race), with new tests:
./core, ./dagql, ./core/schema and ./engine/engineutil/....TestDirectory/TestLongEditChain, TestContainer/TestLongExecChain and the WithNewFile tests;TestLocalCache GC and prune tests (8);TestCachePersistence/TestDiskPersistenceAcrossRestart (11 subtests, including local cache survival, native snapshotter and unclean shutdown).local-cache prune with no session empties the ancestry lease. A prune while a session holds a 50-deep chain leaves the chain evaluating correctly.One session builds 16 parallel chains of 1000 withNewFile edits, each result synced. Main (fcce0f8) → all memory PRs combined, with the session still open: retained heap under leases and the bolt metadata store 250 → 55 MiB (4.6×).
Chart and all demos: memory cake. Reproduce: memoryCake.demo15232(ref: "memory-cake-all") from #15237 (workload in fixtures/15232/).
Impact: Medium. Lease records for retained deep chains drop from owners × depth to owners + depth (200-deep chain: 4.5 MB → 393 KB of heap, 20,100 → 399 records), but the shallow memory-soak workload showed no measurable change (~203 MB both).
Confidence: Medium. Unit, race, GC/prune and restart-persistence integration tests pass, and two rounds of review findings are fixed with regression tests. A downgrade, an upgrade of a long-lived production cache, and a manual chain-survives-restart check (the lab engine prunes everything at shutdown) were not exercised.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Owner leases cost memory proportional to results times chain depth: AttachLease records every ancestor of the snapshot for the lease, as a containerd lease resource (a node of the in-memory fastbolt metadata store) and as two in-memory owner records. One result per snapshot of a 200-deep chain, as a chain of Directory.withNewFile calls makes, holds 20100 lease resources and 40200 owner records, +4.5 MB of live heap (22.6 KB per result, ~224 B per pair); 200 results on one 50-deep snapshot hold 10000 (+2.2 MB). The tests log these numbers, and can write a heap profile with -owner-lease-heapprofile. Signed-off-by: Alex Suraci <[email protected]>
Owner leases are gc.flat, so AttachLease named a snapshot's whole ancestor
chain, snapshots and blobs, in every dagql owner lease. That costs
O(owners x chain depth) lease resources, and with the in-memory fastbolt
metadata store all of it is retained heap.
A dagql owner lease ("dagql/result/") now names only its tip snapshot and
that snapshot's blobs. Each manager has one shared flat lease,
dagger/owner-ancestry/<random generation>, that names every ancestor of an
owned tip. Refcounts are kept in memory: a snapshot is kept while some owner
has it as a tip or a kept child has it as a parent. AttachLease walks Stat
from the tip up to the first ancestor already kept, then writes the owner
lease and the newly kept ancestors in one transaction. RemoveLease deletes
the owner lease first, then decrements the refcounts down the chain and
removes ancestry resources that drop to zero. Lock order is ownerLeaseLocker,
then ancestryMu, then cm.mu.
recordSnapshotContent also attaches blobs to the ancestry lease for
snapshots it names, and PersistentMetadataRows counts ancestry members as
owned. DeleteStaleDaggerOwnerLeases deletes the ancestry leases of other
generations last, after dagql has re-attached every kept owner at boot.
Other AttachLease callers (pins, operation leases, services, scratch) still
name the full chain.
TestOwnerLeaseRecordsOn*, one result per snapshot of a chain:
200-deep chain: 20100 -> 399 lease resources,
+4.5 MB -> +381 KB live heap (22.6 KB -> 1.9 KB/result)
200 results on one 50-deep snapshot:
10000 -> 249 lease resources, +2.2 MB -> +264 KB
Signed-off-by: Alex Suraci <[email protected]>
Name the owner ancestry lease dagql/result/owner-ancestry/<gen>. An engine that predates the ancestry lease deletes every dagql/result/ lease it does not keep at boot, after attaching the whole chains of the owners it keeps to those owners again: on a downgrade it frees the ancestry lease instead of leaking every snapshot and blob it names for good. TestSnapshotTransferTypedAdoptionAndRestart counts leases and owners; the ancestry lease, which holds the imported snapshot's ancestors, is neither, so the test leaves it out. Signed-off-by: Alex Suraci <[email protected]>
recordSnapshotContent checked under cm.mu whether the ancestry lease named a snapshot, dropped the lock to attach the blob, and counted it afterwards. A RemoveLease releasing the snapshot in that window either left the blob attached to the ancestry lease with nothing counting it, so it was never deleted, or, for a blob a released ancestor shared, deleted it from the lease before it was counted for the snapshot that stays kept: the collector then took the blob of an owned ancestor. The ancestry part of a blob record now runs under ancestryMu, like every other change to the ancestry, from the check to the count. Records for snapshots the ancestry lease does not name skip it: an attach that names the snapshot later picks the blob up in attachPendingAncestryBlobs. The two race tests fail without the change. A third covers the attach picking up a blob recorded during it, which no test reached. Signed-off-by: Alex Suraci <[email protected]>
Two cleanup paths could lose track of what the ancestry lease holds: - RemoveLease drops the in-memory counts before it deletes the released ancestors from the ancestry lease. When that write failed, a retry found nothing to release, and the ancestors stayed until a restart. What a failed write leaves is now kept, under ancestryMu, and taken out by the next removal, minus anything the ancestry names again by then. - DeleteStaleDaggerOwnerLeases deletes the previous process's ancestry lease, which holds the ancestors of every owner it kept, assuming each kept owner lease has been attached again. dagql attaches them all first; should a kept one not be attached, the old ancestry lease now stays for a later start, rather than letting its owner's ancestors be collected. Signed-off-by: Alex Suraci <[email protected]>
The boot re-attach of owner leases runs on all cores, but dagql owner leases now share the snapshot manager's ancestry lease, whose changes the manager serializes. Each attach walks to its first kept ancestor, so the serialized part is about one snapshot and one metadata write: 2000 parallel attaches on a 200-deep chain take 36ms, against 323ms when each lease named its chain. Signed-off-by: Alex Suraci <[email protected]>
The ancestry's blobs change only under ancestryMu and mu, like its counts; dagql owner-lease attaches run one at a time end to end; and the pruning doc names the ancestry lease as what keeps a result's ancestors. Signed-off-by: Alex Suraci <[email protected]>
One session builds 16 withNewFile chains 1000 results deep, every result synced so it owns its snapshot. On main each owner lease names its whole chain (up to 128 layers): focus 235.8 MiB live, 54.1 MiB on the PR branch, 63.7 MiB on memory-cake-all. ~20-30 s per session. Signed-off-by: Alex Suraci <[email protected]>
|
🤖 I'm parking this as a draft after a second-look review. The code looks correct, but on a real engine it saves very little, and its stated reason for the change turned out to be wrong.
A question for @sipsma, who may know the history: why are owner leases If this is revived, it needs:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
@vito it's pretty much vestigial at this point and just survived the buildkit->dagql transition When caching moved from buildkit to dagql in #11856, we kept it on purpose: every engine lease flat, and our own metadata, not containerd labels, deciding which blobs belong to a snapshot. It was never about parents. You're right that flat snapshots still follow them, and the design notes from then say so. #14264 later put the gc.ref.content.blob label on snapshots but left the leases flat, and we never revisited that. I agree a non-flat owner lease on the tip should be able to replace the #13307 chain walk and this PR's bookkeeping. Besides the manifest/config caveat, which a label on the image-top snapshot would cover, the checkpoint's content-hash rows and the transfer pins lean on the walk today and would need to follow. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
🤖 Closing for now, thanks @sipsma for the history. We'll come back to this if lease bookkeeping turns out to matter. On a live dev engine the lease slice was 182 MiB of a 15.5 GiB heap, and this PR would save at most about 60 MiB of it. What we'd come back to: your direction, not this PR. Instead of the
Why not now: the risk is out of proportion to the saving.
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.