Commit Graph
4216 Commits
Author SHA1 Message Date
Anees Iqbal 75eb3bfc97 RUNTIME_VERSION 2083: a buffer bound inside an import holds its keep-alive, counted and announced; memory_frees_paced under the race rule
The commits before this one. Since 2073 a second no-copy buffer over a live import's pages is
bound inside that import instead of importing the pages again (VK_EXT_external_memory_host leaves
a second import undefined). The inside buffer keeps the import, so the import keeps the first
buffer's keep-alive until both are released. With a keep-alive the deallocator still runs at
release, as Metal's does; given none, it is delayed until the inside buffer goes, announced as
host-deallocator-delayed (now naming the inside buffer) and counted
(WorkCounts::host_releases_held_inside; a HostImport counts the buffers bound inside it). API.md
records it as an accepted difference: later than Metal, never early. The keep-alive and
dma_buf_imports lane tests that expected two imports are rewritten (the half-range buffer asks
about no mapping: inside the import or a copy). memory_frees_paced, which lands in a different
replay case each run (other cases' quiet-period frees), is reported under the race rule beside
memory_frees_posted.

Verified (potluck jobs, on the branch at 6e51633beb): M3 4/4 keep-alive tests with the counts at
each step (m3-max-18978); 780M 5/5 (18988); lavapipe 5/5 and 229/229 touched suites (18973); M3
replay: memory_frees_paced over no bound (18992); whole-set contrast d0f800ddd0 (18926) vs base
(18864): the frees did not increase. Lint (fmt, clippy all-features, m2v_gpu, m2v_cpu_icd, rustdoc):
19002. Bisect: 8db2f6f5c8 and 269d7066c4 pass, 4f3bc2e7a3 (2073) fails.
Not run: NVIDIA, XTX, full suites.
2026-11-11 21:51:21 -08:00
Anees Iqbal f2cf35406d Tests: a buffer over half a live dma-buf import's bytes asks about no mapping, inside it or a copy
runtime_lane::dma_buf_imports::a_buffer_that_lies_in_a_live_import_asks_about_no_mapping expected
a buffer over the first half of a live buffer's bytes to make its own import and ask the kernel
about its 32 mappings. Since RV 2073 (one page, one import) a page a live import holds is never
imported again: the half is bound inside the live import, or, where that import's memory is the
first buffer's alone (its own dma-bufs, dedicated to its VkBuffer), a copy of its pages
(copied_over_live_imports). Neither asks about a mapping: the live import's making asked about
them all, and the pages stay writable while imported. The test failed at 945 on the RTX 5080
(m3-max-18801) and the RX 7900 XTX (m3-max-18892): asked 0 where it expected 32, no error.

It now asserts no mapping asked, the half inside the import or a copy (one of the two counts),
no import made over the live one's pages (imports_inside_live unchanged), the half's source
uncalled, and the GPU reading the CPU's bytes through the half.
2026-11-11 21:51:08 -08:00
Anees Iqbal b649078d10 Docs: a buffer bound inside a no-copy buffer's import holds its keep-alive, or its deallocator
The release order RV 2073 brought, in the docs a consumer reads. A no-copy buffer made over part
of a live one's bytes, or over the same bytes as memory of another class, is bound inside the
live one's import (one live import of a page: VK_EXT_external_memory_host leaves a host allocation
imported twice into one device undefined) and holds it, so the live one's keep-alive is dropped
only once both are released and the import is freed. With a keep-alive its deallocator still runs
at its release, as Metal's; given none, the deallocator waits for the free, announced as
host-deallocator-delayed.

- API.md: the host-deallocator-delayed entry names the cause and its cost; section 10 (Heaps and
  memory) records the keep-alive's later drop as an accepted difference, with
  WorkCounts::host_releases_held_inside.
- HOWTO, "Unmapping host memory": the order for a buffer over part of another's bytes.
- The runtime README's no-copy paragraph and KeepAlive's doc name it.
2026-11-11 21:51:08 -08:00
Anees Iqbal 1badfbfffc Keep-alives: a buffer bound inside an import holds it; count those releases, test them on every device
Since RV 2073 (cfd7bc829e, one page one import) a no-copy buffer made over part of a live one's
bytes, or over the same bytes as memory of another class, is bound inside the live one's import
(Device::bind_in_import, Placement::in_import holding the import) instead of importing the pages
a second time. It holds that import until it goes, so the first buffer's release is outlived: its
keep-alive is kept by the import, or, given none, its deallocator waits for the free. That is the
order the single import needs (it maps the pages the first buffer's keep-alive keeps), but the two
lane tests still expected the second buffer to be an import of its own: on the M3, where the
texture's image is a shadow, each waited 60 s for a keep-alive that goes only once the second
buffer goes (m3-max-18537, bisected: 269d7066c4 passes in m3-max-18841, 4f3bc2e7a3 fails in
m3-max-18861).

- HostImport counts the buffers bound inside it (Inside, one per buffer however many clones of its
  placement share it). A release that keeps a keep-alive, or delays a deallocator, while one lives
  is counted: WorkCounts::host_releases_held_inside (new). The delayed deallocator's announcement
  names that cause instead of a texture's command buffer.
- keep_alives.rs: a_kept_keep_alive_covers_later_buffers_over_its_bytes and
  a_narrower_live_buffer_covers_no_wider_released_one branch on whether the second buffer lies
  inside (object_churn.buffers_bound_in_import), watch the kept keep-alive stay, and show both
  keep-alives go once the second buffer is released, printing the counts at each step;
  a_buffer_inside_an_import_holds_a_deallocator_given_no_keep_alive (new) shows the deallocator
  given no keep-alive runs after the inside buffer's release, counted and announced once.
- host_ab prints the new count; api_signatures blessed for the field.

(The commit before this one names its test wrongly: the race rule's rows are held by
a_count_that_says_which_thread_arrived_first_is_never_gated.)
2026-11-11 21:51:08 -08:00
Anees Iqbal 63a27d0025 Cost: memory_frees_paced is reported under the race rule, beside memory_frees_posted
RV 2071 added WorkCounts::memory_frees_paced, the frees of the runtime's own background threads
(the free thread, the residency thread, a guest RAM's threads) that waited after the free before
them. Every cost record bounded it at 0 (measured before it existed), and the whole-set replay at
43d2308170 on the M3 (m3-max-18632) put it at 1 on fresh-buffer-private and 2 on
fresh-texture-2d-rgba8unorm-shared.

Those frees are not the cases' work: run alone and as a pair, eight runs each, neither case counts
a free of any kind (m3-max-18854). The paced frees land in their window from the background
threads' timed frees (the quiet period's, which memory_frees_posted already reports, and the idle
windows'), and whether one waited depends on how soon it came after the one before. The tip's
whole-set measurement (m3-max-18574) moved it between runs of one case: depthstencil-depth-codes
0..2, read-write-tier-round-trip-uint 0..1. A re-bless of the two records would not hold, so the
count joins the race rule with its reason (PACED); racy_counts_are_reported holds it there.
2026-11-11 21:51:07 -08:00
Anees Iqbal 71874aefa2 Tests: the spares' burst test reads its counts once each command buffer is done, never polling
command_buffers_the_spares_hold_fall_back_after_a_burst_freed_on_the_free_thread took 32 s on
lavapipe: it polled the spares' count until a guessed condition held, up to 30 s each, and for
a command buffer of 2 encoders the guess (one encoder's count plus one) never held, the pool
holding 3 after both (2 primaries and its secondary, as after one encoder and its barrier's
command buffer). A broken fall-back would have waited out the 30 s of the last poll as well
before failing.

The polls had nothing to wait for: a command buffer's wait returns once its completion's
transition ran, the gate's hold going after it (Transition::run, command_buffer/gate.rs), its
pool's give-back and begin ahead included, and fills() then drains the frees that give-back
posted. So each count is final once fills() returned, and the test reads it there. held_once,
used by this test alone, goes. The assertions are unchanged: freed on the free thread alone,
the burst's count at least one encoder's plus half the burst, and after the load fell back at
most one encoder's plus two.
2026-11-11 21:51:07 -08:00
Anees Iqbal bc08cf1c54 Re-pin the runtime sources at the landing tip
The landed packet changed a runtime-sources input, so the committed digest no

longer described the sources and `the_runtime_sources_are_the_committed_ones`

would fail. Recomputed over the same inputs and committed by land-pkt.sh.
2026-11-11 21:50:32 -08:00
Anees Iqbal 87399f4100 RUNTIME_VERSION 2082: no guest RAM page is imported twice while a chunk's or an object's import is in flight, and a rebind's import is noted
The commits before this one.
1. In-flight claims. 2080's straddle copy and held-back chunk read only finished state, so an
   object made while a chunk's import was in flight, or a chunk imported while an object's own
   import was between its checks and its note, imported the same pages twice. Each RAM the
   device uses now keeps the claims of objects' own imports in flight (Device::claim_ram_pages,
   held through the import until it is noted). A chunk's import is marked in flight only under
   those claims and is held back where a claim meets its pages. Whichever starts first, the other
   never imports the same page; the loser is a copy (CopiedBecause::OverRamChunk).
2. Rebinds. A rebind's own import of its new pages was placed but never noted in the alias
   registry, so once its claim dropped a chunk could still be imported over the rebound buffer's
   pages. It is now noted with a hold (no key joined), and a rebind onto bytes a rebound buffer's
   import holds lies in that import instead of importing them a second time.

Tests (lavapipe, on the branch): the two in-flight tests, which hold a chunk's import or an
object's gate with test-only pauses, failed 3/3 before the fix (m3-max-18881) and pass 3/3 with
it. The rebind test's negative control fails (the chunk imported over the rebound buffer's
import; 18968, 19006). The host_ram, aliases, copied, rebind, dma_buf, residency and host_import
sets pass 260/260, and the whole lavapipe runtime suite passed but for two failures since fixed
on development (19006, 19034). host_import_counts' rebind test now asserts one import
(..._shared_over_bytes_it_holds). Lint (clippy plain, m2v_gpu, m2v_cpu_icd; rustdoc) clean.
Not yet in at landing: the suite rerun at the rebased tip (19047); no GPU device runs of this item.
2026-11-11 21:49:32 -08:00
Anees Iqbal 41b54edde6 Rebind: the noted import joins no key; a rebind onto a rebound buffer's bytes lies in its import
b5bfbaf377 noted a rebound buffer's own import with join, which gives the buffer the memory's
key: host_aliases.rs keeps the memory a rebound buffer takes unjoined ("Not joined"). It is now
noted with hold, as a heap's own import is, joining no key, and so is the live import a rebind's
new pages lie in (shared by bytes another buffer's note holds), so that the note stays while any
buffer lies in it.

With the import noted, a rebind onto bytes a rebound buffer's import holds lies in that import
(one page, one import) where it imported them a second time before.
host_import_counts::a_rebind_s_import_is_unlisted_until_a_command_buffer_uses_it_and_covered_
over_bytes_lain_over (m3-max-18968: [2, 1, 2] expected, the second rebind making no import)
asserted that second import; it is renamed ..._and_shared_over_bytes_it_holds and asserts one
import, none covered, unlisted until the first command buffer. host_aliases.rs's docs say the
bytes rebound onto are looked up and shared as those made over.
2026-11-11 21:49:23 -08:00
Anees Iqbal 711b74238b Rebind: an import of the new pages of the buffer's own is noted, as a making notes one
rebind_host_pages placed the new pages in the alias registry (aliases.place) but never noted
their import, so held_back could not see it: a guest RAM chunk holding some of a rebound
buffer's own imported pages was imported over them, the same pages imported twice
(a_rebind_s_own_import_holds_its_chunk_back_while_it_lives).

After the rebind leaves the memory it was made over, an import of the new pages of its own (not
a copy, not bound in a chunk or inside another import, not a read-only view) is noted as a
making notes one: join for a buffer, hold for a heap's own buffer. The rebind's claim of guest
RAM pages (Device::claim_ram_pages) now lasts until that note, so no chunk's import slips in
between the import and the note.
2026-11-11 21:49:23 -08:00
Anees Iqbal 79424a7169 Tests: a rebind's own import holds its chunk back while it lives
A buffer rebound onto two runs of a chunk not imported yet imports its new pages itself. While
that import lives, the next object over the chunk's other pages must not import the chunk (one
page, one import): it takes its own path, counted held back; once the rebound buffer went, the
next object imports the chunk and is bound there. rebind_host_pages places the new pages in the
alias registry (aliases.place) but never notes their import (join or hold), so held_back cannot
see it and the chunk is imported over them: this test is expected to fail here.
2026-11-11 21:49:23 -08:00
Anees Iqbal 88af28874e Host RAM: an object's own import claims its RAM pages until noted; chunks mark in flight under the claims
The straddle copy (f083e9c806) and the held-back chunk (c55501db1b) each read only finished
state: an object's check read made chunk imports alone (chunks_hold_any), and a chunk's check
read noted object imports alone (the alias registry). So an object made while a chunk's import
was in flight, or a chunk imported while an object's own import was between its checks and its
note, imported the same pages twice. Both tests of 1d77522508 showed it on lavapipe, 3 runs of
3 each (m3-max-18881): imports_inside_live 1.

Each RAM the device uses now keeps the claims of objects' own imports in flight. An object's
making and a rebind claim their window's RAM pages (Device::claim_ram_pages) where no chunk binds
them, and hold the claim through their import until it is noted: where a chunk's import, made or
in flight, holds some of the pages, nothing is claimed and the object is a copy
(CopiedBecause::OverRamChunk, as for a made one). A chunk's import is marked in flight only under
the RAM's claims (RamOnDevice::chunk takes them before the chunk's lock, as a claim does, and
looks at the chunk again), and is held back where a claim meets its pages (held_back), as where a
noted import does. Whichever starts first, the other never imports the same page.

Docs: host_ram.rs's one-import bullet; the OverRamChunk cause, copied_over_live_imports and
docs/API.md's copied-host-pages entry say made or in flight.
2026-11-11 21:49:22 -08:00
Anees Iqbal 2172b1e1bc Tests: no page imported twice while a chunk's or an object's import is in flight
Two deterministic tests, each holding one import in flight by a handshake rather than by timing:
- an object over two runs inside a chunk made while the chunk's import, marked in flight
  (Import::Making), is held by a test-only pause (RamSource::making_pause, called in
  RamOnDevice::chunk before the import is made);
- the reverse: the chunk imported by its first object while an object over two other runs of the
  chunk is held in its gate, after its checks and before its own import.
Each asserts imports_inside_live 0 and that the objects read the RAM's bytes. The chunk check
(chunks_hold_any) reads only made chunk imports, and held_back reads only noted imports, so at
this commit both are expected to fail: a page imported twice.
2026-11-11 21:49:22 -08:00
Anees Iqbal 938ec37659 Tests: a Private export after a dma-buf import is device-local only where the control's is
The export test asserted a device-local type for both exports on every device. On a Radeon 780M
(RADV, m3-max-18941) the control, a device that imported no dma-buf, already places a Private
exportable buffer in type 2 (HOST_VISIBLE | HOST_COHERENT), so the test failed there with the
import's export where the control's lies. It now asserts the control's flags and no overflow on
every device, and a device-local type where the control's is one (the RTX 3090, ANV).
2026-11-11 21:49:22 -08:00
Anees Iqbal 5f72e080c5 Re-pin the runtime sources at the landing tip
The landed packet changed a runtime-sources input, so the committed digest no

longer described the sources and `the_runtime_sources_are_the_committed_ones`

would fail. Recomputed over the same inputs and committed by land-pkt.sh.
2026-11-11 21:37:15 -08:00
Anees Iqbal cdbfec92d9 RUNTIME_VERSION 2081: the command-buffer spares keep their bound of 4096 under load
The commit before this one. The spares held 4097 command buffers against HELD = 4096 in a loaded
lavapipe runtime suite. CommandPool::past(keep) kept one secondary even where keep was 0, so a
pool given back while another pool trimmed to the bound was out with its frees waiting on a slow
free thread kept one past the bound. Spares::begin_ahead made a new primary in a pool holding none
with no bound check. Both now keep the bound: past() honours keep exactly, and a pool whose begin
ahead would make its primary goes out only where the spares and what is out stay within HELD. On
ANV below Xe-HP each spare command buffer holds a 64 KiB block of the binding-table pool, so the
bound is the product's.

Verified (potluck jobs, lavapipe, on the branch at 63a732359c): the forced interleaving test
a_pool_given_back_while_the_bound_is_out_freeing_keeps_none_past_it holds exactly 4096 before and
after a begin ahead; all 19 spares tests pass (m3-max-18938); full runtime suite 2228/2229 with all
spares tests passing (18945; the one failure was the exit_guard scan, fixed in 2e71b1818a).
Negative controls: the product as at the base fails the new test at 4097, 4098 after the begin
ahead (18990); with the first fix alone, 4097 after the begin ahead (18948). Lint (fmt, clippy
plain, m2v_gpu, m2v_cpu_icd, rustdoc): 18942.
Not run: GPU devices (ANV, RADV, NVIDIA, M3); release-mode timing (off the hot path).
2026-11-11 21:36:16 -08:00
Anees Iqbal 9958615931 Spares: a pool given back and a begin ahead keep the bound of HELD command buffers
The spares held 4,097 command buffers against their bound of 4,096 in a loaded lavapipe
runtime suite (tests::spares::device::command_buffers_alive_at_once_leave_the_spares_holding_at_most_held),
while the test passed alone. The product exceeded its bound; the test read nothing early.

Two places added command buffers past HELD:
- CommandPool::past(keep) always kept one secondary (and never freed the primary begun
  ahead), even where keep was 0. A pool given back while another pool trimmed to the bound
  was out of the spares, its frees waiting on the device's free thread (slow under load),
  computed keep = 0 and kept its secondary anyway: HELD + 1 once both came back. past()
  now frees, past keep, secondaries down to one, then primaries, then that secondary, then
  the primary begun ahead.
- Spares::begin_ahead made a new primary in a pool holding none and kept it again with no
  bound check. take_to_begin moves onto CommandPools: a pool whose begin makes its primary
  goes out only where the spares and what is out hold fewer than HELD, counted out with
  the primary it makes so a give-back meanwhile keeps the bound with it.

On ANV below Xe-HP each spare command buffer holds a 64 KiB block of the binding-table
pool, so the bound is the product's to keep.

Test: the free thread's test hold now also holds a spare pool's frees.
tests::spares::device::a_pool_given_back_while_the_bound_is_out_freeing_keeps_none_past_it
forces the interleaving: the free thread held, a command buffer of HELD + 64 blit
encoders (its pool trimmed to HELD, out freeing), then one of one encoder, then the hold
released; the spares must hold HELD, and still after a begin ahead in the newest pool
(which holds no primary). Unit tests cover past() and take_to_begin's room and count.
2026-11-11 21:36:06 -08:00
Anees Iqbal 36bfd48bba Re-pin the runtime sources at the landing tip
The landed packet changed a runtime-sources input, so the committed digest no

longer described the sources and `the_runtime_sources_are_the_committed_ones`

would fail. Recomputed over the same inputs and committed by land-pkt.sh.
2026-11-11 21:24:48 -08:00
Anees Iqbal 2e71b1818a Test: the per-thread makings test, which starts a thread, lives in src/tests
exit_guard's threads_and_the_program_s_code_go_through_the_guard scans the runtime's sources for
thread starts outside exit_guard.rs, skipping src/tests/ alone. 73d706151e put
a_thread_s_makings_are_its_own_and_those_it_waited_for, which starts a thread, in churn_counts.rs's
own test module, so the scan failed on development ("threads started elsewhere:
churn_counts.rs: thread::spawn(..)"; lavapipe runtime suite, m3-max-18945). The test moves
unchanged to src/tests/churn_counts.rs; the items it uses are pub(crate). Test-only: no runtime
behaviour changes.
2026-11-11 21:24:09 -08:00
Anees Iqbal 7c1a963111 Re-pin the runtime sources at the landing tip
The landed packet changed a runtime-sources input, so the committed digest no

longer described the sources and `the_runtime_sources_are_the_committed_ones`

would fail. Recomputed over the same inputs and committed by land-pkt.sh.
2026-11-11 21:21:19 -08:00
Anees Iqbal ff9cf4c89e RUNTIME_VERSION 2080: dma-buf imports skip the type NVIDIA refuses, and no guest RAM page is imported twice
The commits before this one, two changes.

1. dma-buf memory type order (c267e94e74, refined in 85041aa633). NVIDIA's 620.70.06 lists a
   udmabuf of host pages as type 0 (system memory, no flag) and type 4 (host-visible, coherent,
   cached). It refuses every import as type 4, and once it has refused one, it refuses every
   later exportable device-local allocation for the device's life. So every Private exportable
   buffer after the first Shared import overflowed into system memory. The runtime never maps a
   dma-buf import, so system-memory types the host maps (HOST_VISIBLE without DEVICE_LOCAL) now
   go last, and device-local types keep their class's order. NVIDIA imports as type 0 without
   the refused attempt. ANV, RADV and lavapipe keep the class's order: the refinement exists
   because the first form moved ANV's Shared imports from its coherent cached type 2 to type 0.
2. One live import per guest RAM page (ea4bbb5fa3, 53501197a8). A guest RAM chunk is held back
   while a live import of an object's own holds its pages (host_ram_chunks_held_back). An object
   across two imported chunks, or over a live chunk's pages that no resolver routed, is a copy of
   its pages (CopiedBecause::OverRamChunk, announced as copied-host-pages), at its making and at
   a heap's rebind, never a second import (VK_EXT_external_memory_host issue 6 leaves that
   undefined). reims's walks on the 2080 and 3090 met it at boot: imports_inside_live = 1, a
   2 MiB heap across a 64 MiB chunk's end.

Verified (potluck jobs, on the branches):
- Export: lavapipe and Iris Xe ANV at be0cd3e124 (m3-max-18858): ANV's order equals the class
  order for every class and both sources, Shared/WriteCombined/Managed type 2 and Private type 0;
  lavapipe 27/27, the memory unit tests included. The 3090 export test failed before the change
  (type 0, one overflow each).
- RAM: the straddle and rebind negative controls (the chunk check disabled) fail as they should:
  the straddling heap gives one pointer import and imports_inside_live 1. With the fix, 141/141
  pass across the host_ram_device, aliases, copied, rebind, one_import and dma-buf sets on lavapipe
  (m3-max-18807). Lint (clippy plain, m2v_gpu, m2v_cpu_icd), rustdoc, api_signatures, api_surface
  and refusal_surface are clean (18863, 18901).
Not yet in at landing: the 3090 (18803, at d8944892df), XTX (18859) and 780M (18941) export runs
at be0cd3e124.
2026-11-11 21:20:20 -08:00
Anees Iqbal e93baf2b6b Tests: a rebind onto runs a live chunk holds is a copy, the gate not asked
The rebind onto two runs that the first chunk's live import held asked the gate and, admitted,
would have imported those pages a second time; since f083e9c806 it is a copy
(CopiedBecause::OverRamChunk), the gate unasked, and the lavapipe suite (m3-max-18714) failed
a_rebind_onto_several_runs_takes_the_gate_and_the_copy_where_it_refuses on 'the gate asked once'.
That test now rebinds onto runs of the second chunk, which no import holds, so it still covers
the gate's path; a new test covers the rebind onto a live chunk's runs: a copy, no import of its
own, none over a live import's pages, its bytes read and a fill through it written back.
2026-11-11 21:20:02 -08:00
Anees Iqbal ab316b4b1a Tests: the straddling heap's chunk-importing buffers lie away from its pages
The buffer that imported the second chunk lay inside the heap's pages (64 KiB into the chunk,
the heap reaching 1160 KiB into it), so the heap met that buffer's live import and was a copy
for it (CopiedFor::OverImport) with or without the chunk check: the lavapipe negative control
(m3-max-18714, the chunk check disabled) passed. The second chunk is now imported by a buffer at
96 MiB, past the heap's end, so only the chunk check makes the heap a copy.
2026-11-11 21:20:02 -08:00
Anees Iqbal 53501197a8 Host RAM: an object across two imported chunks is a copy, never a second import
A no-copy object whose pages cross the end of a guest RAM's chunk, the chunks on both sides
imported, is bound in neither: route_runs answers Runs, and the object took the gate's path
and imported its own pages, the same host addresses as the two live chunk imports
(VK_EXT_external_memory_host leaves that undefined; imports_inside_live counted it). The
consumer's walks hit it at boot on the 2080 and the 3090: a 2 MiB heap from 0x3f22000 into a
64 MiB chunk, 0xde000 bytes in the first chunk and 0x122000 in the next.

Such an object, and one over a live chunk's pages that no resolver routed, is now a copy of its
pages (CopiedBecause::OverRamChunk, counted in copied_over_live_imports, announced as
copied-host-pages, the gate not asked), at its making and at a heap's rebind. Chosen over:
- aligning chunk imports to objects: the chunks are imported ahead, before the objects over
  them exist, and objects lie anywhere;
- one import over both chunks: each chunk's import already binds objects when the straddling
  one comes, and swapping it would move every bound object;
- a sparse binding of both chunks' memory: heaps place resources at any offset, and not every
  device binds sparse buffers.
A copy costs one copy of the object's pages per commit, the rare edge object alone (one per
chunk end an object crosses).

Test: a_heap_across_two_imported_chunks_is_a_copy_and_imports_nothing (the consumer's shape:
both chunks imported by a buffer each, then a 2 MiB heap from 0xde000 before the first chunk's
end): one copy, no pointer import, imports_inside_live 0, the gate not asked; a buffer placed
across the chunks' end reads the RAM's bytes and a fill through it reaches them.
2026-11-11 21:20:02 -08:00
Anees Iqbal ea4bbb5fa3 A guest RAM chunk waits while a live import of an object's own holds its pages
reims's pin 42 walks on the RTX 2080 counted imports_inside_live = 1 at boot, once in each of
two walks, in the second the device's thread imported its first chunks ahead (with a 2 MiB
pointer import and host_imports_kept_of_heap in the same second). A no-copy heap made over the
RAM's pages before use_host_ram (or with no run resolver) imports its own pages outside the
RAM's routing, and the thread's import of the chunk holding them then imported those pages a
second time, which VK_EXT_external_memory_host leaves undefined (issue 6).

Now RamOnDevice::chunk holds the chunk back while HostAliases::within finds a live import over
its span (RamOnDevice::held_back): no import, the device's thread marks it tried, an object
over it falls back to the paths of memory no RAM holds (its own import, inside the live
import, or a copy), and copy_take sends copies over it through the CPU. Once every such import
over the chunk went, the next object over it imports it. Counted:
WorkCounts::host_ram_chunks_held_back (api_signatures updated).

Docs: host_ram.rs's module doc no longer describes pointer chunks' runs imported alone (the
2073 fix made those dma-buf-only); it states the held-back chunk. host_aliases.rs,
churn_counts.rs's imports_inside_live and HOWTO's guest RAM paragraph say the same.

Test: host_ram_device::a_chunk_a_live_import_made_before_the_use_holds_waits_for_it_to_go
(a heap over the first chunk made before the use; the thread and a buffer's take hold the
chunk back, the buffer imports its own pages and reads the RAM's bytes, no import inside a
live one; once both went, the next buffer is bound in the chunk).
2026-11-11 21:20:02 -08:00
Anees Iqbal 85041aa633 dma-buf imports try only the system-memory types the host maps last
87b0acd6d5 tried every type the host does not map before every type it maps. On an Iris Xe
(ANV, Mesa 26.2.x, m3-max-18804) that moved Shared, WriteCombined and Managed imports of a
udmabuf and of a device-local dma-buf from type 2 (DEVICE_LOCAL|HOST_VISIBLE|COHERENT|CACHED,
the class's first) to type 0 (DEVICE_LOCAL alone). On a unified-memory GPU the host's flags on
a device-local type may choose how the GPU caches its accesses to the pages, so that move is
not shown to be harmless.

Now only the system-memory types the host maps (HOST_VISIBLE without DEVICE_LOCAL) go last;
device-local types keep their class's order. NVIDIA's udmabuf types (0: no flag, 4: host-visible
coherent cached system memory) still order 0 before 4, so the 3090's result stands. ANV's types
are all device-local, RADV's for a udmabuf all host-mapped system memory, lavapipe's one: the
class's order as before.

Unit test: dma_buf_imports_try_the_system_memory_types_the_host_maps_last (renamed), with an
ANV-like set (all device-local, unified) and a GTT-like set (all host-mapped system memory)
whose orders and forms stand. FAST-PATHS's NVIDIA dma-buf gap says the same.
2026-11-11 21:20:02 -08:00
Anees Iqbal 8abde0afb8 Tests: the dma-buf type check prints memory flags as their bits
ash's Debug of vk::MemoryPropertyFlags is behind a feature this crate does not enable, so the
test target did not build (m3-max-18728). The descriptor the driver exports is taken in a block
of its own, its SAFETY comment over it.
2026-11-11 21:20:02 -08:00
Anees Iqbal c267e94e74 dma-buf imports try the types the host does not map first
NVIDIA's 620.70.06 lists a udmabuf of host pages as its type 0 (system memory, no property
flag) and its type 4 (host-visible, coherent and cached, the Shared class's first), refuses
every import as type 4 with ERROR_OUT_OF_DEVICE_MEMORY, and imports it as type 0. Measured on
an RTX 3090 (tests::export_after_dma_buf, raw vkAllocateMemory answers on fresh devices): once
it refused an import as type 4, it answers ERROR_OUT_OF_DEVICE_MEMORY to every allocation of
its device-local type 1 exportable as an opaque fd or a dma-buf (with the device-address flag
or without), at 12,441,600 bytes and at 64 MiB, for the device's life; plain and
device-address-only allocations are still made. After a successful import as type 0, every
chain is made. Whether the import was dedicated does not matter. The runtime's first Shared
dma-buf import tried type 4 first, so every later Private exportable buffer overflowed into
system memory (type 0, DeviceMemoryOverflow).

The runtime never maps a dma-buf import (the CPU reaches the pages through the caller's own
mapping), so a type the host does not map serves it as well. dma_buf_candidates now orders the
types the host does not map first, then those it maps, each in the class's order
(dma_buf_class_order, the order before), and dma_buf_attempts tries every form (dedicated to
nothing, then to the buffer) of the first group before any form of the second. On NVIDIA the
import ends as type 0, as before, without the refused attempt. A driver that lists only
host-mapped types for a dma-buf keeps the class's order.

Tests:
- memory::dma_buf_imports_try_the_types_the_host_does_not_map_first (unit): both orders, and the
  attempts' order, for NVIDIA's types and for a set whose listed types are all host-mapped.
- export_after_dma_buf::a_private_exportable_buffer_after_a_dma_buf_import_lies_in_device_local_memory
  (renamed): asserts each export lies in a DEVICE_LOCAL type with the control's flags and no
  overflow counted. It failed on the RTX 3090 before this change (type 0, one overflow each).
- export_after_dma_buf::the_driver_s_answers_after_each_kind_of_dma_buf_import: kept as the
  driver's evidence, printed and not asserted.
- export_after_dma_buf::the_type_each_class_s_dma_buf_import_takes_against_the_class_s_order:
  prints, per class, the type the runtime's import takes and the type the class's order took,
  for a udmabuf and for a dma-buf of the device's own device-local memory; asserts they agree
  where both orders are the same.
docs/FAST-PATHS.md's NVIDIA dma-buf gap records the driver's refusal and the order.
2026-11-11 21:20:02 -08:00
Anees Iqbal 9cae29397c The memory log names each block the driver refused, with its chain and VkResult
A Private exportable buffer overflowed to system memory on an RTX 3090 after a dma-buf import
(m3-max-18507) with no record of what the driver answered: `place` tries each type, and a
refused block is only an Error::OutOfMemory there, whether the driver said out of device
memory or out of host memory. The default-off memory log (METAL2VULKAN_LOG_MEMORY) now
says, for every block BlockMaker::make_as fails to allocate, its memory type and bytes, the
allocation flags, the handle types it was to be exportable as, the buffer it was dedicated
to, and the VkResult. BlockMaker carries a clone of the memory's log for it.

Off, it formats nothing (the log is None). Verified: cargo fmt; the build and the 3090 run
come with the export measurement's next job.
2026-11-11 21:20:01 -08:00
Anees Iqbal 8b007248b0 Tests: the driver's answers to device-local allocations after each kind of dma-buf import
On an RTX 3090 (620.70.06, m3-max-18507) a Private exportable buffer made after one dma-buf
import was made and freed overflowed to system memory (type 0, one DeviceMemoryOverflow each
export) where a control device placed it in device-local type 1, with 24 GB of budget free.
The new measurement asks the driver directly, on a device per kind of import: none, the
test's own import as each type the udmabuf lists, the runtime's import as it makes it, and the
runtime's import with its undedicated form refused (so dedicated). After each it prints the
VkResult of device-local allocations of each chain the runtime's blocks pass, and where the
runtime places the exportable buffers.
2026-11-11 21:20:01 -08:00
Anees Iqbal 174d8b28c6 Tests: the export measurement's memfd is sealed against shrinking, as udmabuf requires
m3-max-18475 on the 3090 failed at the probe's UDMABUF_CREATE_LIST (an
unsealed memfd); its control ran: both exports in type 1.
2026-11-11 21:20:01 -08:00
Anees Iqbal a4812e920f Tests: the export measurement prints memory flags as their bits
ash's flag types have no Debug here (m3-max-18420 on um790).
2026-11-11 21:20:01 -08:00
Anees Iqbal 62032268aa Tests: where a Private exportable buffer lies after a dedicated dma-buf import's free
A measurement for the lead that, on NVIDIA, a dedicated dma-buf import
made and freed at a device's start leaves a 12,441,600-byte Private
exportable buffer in system memory. A control device makes and exports
the buffer (opaque fd, dma-buf) with no import; a second device first
makes and frees a no-copy buffer over the mapping of one udmabuf of
1,024 scattered memfd pages (the runtime keeps such pages' pointer from
NVIDIA's driver and imports the dma-buf, dedicated), then makes and
exports the same buffers. It prints each export's memory type, flags,
dedication and the overflows counted, and each heap's VK_EXT_memory_budget
budget and usage around the import (the runtime reads neither), and
asserts the exports' memory flags match the control's. Not yet run.
2026-11-11 21:20:01 -08:00
Anees Iqbal 91f1f4f12a Re-pin the runtime sources at the landing tip
The landed packet changed a runtime-sources input, so the committed digest no

longer described the sources and `the_runtime_sources_are_the_committed_ones`

would fail. Recomputed over the same inputs and committed by land-pkt.sh.
2026-11-11 21:01:12 -08:00
Anees Iqbal 9ec681c85c REFUSALS: regenerated for the pooled bound's moved refusal sites 2026-11-11 21:00:30 -08:00
Anees Iqbal 1ef739d294 RUNTIME_VERSION 2079: a texture over bytes another texture was made over takes the image at Metal's pitch
The commits before this one. A guest's window server makes dozens of textures over each of its
large Private surfaces (other formats of the same bytes, and a new texture each frame). Past the
pooled bound each was a shadow of its linear cost of its own: 216 shadows of 145 MB on a Radeon
780M at a login. storage_over_buffer weighed each texture alone. A buffer now notes the runs of
bytes textures were made over (texture_spans.rs, at most 8 runs, joined where they meet), so a
texture over bytes another texture was made over takes the DRM_FORMAT_MOD_LINEAR image at Metal's
pitch at any size, and the first texture's shadow moves to that image at the next quiet commit
with no copy. Both forms give Metal's answer, so the bound has no FAST-PATHS row. The quiet
commit's definition in HOWTO now also requires that none of the commit's work is left to record
after it (what takes_storage_forms checks).

Numbers (runtime_lane::aliased_surfaces::aliased_surface_costs, release; GPU not held
exclusively):
- 36 live textures over one Private surface, per frame: Radeon 780M 28.22 -> 0.22 ms (869 MB
  copied in and 290 MB back -> none; peak device memory 6037 -> 964 MB), Iris Xe 32.80 -> 1.40 ms
  (5842 -> 759 MB), lavapipe 119.08 -> 1.48 ms.
- Four made and released each frame: 780M 26.67 -> 0.18 ms (four 145 MB shadows a frame -> none),
  Iris Xe 28.37 -> 0.83 ms, lavapipe 102.05 -> 1.28 ms.

Verified (potluck jobs, on the branch): before 23c0a7e552 / after 990cfbacb6: 780M m3-max-18769 /
18831, Iris Xe 18707 / 18726, lavapipe 18608 / 18677; all four aliased_surfaces tests pass after
on all three, and both count checks fail before (4 shadows, 0 pitched images). The first shadow's
move: moved 1, freed 1, the next read copies nothing. Final lint at the branch tip 42d518f345:
m3-max-18833.
Not run: NVIDIA and the M3.
2026-11-11 21:00:02 -08:00
Anees Iqbal 9b1546d3f8 Pooled bound: the doc records what aliasing textures cost as shadows and as images
Measured with runtime_lane::aliased_surfaces::aliased_surface_costs (release, --cfg m2v_gpu or
m2v_cpu_icd), before the pooled bound's change (23c0a7e552) and after it (990cfbacb6 and
19b62892ac):
- Radeon 780M (RADV PHOENIX, gem10): m3-max-18769 before, m3-max-18831 after.
- Iris Xe (ANV RPL-P, ms01): m3-max-18707 before, m3-max-18726 after.
- lavapipe (msi): m3-max-18608 before, m3-max-18677 after.
36 live textures over one Private surface: 28.22 / 32.80 / 119.08 ms a frame with 869 MB copied
in and 290 MB back, 5211 MB of shadows, before; 0.22 / 1.40 / 1.48 ms, no copies, one shadow and
35 images at Metal's pitch, after. Four made each frame and dropped: 26.67 / 28.37 / 102.05 ms
with four 145 MB shadows made a frame before; 0.18 / 0.83 / 1.28 ms with none after. The GPU
was not held exclusively, so the times are a shared GPU's.
2026-11-11 20:59:50 -08:00
Anees Iqbal f9999c588c HOWTO: a quiet commit leaves none of its work to be recorded after it
The quiet-commit definition, where a shadow made before its verdicts (or a pooled texture's
shadow of its linear cost) moves in place, named only the uncommitted command buffers, events
and textures bound by ID. The commit also takes the move only where every batch before it was
submitted, every encoder of it may run, and none of its work is left to record after the commit
(command_buffer/storage_form.rs takes_storage_forms; Device::storage_form_switch). Found on
lavapipe: a diagnostic run (m3-max-18654, scratch prints, never landed) showed four compute-only
commits declining the move, each with recorded segments, and a blit's commit taking it
(moved 1, freed 1, the next read copying nothing).
2026-11-11 20:59:50 -08:00
Anees Iqbal 92063eeaa4 Lane: aliased_surfaces moves the first shadow at a blit's commit
The live-order check read the first texture through a kernel to commit the move. On lavapipe
(m3-max-18602) the move never rode on those commits: a diagnostic run (m3-max-18631, scratch
prints) showed each compute command buffer's commit declined storage forms
(command_buffer/storage_form.rs takes_storage_forms). The device's other move checks
(in_place_textures) commit a blit; this one now reads through a blit too.
2026-11-11 20:59:50 -08:00
Anees Iqbal c914f5720a Lane: aliased_surfaces copies its placement answers by value
clippy's clone_on_copy under --cfg m2v_gpu and --cfg m2v_cpu_icd: TexturePlacement is Copy.
Found by the lint job m3-max-18592 (msi).
2026-11-11 20:59:46 -08:00
Anees Iqbal cd8f1e5140 Pooled bound: the coercions to a type-erased texture keep their cast
3b6d600892 dropped the cast from both, and Arc::clone then takes its argument's type from the
annotation (m3-max-18585 refused it).
2026-11-11 20:59:46 -08:00
Anees Iqbal 59e44d4314 Pooled bound: the waiting texture's handle coerces without a cast 2026-11-11 20:59:46 -08:00
Anees Iqbal 8cb5400e78 Pooled bound: a texture over bytes another texture was made over takes the image at its pitch
A guest's window server makes dozens of textures over each of its large Private surfaces (other
formats of the same bytes, and a new texture each frame), and past the pooled bound each was a
shadow of its linear cost of its own (216 on a Radeon 780M at a login, 1022 in 13 s on an Iris Xe).
storage_over_buffer decided each texture alone: pooled_pitched_image answered LinearCost for any
tracked texture over a Private buffer past 48 KiB, so every texture over the same bytes made a
full image of its own, copied every texel in at its first use, copied in again after a write
through any other (which lets go of its standing) and copied back whole after a kernel's write.
The shadow log names the buffer's object, not the texture's, so one object's two lines 22 ms apart
are two textures over the same surface, a frame apart.

The bound weighed one texture over the bytes. A buffer now notes the runs of bytes textures were
made over (texture_spans.rs, at most 8 runs, joined where they meet), whether those textures
still live: a texture over bytes another texture was made over takes the DRM_FORMAT_MOD_LINEAR
image at Metal's pitch at any size, as over CPU-visible memory, and the first texture's shadow of
its linear cost moves to that image once another texture is made over its bytes, through the
existing pooled move (wait_to_move_in_place: at the next quiet commit, with no copy). Both forms
give Metal's answer; the textures alias the bytes as Metal's do. The bound has no FAST-PATHS row:
it chooses between two exact speeds (6717cac4ea). API.md, HOWTO and the LinearCost docs say so.

Verified: cargo fmt; builds and device runs follow as potluck jobs.
2026-11-11 20:59:46 -08:00
Anees Iqbal 150dd334b5 Lane: aliased_surfaces checks the first shadow's move and textures made one after another
textures_over_one_surface_s_bytes_take_one_shadow now also reads the first texture after the
textures were made: its shadow moves to the image at Metal's pitch at the next quiet commit
(pooled_textures_moved_in_place) and a later read copies nothing.
textures_made_one_after_another_over_one_surface_s_bytes_take_one_shadow makes the same four over
one surface's bytes, each written and released before the next, as a guest's frames make them:
one shadow, every later texture the image. Both fail until textures over bytes another texture was
made over stop taking shadows of their own.

Verified: cargo fmt; builds follow.
2026-11-11 20:59:46 -08:00
Anees Iqbal b297e9ff07 Lane: aliased_surfaces declares its surfaces' padding unobserved, as the guest's
Without the declaration a texture over rows that lie apart is a shadow of BytesBetweenRows on every
device (the Iris Xe's first run, ms01 job m3-max-18558), not of its linear cost: the guest's
surfaces declare it.

Verified: cargo fmt; builds follow.
2026-11-11 20:59:46 -08:00
Anees Iqbal b625494c31 Lane: aliased_surfaces imports AirLibrary 2026-11-11 20:59:45 -08:00
Anees Iqbal ccfd6e3f95 Lane: aliased_surfaces weighs many textures over one Private surface's bytes
A guest's window server makes dozens of textures over each of its large Private surfaces
(BGRA8Unorm and R32Uint, shader read and write, 6016x6016 at 24,576-byte rows) and writes and
reads a few each frame; past the pooled bound each texture is a LinearCost shadow of its own.
aliased_surface_costs (ignored, release) measures the guest's surface with 36 live textures and
with four made each frame: forms, shadows made, a frame's GPU time, shadow copies and texels
copied, and peak device memory (DRM fdinfo, resident set). Two checks over a small surface past
the bound: four textures over one surface's bytes take one shadow (fails until the fix), and a
kernel's write through each is what every other reads and the bytes hold.

Verified: cargo fmt; builds follow as potluck jobs.
2026-11-11 20:59:45 -08:00
Anees Iqbal 010958b7f8 Re-bless the golden tables at 43d2308170
What moved since d0f800ddd0's bless. Blessed on the M3 (dv-m3).
2026-11-11 20:49:13 -08:00
Anees Iqbal b0e379733d Re-bless the authored compile census at 43d2308170
Its product fingerprint follows the runtime-sources pin at 43d2308170 (dv-m3).
2026-11-11 20:49:12 -08:00
Anees Iqbal 2cf251fcee Re-pin the runtime sources at the landing tip
The landed packet changed a runtime-sources input, so the committed digest no

longer described the sources and `the_runtime_sources_are_the_committed_ones`

would fail. Recomputed over the same inputs and committed by land-pkt.sh.
2026-11-11 20:31:47 -08:00