Skip to content

drm/asahi: g17: give each render pool its own window of lower VA - #4348

Open
jgoyvaerts wants to merge 11 commits into
aurora-silicon:mainfrom
jgoyvaerts:m4pro/g17-lower-va-reserve
Open

jgoyvaerts wants to merge 11 commits into
aurora-silicon:mainfrom
jgoyvaerts:m4pro/g17-lower-va-reserve

Conversation

@jgoyvaerts

@jgoyvaerts jgoyvaerts commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

What: Stacked on #3704 (and #3683); review only the top commit. On G17 NEO GPUs, a context reserves a window of the kernel's lower dynamic range for its render pool at its first render SUBMIT, before any command of that submission is queued, and keeps it until it goes. Every backing of that pool, the first one and each one re-armed after a pressure vacate, is placed there, so a context that has rendered never needs lower VA again and no other client can take its window. When the range is really full, the refusal is the new renderer's own ENOSPC at that SUBMIT, never a publication or another client's SUBMIT. Compute pools reserve a window of their own before any page is allocated. The small canonical lower objects go to a band at the end of the range: the objects bound to hardware queue identities (sized by the QIDs, not by how many queues exist) from boot, and each computing owner's own budget from its first compute SUBMIT. Nothing is set aside for queues that don't exist; every refusal is real exhaustion of what the requesting client needs, at its own SUBMIT. Queue admission and QUEUE_LIMITS are unchanged. This is D3 (owner's decisions: 11-30 "LowerVa per pair, with the pool size from a hardware property"; 12-04 "D3 first, reclaim later" and "reserve on first use, keep it": no count derived from windows, refuse only on real exhaustion, applied to the small objects too).

