Repository navigation
drm/asahi: g17: re-arm a vacated render pool at SUBMIT, not at publication - #3976
jgoyvaerts wants to merge 15 commits into
Conversation
The firmware objects of a G17 client's queues were kernel memory: counted
towards the device total (kernel_resident in gpu_memory) but owned by no
client, and owned by no memory cgroup when a kernel thread populated them.
Under a dq-fast timeline-cases load on an M4 Pro, kernel_resident peaked
at 2.4 GB.
This charges the objects that QUEUE_CREATE builds, the context's scheduler
storage and work state, to the client that creates the queue:
- **Driver accounting:** they count as the client's held memory (fdinfo
drm-resident-system, its limits) instead of kernel memory.
- **Memory cgroup:** their pages are charged to the client's memory
cgroup. That is the cgroup of the task that opened the DRM file, made
the active memory cgroup while the pages are populated.
- **Failure:** QUEUE_CREATE builds them in the client's ioctl, so a
failed allocation comes back from it as ENOMEM, which Borealis reports
as VK_ERROR_OUT_OF_HOST_MEMORY.
- **Lifetime:** the charge belongs to the object. It is released when the
object is freed, also after the client's file is gone while the
firmware still holds the object.
The rest of a queue's objects stay uncharged, as before: render pairs,
kick rings, generations, tiler heaps, compute state and timestamps. G17
builds them when a submission is published, after SUBMIT accepted it. A
memory cgroup at its limit would fail them there, and a failure there
costs the client its device: a test kernel with all of them charged lost
4 devices with ENOMEM when its cgroup filled.
- They are charged once they are built in QUEUE_CREATE or SUBMIT.
- The Allocator now names its client: QUEUE_CREATE's names it, the
publication paths say None.
- `KernelObject::queue_backing()` and `Allocator::backing()`/`object()`
are the way in for both.
Device-global objects stay uncharged kernel memory: the boot-time firmware
structures and heaps (initdata.rs, initdata/m5.rs), the crash buffer, the
PM metrics and the M5 metrics in mod.rs, and the shared compute pool.
Tests:
- **KUnit:** a queue charge is taken past both limits, counts against the
client's and the device's next objects, outlives the client's file and
is released once with its object. A memory-cgroup scope restores what
it replaced.
- **Host test** (g17-queue-object-charge-tests.py):
- only QUEUE_CREATE's Allocator names a client, and every other one
says None;
- uncharged kernel objects appear only in the global boot files and in
the three publication files that build objects outside an Allocator
(buffer.rs, buffer/target.rs, completion.rs);
- three injected faults are caught.
Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
A fresh G17 compute queue was built for the QID publication reserves: the pool's control header names the QID's pool slot, and the kick ring carries the QID. So its objects could only be allocated once the QID was known, at publication, after SUBMIT accepted the job. Only stores depend on the QID. Split construction in two: - **Allocate:** `compute::Kit::new` allocates the pool's control and state (`freelist::PoolObjects`), the kick ring storage (`kick::ComputeRing`) and the graph's objects (`GraphObjects`), with no QID. The pool pages and the descriptor ring are allocated as before. - **Bind:** `compute::Queue::new_channel(kit, pages, ring, id, ...)` binds them to the QID: `ComputePool::bind` writes the control header, `kick::Queue::compute` keeps the id and `Graph::new` writes the owner's queue record. No device memory is allocated. Publication still calls both, in the same order of effects: the pool's row is installed before the queue is built. A later change allocates in SUBMIT. tools/asahi/g17-compute-reserve-tests.py checks that the bind steps allocate nothing, with two mutations that inject an allocation. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
G17P's device-wide compute aperture (ComputeShared, 22 blocks of 1 MiB plus its lists) and compute scheduler were built by the first compute publication that needed them, on the scheduler's kworker, after SUBMIT had accepted the job. A refused allocation there failed the job, and the client lost its device. A compute SUBMIT now allocates them while they are neither installed nor prepared (`Backend::provision_compute`, from `ensure_compute`). A refusal is that SUBMIT's error. The publication that needs them takes the prepared object and installs it, as before; it allocates nothing, so its builder flags, the waits for another builder and the condition variable they waited on go. Installation keeps its timing: the aperture with the first publication's lease, the scheduler with the first fresh queue's pool row. Both stay device memory: they serve every client until processor stop. Allocated in a client's ioctl, their pages would be charged to that client's memory cgroup, so `memacct::device_memory` charges them to the root cgroup, as when the kworker allocated them. M5 has neither and allocates nothing. Tests: - g17-compute-constructor-tests now runs the production SUBMIT and publication halves (prepared once, a refusal fails the SUBMIT and prepares nothing, publication never builds and keeps the prepared object on cancel, a stale lease or a crash) with three mutations. - g17-admission-order-tests checks that every valid compute SUBMIT provisions and that a refusal fails it. - g17-m5-render-fast-done-tests checks that note_changed wakes render waiters only. - KUnit asahi_memacct: device_memory_is_charged_to_the_root_cgroup. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
A G17 compute queue's backing (the pool pages, at least 23 MiB on G17P, and the descriptor ring) and a fresh queue's kit were allocated when a command was published, on the scheduler's kworker, after SUBMIT had accepted it. A refusal there failed the job, and the client lost its device. With the backing charged to the client's memory cgroup, a client at its cgroup limit lost it that way. Each logical queue (owner) now has a reserve of compute backing: - **SUBMIT provisions.** A compute SUBMIT allocates what its publication would lack (`Backend::provision_backing`): pages that fit the command and a ring, unless the owner's spares or the queues holding its backing have them, and a kit while the owner has no queue of its own. Pages and ring are charged to the client through its Allocator; the kit is device memory (`memacct::device_memory`), since an installed queue outlives the owner. A refusal is that SUBMIT's ENOMEM or ENOSPC, before the command is queued. - **Publication takes.** Re-arming a vacant queue, building a fresh one (now in one device-mutex section with its install), growing a pool and adding an M5 sibling take from the owner's spares and allocate no device memory. A sibling that finds none asks the next SUBMIT for a set. - **Backing is the owner's until it closes.** A queue records whose backing it holds. When it gives the backing back (a pool release the firmware consumed, a grown pool's smaller pages, a recycled ring, a never-published queue's rollback), the pages and ring go back to that owner's spares, reset, while the owner has compute commands. Another open owner's backing is never bound: a queue holding it is given back first, as another VM's is. - **Claims.** Each compute command holds a claim on its owner from before its SUBMIT provisions until the command is dropped. An owner without claims is idle: what its queues give back is freed, and the pool pass frees its spares, so idle memory is what it was. Close frees the rest. A publication whose backing is on its way back waits as it waits for a channel today, and the event pass that observes the consumed release returns the backing and wakes it. That release is published by the pool pass and consumed by the firmware, whatever the waiting client does. Tests: - KUnit asahi_g17_compute_reserve: spares move without being freed, the smallest fitting pages are taken, a full owner frees only covered pages, and each spare is freed once. - g17-compute-reserve-tests: publication paths allocate nothing; SUBMIT charges pages and ring and allocates the kit as device memory; the claim precedes it and the command is queued after; every give-back keeps the backing for its owner; the production keep_backing, stock and trim_reserves free every spare exactly once; a queue-less owner always gets a kit. Six more mutations. - g17-queue-object-charge-tests: SUBMIT's compute backing is the second allocator that names the client; two more mutations. - Fixture updates for the changed functions in the g17 compute, growth, sibling and cleanup tests. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
Signed-off-by: DjDeveloperr <hey@djdev.me>
Signed-off-by: DjDeveloperr <hey@djdev.me>
Signed-off-by: DjDeveloperr <hey@djdev.me>
Main at 9b8e29f. Conflicts resolved keeping both sides: - Makefile: main's object list (g17/mesh_exclusion.o is gone) plus memcg_scope.o. - queue/compute.rs: main's new protections for the queue objects (records firmware-only, the lower-VA context and operand GPU+FW, the M5 timestamps) applied where this branch allocates them, GraphObjects::allocate(); main's removal of install_job_context_aliases() applied to map_binding(); main's pending_failed allocated before the pool row is installed. - runtime.rs: the compute growth path keeps main's unbound exit (no primary queue: EAGAIN, rebound by build_compute) around this branch's provisioned pages; DeferredBatch::is_idle() is main's pub(super) form with the object_pool check. - job.rs, queue/mod.rs: Packet takes main's batch_renders and producers and this branch's compute claim. - context.rs: both main's render_active helpers and compute_claimed(). - object.rs: main made a retained object's fence optional (None: kept until firmware stop); the reap of charged objects uses Retained::ready(). - g17-object-fence-tests: main() runs both client_pool_retirement() and cached_queue_lifetimes(); main's new test builds its Allocator with client: None. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Approving the code at 72acf636be97. This only changes NEO-layout (G17P) code, so the merge waits for a J700 row at this head (with the Neo lead) as well as the J714s row. The M5 path is unchanged.
What I checked:
- The new EIO in
build_render_pair()is reached only when the matching pair's pool is vacant. - On NEO,
pool_plan()isNone, so a context keeps one pool. That means a matching pair's pool is the same pool thatprovision_render_pool()re-arms at SUBMIT. provision_render_pool()takes the preparation lease, then the device lock (dropped before allocating), then the context's pool lock. That is the same order as the publication path.- The main merge gives the same tree as merging #3704 first and then this PR, so the shared commits resolve the same way.
Local checks, on current main 35ddf947 + #3704 + this PR (tree 13e3b683):
run-host-tests.py --only g17-in the host-tests container: 425/425 pass, includingg17-render-rearm-submit-testsand its mutations.- On main
a16156f8,drivers/gpu/drm/asahibuilt with no new W=1 warnings. - Hosted CI is green.
For landing: merge after #3704. The two don't conflict.
c2b6202 to
832fd07
Compare
On a NEO GPU every render pool, every compute pool and the small canonical objects of hardware queues share one lower dynamic range of the kernel lower VM: 1984 MiB on the M4 Pro, which uses the narrow split. A base render pool takes 46 MiB of it. Pools were placed first come, first served, and a pool vacated under pressure gave its addresses back, so a client whose pool had been vacated needed a fresh hole to re-arm it. On m4.230 a capped dEQP-VK load filled the range; reclaim_idle_render_pools() then handed the compositor's idle pool to a waiting client, and the compositor's next frame found no hole for its re-armed pool: its SUBMIT got ENOSPC and Hyprland aborted. One client's use of a device-wide range failed another client. Split the range once at boot (Uat::split_lower_window()). Windows (Uat::reserve_lower_window(), drm_mm nodes that map nothing) are placed lowest hole first from its start; the small canonical lower objects go to a band at its end, which only grows. Nothing is set aside for queues that do not exist yet: every reservation is made by the client that needs it, the first time it needs it, and kept until it goes. - The band starts with the objects bound to hardware queue identities, which stay with their QID until the firmware stops, past the queue that made them: the render pairs the QIDs allow, each with two kick rings and a current and a prepared graph; the 128 retired bindings; and the compute QIDs render leaves (kick::render_reserve()) with their kits. Its size depends on the QIDs, not on how many queues exist. Probe fails if not even one base render pool window fits beside it, and logs the split. - A computing owner takes its own budget of the band (its descriptor ring and spares, and a spare kit) at its first compute SUBMIT, in provision_backing(), before allocating them, and keeps it until it goes (Uat::reserve_lower_budget()). The band grows down only into space no window holds; a closed owner's budget stays in the band for the next. - A context reserves its render pool window, sized for its blocks (the base pool from the GPU's cores and clusters, or more after reserve_render_scs()), at its first render SUBMIT, before any command of that submission is queued. Only its pool places backing there, the first time and at every re-arm, so a context that has rendered never needs lower VA again, and no other client can take its window. The window goes back when the pool and every backing placed in it are gone. - A compute pool reserves a window of its own before any of its pages are allocated, in its client's SUBMIT, and gives it back with them. A refused window no longer costs a populated backing. - A refusal is the requesting client's own ENOSPC at its SUBMIT, when the range is used up or no hole of the size it needs is left; the capacity snapshot counts the latter (refused_fragmented) with the band's state. Queue admission and QUEUE_LIMITS keep the variant's limit. reclaim_idle_render_pools() existed to free shared lower VA for a waiting publisher; a vacated pool now frees none, so it and its trigger go. Vacating evicted clients' pools under memory pressure is unchanged. The compile-time check that WIDE_LOWER holds a base pool per execution context, which the narrow split never met, becomes a KUnit test of the split on both ranges. The capacity snapshot names each render context's owner pid and window size. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
…ation Under memory pressure, vacate_evicted_render_pools() gives back the render pool backing of a client whose VM pressure reclaim evicted while idle (b138b1c). On NEO, the next publication that needed the pool re-armed it with fresh backing, in the scheduler's worker. A worker has no memory cgroup, so those pages were charged to the root cgroup: a client's MemoryMax did not bound them, and the OOM killer and systemd-oomd could not see them in the client's cgroup. Evict, vacate and re-arm repeated under pressure, filling backing in the worker far faster than the vacated backing was freed. Re-arm in the client's SUBMIT instead. Queue::enqueue() calls the new Backend::provision_render() for every render command before it queues anything; on G17 it re-arms the context's pool if it is vacant, under client.charging() and with a preparation lease, so the pages go to the client's cgroup and a refusal (ENOMEM at the cgroup's limit) is this SUBMIT's. The backing goes in the context's own window of lower VA, so the re-arm takes no VA from other clients; while the vacated backing is still being unmapped from that window, the re-arm returns EAGAIN and libdrm retries. The command's VmJobGuard holds the VM's residency lease from before enqueue until the job is dropped. While a lease is held, pressure reclaim does not evict the VM and the residency gate does not report it evicted, so vacate_evicted_render_pools() cannot vacate the pool again before the job is published. Its other loop vacates only the pools of kept graphs, which are graphs of torn-down contexts. Publication (Context::render_pool(), build_render_pair()) therefore only takes the pool; a vacant one there is a broken invariant, logged once and failed with EIO, never re-armed in the worker. Unchanged: a context's first pool is still built at its first publication, and M5 pools are still armed by the pair that pins them. g17-render-rearm-submit-tests checks the SUBMIT call and its order, the charge and the lease check, and that publication no longer re-arms on NEO, with a mutation for each. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
The previous commit re-arms a vacated NEO render pool in the client's SUBMIT and lets publication only take it, trusting the command's residency lease to keep the pool armed in between. The lease only holds off vacate_evicted_render_pools(). On m4.230, before the pools had windows of their own, reclaim_idle_render_pools(), which checked only whether the owner was active, vacated a pool in that window: "render pool vacant at publication", and the clients behind it saw lost devices. That path is gone with the windows, but the invariant should not rest on which vacate paths exist and what each one checks. Make the hold explicit. SUBMIT takes a RenderClaim on the context's pool, counted under the pool's backing lock, before it checks whether the pool is vacant; the command's Packet holds it until the command is dropped. RenderPool::vacate() keeps the backing of a claimed pool, so no vacate path empties it before publication. The claim is counted under the same lock vacate checks it under: a vacate either finished first, and SUBMIT sees the pool vacant and re-arms it, or it leaves the pool alone. Context::rearm_render_pool and render_pool_vacant go away; the SUBMIT re-arms through the claim. The host test gains unclaimed-vacate, claim-unlocked and claim-dropped mutations. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
…eued A submission can carry several commands, and Queue::enqueue() queues them one by one. The re-arm of a vacated render pool ran in enqueue(), per render command, so a refusal (ENOMEM in the client's cgroup) for a render command came back after the submission's earlier commands were already queued: not a refusal that leaves the submission untouched, but a failure with failed fences on its outputs. Re-arm once per submission in Queue::submit(), right after the context's render window is reserved and before any command is queued, holding a RenderClaim until every command is. Each render command then takes its own claim on the armed pool in enqueue() (Backend::claim_render(), which cannot fail), and its packet holds that one until it is dropped. g17-render-rearm-submit-tests checks the re-arm in submit() before the first enqueue(), none in enqueue(), and a claim per render command, with the late-rearm and unclaimed-command mutations. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
832fd07 to
2529bca
Compare
|
@jgoyvaerts This branch now conflicts with
Note: this branch is stacked on Could you forward-merge |
Main at f02bd68. Conflicts resolved keeping both sides: - memacct.rs: main's ledger (reserve() with the reclaimable/unreclaimable split and their limits, release(), Commit::reclaimable, and its own private commit()) with this branch's commit for a client's queue objects, renamed Ledger::commit_queue() (object.rs calls it): they are committed whatever the limits, as before, and now also count as unreclaimable (idle reclaim never releases a queue's objects), with reclaimable: false so release() gives back both. Tests: main's new ones and this branch's queue-object, root-cgroup and charging-scope tests, side by side. - job.rs: Packet::new() is main's (the command moved in from the queue's pending entry, the footprint passed in, shared_inputs) with this branch's compute claim. - run-host-tests.py: main's idle-reclaim and held-ceiling tests and this branch's queue-object charge tests. - g17-m5-sibling-rearm-tests.py: resolved as in the previous merge (rerere). - g17-compute-reserve-tests.py: enqueue() borrows the command now (main): the checks and the claim-after-provision mutation follow (ensure_compute(command), main's entry.command.as_ref() line). Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
Brings aurora-silicon#3704's merge of main at f02bd68. Conflicts resolved keeping both sides: - g17/capacity.rs: main's M5 render template counters and this branch's lower_band line. - run-host-tests.py: main's idle-reclaim and held-ceiling tests and this branch's g17-lower-window-tests. - g17-lower-window-tests: its admission check accepts main's Pool::with_waiters_and_depth() (any constructor given the variant's queue limit). Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
Brings aurora-silicon#4348 and aurora-silicon#3704 up to main at f02bd68. Conflicts resolved keeping both sides: - job.rs: Packet::new() is main's (the command moved in, the footprint passed in, shared_inputs) with the compute claim and this branch's render claim. - queue/mod.rs: enqueue() borrows the command as main does; a render command still takes its claim on the armed pool (Backend::claim_render()), then main's query_access. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
What: Stacked on #4348 (D3, per-context lower-VA windows), which is stacked on #3704 (and #3683); review the top three commits (b83c328, 5b9b151, 2529bca). It depends on #4348: without the windows, a SUBMIT re-arm could take lower VA another client needs, and on m4.230 that made the compositor's own SUBMIT fail. The re-arm runs once per submission, right after #4348 reserves the context's window and before any of its commands is queued, so a refusal leaves the whole submission unqueued. On G17, a render pool that pressure reclaim gave back (
vacate_evicted_render_pools(), from b138b1c "drm/asahi: give back the render pool backing of evicted idle clients") is re-armed in the client's SUBMIT, under its memory cgroup, instead of at publication in the scheduler's worker. A refusal (ENOMEM at the cgroup's limit) is that SUBMIT's error, before the command is queued; the backing goes in the context's own window from #4348, so the re-arm takes no lower VA from anyone (a window still being vacated returns EAGAIN, which libdrm retries). The command holds a claim on the pool from SUBMIT until it is dropped, and no reclaim path vacates a claimed pool, so publication only takes it. This is D2 stage 3b for the render pool, the render counterpart of #3704's compute reserve.Tested: no Mac at this head yet (218308f, which brings main at f02bd68 through #3704's merge). KUnit (arm64 qemu) at 218308f: 1118 run, 1117 passed, 1 skipped, 0 failed (built with main's
asahi_g17_m5_pair_windowKUnit test patched locally: at main f02bd68 it still sets fields fb0d404 removed; #4382 fixes main). Host tests--only g17at 218308f: 460 of 460 pass. Before that merge, at 2529bca: KUnit 1066 run, 1065 passed, 1 skipped, 0 failed; host--only g17421 of 421 pass, including g17-render-rearm-submit-tests (10 mutations) and #4348's g17-lower-window-tests. Hardware, backport: M4 Pro (J616s), TEST kernel m4.235 = m4/private-232 + T142t-w: #4348 3ad4260 and #3976 b83c328 / 5b9b151 / 2529bca picked-xonto the private line, which already carries #3704's and #3683's commits as earlier backports (T142 series); hwrow7, 12-04 23:57-23:59 UTC, a capped dEQP-VK load (timeline-cases -j8 beside a compute-q4 -j2 loop, cage MemoryMax 25.8 GB, swap 0): PASS: 0 failures of any client outside the cage (a guard stopped the run at the first one; none came), 2298 SUBMIT refusals (ENOSPC), 0 lost devices, 0render pool vacant at publication, 0 recoveries, root-only shmem 0.54-1.80 GiB (13.95 GiB on m4.228 before #3976), cage peak 11.6 GiB; 42 fresh surfaceless GL clients (Mesa I62 = mesa#1647) refused at their first SUBMIT with 0 resets. This is a backport row, not a row at this PR's exact head. That load vacated no pool (0 vacates, 0 re-arms), so the re-arm at SUBMIT and the claim were not exercised by that load (hwrow9 below did): the row shows #4348's windows and that hwrow6's compositor crash is gone. Earlier, M4 Pro (J616s), m4.230, with 4b2eace only (no claim, no windows): failed. In a capped dEQP-VK run (cage 21.4 GB, swap 0), root-only shmem peaked at 1.69 GiB, down from 13.95 GiB, and refusals landed at SUBMIT, with 0 recoveries. Butreclaim_idle_render_pools()vacated a pool between its SUBMIT re-arm and its publication (lost devices; the claim commit fixes that, and #4348 removes that path), and the device-wide lower VA ran out, so the compositor's own render SUBMIT got ENOSPC and it aborted (#4348 fixes that). Hardware, backport (hwrow9): M4 Pro (J616s), TEST kernel m4.235 = m4/private-232 + T142t-w (#4348 3ad4260 and #3976 b83c328 / 5b9b151 / 2529bca picked-x), 12-05 01:21:45-01:26:46 UTC: a Vulkan client held 23 GiB of GPU memory and re-populated one 256 MiB chunk every 500 ms, so held memory stayed past the driver's idle-reclaim ceiling (26.2-26.4 GB against 24.98 GB) for 300 s, beside 6 vkmark clients cycled idle/active; the desktop's idle apps were exposed to the same eviction. PASS: at least 125 render pools vacated (all by the reclaim worker, no pool teardown among them) and at least 130 re-armed at SUBMIT, 128 in the test clients and 2 on the desktop (Xwayland, steamwebhelper); render packets dropped with their claim throughout; 0render pool vacant at publication, 0 refused SUBMITs of any client, 0 lost devices, 0 recoveries, root-only shmem 0.53-1.14 GiB. Vacate -> release: GEM release median 0.03 ms (p95 0.11, max 2.2) in the same worker, the pages freed (shmem inode eviction) median 1.8 ms (p95 3.0, max 4.6); re-arms came median 1.85 s after the latest vacate, none within 5 ms. The trace ring wrapped on 3 CPUs, so the counts are lower bounds. This is a backport row, not a row at this PR's exact head. This row exercised the re-arm at SUBMIT and the claim.Risk: two-way door · M4 Pro and other G17P (NEO layout) Macs. A render SUBMIT of a client whose pool was vacated now allocates the pool's backing itself: under a memory-capped cgroup it can fail with ENOMEM where the backing used to be charged to the root cgroup. M5 is unchanged.
Not yet:
prepare_pool_backing), at publication.dma_fence_begin_signalling()/lockdep) for the publication path: stage 3e.cache_reclaimed()does), only where that keeps the vacate's purpose.Details
Before.
vacate_evicted_render_pools()vacates the pool of a client VM that pressure reclaim evicted while idle and hands the backing to the worker's DeferredBatch. On NEO,RenderPool::ensure_backing()gave a vacant pool fresh backing at its next use: inContext::render_pool()and inbuild_render_pair()'s matching-pair branch, both reached fromdrm_sched_run_job_work→Backend::publish→render_with_lease→ensure_render. Under pressure that repeated: evict, vacate, re-arm in the worker, free later.Now.
Queue::submit()calls the newBackend::provision_render()once for a submission with render commands, after drm/asahi: g17: give each render pool its own window of lower VA #4348's window reservation and before any command is queued, and holds theRenderClaimit returns until all are;Queue::enqueue()gives each render command its own claim (Backend::claim_render(), which cannot fail) for itsPacket. Other backends keep the defaults (no claim).provision_render_pool()(NEO only) claims the context's pool (RenderPool::claim()), then returns unless the pool is vacant. Otherwise it enters a preparation lease (recovery joins it before replacing the firmware whose VMs the backing maps into), takes the build resources under the device lock if the lease is current (EAGAIN otherwise; libdrm retries), and re-arms the claimed pool insideclient.charging().Context::render_pool()andbuild_render_pair()no longer callensure_backing()on NEO. A vacant pool there is logged once and fails with EIO.Why a pool re-armed at SUBMIT is still armed at publication. The command holds a
RenderClaimon its pool from SUBMIT until it is dropped (retired, cancelled or refused), andRenderPool::vacate()keeps the backing of a claimed pool, whichever path calls it.claim()counts under the backing lock thatvacate()checks under, so a vacate either finished before the claim (SUBMIT then sees the pool vacant and re-arms it) or leaves it alone. With #4348 the only vacate paths left arevacate_evicted_render_pools()(which the command's residency lease already holds off) and kept graphs' pools; the claim makes the invariant hold regardless. On m4.230, without either,reclaim_idle_render_pools()vacated a pool in that window. The EIO at publication is therefore a broken invariant, not a load case.No deadlock, and out of the fence path. The re-arm runs in the client's ioctl, holding its queue lock and a preparation lease, in the same order
build_render_pair()takes them (preparation lease, then the device lock, then the context's pool lock). It waits on nothing the GPU must signal. Before,RenderBacking::new()→drm_gem_get_pages()→shmem_read_folio_gfp()ran indrm_sched_run_job_work, inside the dma-fence signalling path: under reclaim that allocation could wait on a shrinker that waits on a fence this very job must signal. The re-arm is no longer on that path.Evidence
Hardware, backport (hwrow9): M4 Pro (J616s), TEST kernel m4.235 = m4/private-232 + T142t-w (drm/asahi: g17: give each render pool its own window of lower VA #4348 3ad4260 and drm/asahi: g17: re-arm a vacated render pool at SUBMIT, not at publication #3976 b83c328 / 5b9b151 / 2529bca picked
-x), 12-05 01:21:45-01:26:46 UTC: a Vulkan client held 23 GiB of GPU memory and re-populated one 256 MiB chunk every 500 ms, so held memory stayed past the driver's idle-reclaim ceiling (26.2-26.4 GB against 24.98 GB) for 300 s, beside 6 vkmark clients cycled idle/active; the desktop's idle apps were exposed to the same eviction. PASS: at least 125 render pools vacated (all by the reclaim worker, no pool teardown among them) and at least 130 re-armed at SUBMIT, 128 in the test clients and 2 on the desktop (Xwayland, steamwebhelper); render packets dropped with their claim throughout; 0render pool vacant at publication, 0 refused SUBMITs of any client, 0 lost devices, 0 recoveries, root-only shmem 0.53-1.14 GiB. Vacate -> release: GEM release median 0.03 ms (p95 0.11, max 2.2) in the same worker, the pages freed (shmem inode eviction) median 1.8 ms (p95 3.0, max 4.6); re-arms came median 1.85 s after the latest vacate, none within 5 ms. The trace ring wrapped on 3 CPUs, so the counts are lower bounds. This is a backport row, not a row at this PR's exact head.Hardware, backport (hwrow7): M4 Pro (J616s), TEST kernel m4.235 = m4/private-232 + T142t-w: drm/asahi: g17: give each render pool its own window of lower VA #4348 3ad4260 and drm/asahi: g17: re-arm a vacated render pool at SUBMIT, not at publication #3976 b83c328 / 5b9b151 / 2529bca picked
-xonto the private line, which already carries drm/asahi: g17: allocate compute objects in SUBMIT, not at publication #3704's and drm/asahi: g17: charge a client's queue context to that client #3683's commits as earlier backports (T142 series); hwrow7, 12-04 23:57-23:59 UTC, a capped dEQP-VK load (timeline-cases -j8 beside a compute-q4 -j2 loop, cage MemoryMax 25.8 GB, swap 0): PASS: 0 failures of any client outside the cage (a guard stopped the run at the first one; none came), 2298 SUBMIT refusals (ENOSPC), 0 lost devices, 0render pool vacant at publication, 0 recoveries, root-only shmem 0.54-1.80 GiB (13.95 GiB on m4.228 before drm/asahi: g17: re-arm a vacated render pool at SUBMIT, not at publication #3976), cage peak 11.6 GiB; 42 fresh surfaceless GL clients (Mesa I62 = mesa#1647) refused at their first SUBMIT with 0 resets. This is a backport row, not a row at this PR's exact head.g17-render-rearm-submit-tests:enqueue()re-arms for render commands before it queues; the re-arm is charged to the client and checks its preparation lease;Context::render_pool()andbuild_render_pair()no longer re-arm; the remainingensure_backing()callers are M5 paths. the command's packet holds the claim;vacate()keeps a claimed pool andclaim()counts under the backing lock. Mutationsno-submit-rearm,late-rearm,uncharged-rearm,no-lease-check,publication-rearms,pair-rearms,unclaimed-vacate,claim-unlocked,claim-droppedmust be caught, and are.m4.230 (J616s, 4b2eace without the claim), capped dEQP-VK: one
render pool vacant at publication: not re-armed at SUBMIT, followed 47 us later by the first lost device; LowerVa capacity refusals mostly atobject.rs:522(lower_with_aliases(), the render pool backing).Before this change, on an M4 Pro (J616s) test kernel with drm/asahi: g17: allocate compute objects in SUBMIT, not at publication #3704, a capped dEQP-VK run with a kprobe on
charge_memcgfiltered to the root memory cgroup (validated with a write from a process placed in the root cgroup and two from user units): root-only shmem reached 13.95 GiB while the driver's held kernel objects stayed at 1.3-1.85 GiB. 11054 of the kernel-worker stacks weredrm_sched_run_job_work→Backend::publish→render_with_lease→ensure_render→build_render_pair→RenderPool::ensure_backing→RenderBacking::new→drm_gem_get_pages.