Tested: no Mac at this head yet (ac1359e, which brings main at f02bd68 through #3704's merge). KUnit (arm64 qemu) at ac1359e: 1118 run, 1117 passed, 1 skipped, 0 failed (built with main's asahi_g17_m5_pair_window KUnit test patched locally: at main f02bd68 it still sets fields fb0d404 removed; #4382 fixes main). Host tests --only g17 at ac1359e: 449 of 449 pass. Before that merge, at 3ad4260: KUnit 1066 run, 1065 passed, 1 skipped, 0 failed; host --only g17 410 of 410 pass, including g17-lower-window-tests and its 14 mutations. Hardware, backport: M4 Pro (J616s), TEST kernel m4.235 = m4/private-232 + T142t-w: #4348 3ad4260 and #3976 b83c328 / 5b9b151 / 2529bca picked -x onto 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, 0 render 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. On m4.235 the probe logged lower VA: 1984 MiB, 151 MiB for queue-identity objects, room for 39 base render pool windows (2624 KiB less per computing owner) as computed. 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; 0 render 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.

Risk: two-way door · M4 Pro (narrow split) and other G17 NEO Macs (wide split); M5 unchanged. A context's first render SUBMIT can now fail with ENOSPC when the range is full (before: the failure came at publication, or hit whichever client re-armed next). Vacated render pools keep their window (VA only, not memory). The queue-identity band takes 118 MiB of the M4 Pro's 1984 MiB at boot (QID floor 32; 151 MiB at floor 0), leaving room for 40 (39) base render windows before any owner computes; each computing owner then takes 2.6 MiB of the band; a queue that never renders takes no render window.

Not yet:

  • Hardware, exact head: the capped dEQP-VK row with drm/asahi: g17: re-arm a vacated render pool at SUBMIT, not at publication #3976 at these heads (the PASS above is a backport row).
  • Contiguity (reclaim-stage decision): windows need a contiguous hole, and compute windows differ in size from render windows. In the backport row 2189 of 2266 window refusals were refused_fragmented (enough bytes free below the band, no hole of the requested size). Both refusals land only on new requesters. The real fixes (one window size class, or discontiguous pool backing) are to be weighed with the reclaim stage on this data.
  • Band high-water (reclaim stage): the band never shrinks; a closed owner's budget stays in it for the next. In the backport row it grew from 170 MB to 242.5 MB with 59 MB spare at the end, unavailable to windows.
  • Retired unwritten render kick-ring storage: written rings are counted (a ring that committed an entry stays with its published QID until both firmware processors stop: at most 2 x 63, about 16 MiB at QID floor 0, about 12 MiB at floor 32); storage of a pair reclaimed before it published is handed only to the same VM or a closed one (RenderRings::take, 1d478ee), so that stock is not counted (shortcut: in split_lower). Pending drm/asahi: g17: give each render pool its own window of lower VA #4348 (comment).
  • Mesa (merge order): a first-SUBMIT ENOSPC is a normal path for a new renderer while the range is full: Borealis needs mesa#1421 and gallium asahi mesa#1647 before this goes into a daily kernel.
  • New renderers when the range is full: contexts that have rendered or computed are never refused for lower VA, but a new app or a compositor's new context (hotplug, screencast) is refused at its first SUBMIT while the range is really full. Reclaiming idle clients' windows is the next stage.
Details

Follow-ups (not blocking):

  • Split choice: UatQuirks::narrow_pool_window is still a per-SoC quirk; this sizes from whatever range it picks (the live kernel_lower_dynamic_range()), and moving the quirk onto a hardware property is a follow-up.
  • Per-cgroup readout: the capacity snapshot names each render context's pid and window; a table of every window per client and cgroup comes with the reclaim stage.

Before. All lower objects were placed best-fit over one range (1984 MiB narrow, 3264 MiB wide). A base render pool takes 46 MiB, a compute pool 24-65 MiB. A pool vacated under pressure gave its addresses back, and reclaim_idle_render_pools() vacated idle owners' pools so a waiting publisher could place one. On m4.230, with #3976's SUBMIT re-arm, a capped dEQP-VK load filled the range, Hyprland's idle pool was handed out, Hyprland's next frame got ENOSPC from SUBMIT, and the compositor aborted.

Now.

  • Uat::split_lower_window() (once, at G17 NEO boot) sets up one ledger over the range: windows (Uat::reserve_lower_window(), drm_mm nodes of their own allocator that map nothing) are placed lowest hole first, below the band's floor only; the small objects go to the band above it (kernel_lower_misc_range()).
  • freelist::split_lower() sizes the band's boot part as the bound of the objects that stay with hardware queue identities until the firmware stops: render pairs from the QIDs (two kick rings and a current and a prepared graph each), the 128 retired bindings, and the compute QIDs kick::render_reserve() leaves (with their kits). Probe fails if not even one base render window (TABLE_SIZE + render_rt::base_blocks(active_cores, clusters) x 1 MiB + guard, from G17Id) fits beside it, and logs the split.
  • A computing owner takes its budget (freelist::owner_lower_bytes(): its descriptor ring and spares, and a spare kit) in provision_backing() at its first compute SUBMIT, before allocating them (Context::reserve_compute_budget(), Uat::reserve_lower_budget()). The band grows down for it only into space no window holds; a budget given back by a closed owner stays in the band for the next. OwnerReserve drops its context after its spares, so the budget outlives them.
  • Queue::submit() asks Backend::reserve_render_window() once for a submission with render commands, right after reserving the frontier room and before queueing any: a context without a window reserves one for its render_blocks (Context::reserve_render_window()), a context with one keeps it (checked without the device mutex). reserve_render_blocks() (QUEUE_CREATE's scratch sizing) refuses once the window exists, so a pool never outgrows it.
  • RenderPool and every RenderBacking hold the window (Arc), so it goes back only after the context, the pool and every backing placed in it, also a vacated one still in a deferred batch, are gone.
  • Pages::new() (compute) reserves its window first, then allocates and maps the backing inside it; the refused-size throttle (place_lower) now gates the reservation, which costs no pages.
  • The compute kick ring, operand and context lows, the compute descriptor ring alias, the render kick ring alias and the render descriptor aliases move to the small part.
  • reclaim_idle_render_pools() and lower_window_short() are removed: vacating a pool no longer frees VA for anyone else. Vacating evicted clients' pools under memory pressure is unchanged.
  • The compile-time check that WIDE_LOWER holds a base pool for every execution context (never true for the narrow split) is replaced by the probe-time split and a KUnit test of both splits.
  • Render kick rings in the small part: a written ring is never dropped or reused while the firmware runs (its QID stays installed with it), so the live pairs bound them; retired never-written storage tied to an open VM is the one term not counted (see Not yet).
  • Capacity snapshot: lower_band bytes= spare= window_bytes= refused_fragmented=, and context scope=render ... pid=<owner> lower_window=<bytes> (0 before the first render).

Room (KUnit): narrow split, QID floor 32: 118 MiB band, 40 base windows; floor 0: 151 MiB, 39; wide, 6-core one-cluster: 67; wide, 40-core four-cluster (128 MB windows): 25. On a real desktop (m4.230, 12-04 17:59 UTC, the owner gaming plus chromium, slack, T3: 14 render contexts, 10 computing owners with compute pools) this uses about 1168 MB of 2080 on main (1203 MB at floor 0), leaving room for about 18 more render-only contexts.

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; 0 render 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. Run data: hwrow9/run-20261205T012145Z (lag.txt, probes-lag.txt, capacity snapshots, kernel window).

  • 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 -x onto 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, 0 render 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. The ledger under that load: band 170.0 -> 242.5 MB, window bytes up to 1788.6 MB, LowerVa refusals 2266 of which 2189 refused_fragmented; vacate->release lag not measured (0 re-arms). Run data: hwrow7/run-20261204T235753Z (capacity snapshots every 2 s, GL probe log, kernel window).

  • lower_split_keeps_room_for_windows (KUnit): the four shapes above; each keeps room for its windows beside the band and no more, a range without room for one window refuses the probe, and an M4 Pro owner budget is 2,686,976 bytes.

  • g17-lower-window-tests (host): boot splits; admission and QUEUE_LIMITS keep the variant's limit; QUEUE_CREATE reserves nothing; the first render SUBMIT reserves before the first enqueue(), never per command; a held window is never replaced and the pool size cannot change after it; render backings are placed only in their pool's window and keep it; compute pools reserve before allocating; small objects never use the whole range. No window is placed in the band, the band never grows over a window, QUEUE_CREATE reserves nothing, an owner's budget is taken only before its first compute objects and never replaced. Mutations submit-unreserved, late-reserve, window-replaced, blocks-after-window, count-cap, rearm-anywhere, pool-drops-window, pages-before-window, misc-in-pools, window-in-band, band-over-window, create-reserves, unbudgeted-owner, budget-replaced must be caught, and are.

  • m4.230 hwrow6 (12-04, drm/asahi: g17: re-arm a vacated render pool at SUBMIT, not at publication #3976 without this): G17 capacity refusal LowerVa up to count 128 at object.rs:522; Hyprland's DRM_IOCTL_ASAHI_SUBMIT render failed: No space left on device, then Hyprland has crashed.

jgoyvaerts and others added 8 commits November 30, 2026 12:41
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>
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>
@jgoyvaerts

Copy link
Copy Markdown
Contributor Author

@DjDeveloperr a question on RenderRings::take() (from 1d478ee): retired storage of a never-written ring goes only to the same VM or to a VM whose client closed. Since then Queue::render says the pair drops its client views before the ring, so retired storage has no view in any VM. Is the open-VM restriction still needed, or could unwritten retired storage go to any VM (with prepare_alias refusing a VM that still has a view)? We are bounding the lower-VA budget and want to know whether that stock can grow with the number of open VMs.

@jgoyvaerts
jgoyvaerts force-pushed the m4pro/g17-lower-va-reserve branch from 20bdac4 to 1e53e11 Compare December 4, 2026 19:43
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>
@jgoyvaerts
jgoyvaerts force-pushed the m4pro/g17-lower-va-reserve branch from 1e53e11 to 3ad4260 Compare December 4, 2026 19:58
@jgoyvaerts
jgoyvaerts marked this pull request as ready for review December 5, 2026 00:03
@jgoyvaerts
jgoyvaerts requested review from a team and DjDeveloperr as code owners December 5, 2026 00:03
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:m4 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) blast:neo Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 5, 2026
@github-actions

github-actions Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

Merge readiness at ac1359e9: not ready yet

Check Detail
CI at head no failing: host-tests
Review no needs one approving review from Core, Omarchy Mac or Aurora Maintainers (not the author)
Requested changes ok none
Hardware row at head no no line with the head SHA ac1359e9, a Mac and a result in the PR body or a comment
Conflicts no merge conflicts with main: merge it in (no force push)
PR text ok Risk: two-way · M4 Pro (narrow split) and other G17 NEO Macs (wide split); M5 unchanged. A context's first render SUBMIT can now fail with ENOSPC when the range is full (before: the failure came at publication, or hit whichever client re-armed next). Vacated render pools keep their window (VA only, not memory). The queue-identity band takes 118 MiB of the M4 Pro's 1984 MiB at boot (QID floor 32; 151 MiB at floor 0), leaving room for 40 (39) base render windows before any owner computes; each computing owner then takes 2.6 MiB of the band; a queue that never renders takes no render window.

Areas: area:gpu

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@github-actions github-actions Bot added the merge-conflict Conflicts with the base branch (bot) label Dec 5, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

@jgoyvaerts This branch now conflicts with main (1da341136110) in:

  • drivers/gpu/drm/asahi/g17/capacity.rs
  • drivers/gpu/drm/asahi/g17/job.rs
  • drivers/gpu/drm/asahi/memacct.rs
  • tools/asahi/g17-m5-sibling-rearm-tests.py
  • tools/asahi/run-host-tests.py

Note: this branch is stacked on #3704 and shares its conflict files plus drivers/gpu/drm/asahi/g17/capacity.rs.

Could you forward-merge main into this branch (normal git merge, no rebase/force-push)? If you haven't had a chance within 24 hours, a maintainer can forward-merge main on top for you.

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>
jgoyvaerts added a commit to jgoyvaerts/linux that referenced this pull request Dec 5, 2026
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>
@jgoyvaerts

Copy link
Copy Markdown
Contributor Author

Merged main (f02bd68) up the stack: #3704 e437e7a, #4348 ac1359e, #3976 218308f.

@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) needs-hw-row No hardware row at the PR head (bot) merge-conflict Conflicts with the base branch (bot) and removed merge-conflict Conflicts with the base branch (bot) ci-failing A check failed at the PR head (bot) labels Dec 5, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpu Area from CODEOWNERS (bot) blast:m4 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) blast:neo Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) merge-conflict Conflicts with the base branch (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants