Repository navigation
drm/asahi: g17: allocate compute objects in SUBMIT, not at publication - #3704
jgoyvaerts wants to merge 9 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>
9a9efbe to
c769558
Compare
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>
c769558 to
2c8dfe7
Compare
Signed-off-by: DjDeveloperr <hey@djdev.me>
Signed-off-by: DjDeveloperr <hey@djdev.me>
Signed-off-by: DjDeveloperr <hey@djdev.me>
|
Fixed compute backing ownership, channel rollback and concurrent shared-aperture allocation in 936c70c. |
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>
Main at 9b8e29f. Conflicts resolved keeping both sides: - Makefile: main's object list (g17/mesh_exclusion.o is gone) plus memcg_scope.o. - As in the merge of main into aurora-silicon#3704's branch for queue/compute.rs, runtime.rs, job.rs, queue/mod.rs and context.rs. - 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 e005b68b1d46. I'll merge after the J714s and J700 rows pass at this head.
What I read: everything this merges into main. Because #3683 is still a draft, that includes its two commits (2dc7fb52d56d, da65b3f1562c), plus the four commits here and the main merge.
7ff8f5a44062only moves the allocations ahead of the QID reservation. Binding to the QID is stores only.- The reserve in
2c8dfe7aa8acmatches the description:- The claim is taken before
ensure_compute()provisions the backing. keep_backing()only keeps backing while the owner still holds a claim.close_reserve()untags the owner's queues and frees its spares after the device mutex is dropped.- An owner that gets no reserve slot fails its SUBMIT with ENOSPC. It never queues a command that has no backing.
- The claim is taken before
- The main merge in
e005b68b1d46resolves all 7 files correctly:- The Makefile drops
mesh_exclusion.o, as main did. GraphObjectstakes main'slowerand FW-shared timestamp protections.- Dropping
install_job_context_aliases()matches main's 969bbd2. reap_deferred()uses main'sentry.ready().
- The Makefile drops
Local checks, on current main 35ddf947 (after #4020 and #4258 landed):
- This PR and then #3976 merge cleanly (tree
13e3b683; merging #3976 alone gives the same tree). run-host-tests.py --only g17-in the host-tests container: 425/425 pass.- Built on main
a16156f8, before those two landed:aurora.kobuilds, and W=1 ofdrivers/gpu/drm/asahiadds no warnings (43 on main, 43 here). - Hosted CI is green at this head.
For landing:
- The readiness bot reads "no Mac at this head yet (e005b68...)" in the description as a hardware row. It isn't one. The rows are still owed: J714s (kit with the M5 lead) and J700 (with the Neo lead). Both test the driver of all three PRs on main
35ddf947. - Merge order: this PR, then #3976 (clean), then #3956. #3956 conflicts with this PR only in
tools/asahi/g17-queue-object-charge-tests.pyandrun-host-tests.py. The forward merge has to keep both sides' checks: the allocator list{Backend::new, provision_backing}, theclient_backing()→charged()check, and all seven mutations.
Withdrawn: this head loses the device on the M5 at boot (ENODEV from install_compute_shared). Cause and fix in the comment below.
|
J714s (M5 Pro) row: this head loses the device at boot, so this PR shouldn't merge as it is. I've withdrawn my approval. Setup. Base and head boot the same kernel, and only
Cause: my commit
Fix: put main's test back in those three places: fn shared_compute(&self, admission: &Admission<'_>) -> Result {
- if !self.shared.variant.compute.needs_shared_aperture() {
+ if self.context.is_m5() {
return Ok(());
}
@@
- if self.shared.variant.compute.needs_shared_aperture() && !firmware.init.has_compute_scheduler() {
+ if !self.context.is_m5() && !firmware.init.has_compute_scheduler() {
@@
fn provision_shared(&self) -> Result {
- if !self.shared.variant.compute.needs_shared_aperture() {
+ if self.context.is_m5() {
return Ok(());
}Two notes on the fix:
The commit is on your branch, so the change is yours to make. If you'd rather I push it, say so. #3976 carries the same commit, so it is held too. #3956 is not involved. I'll re-cut the J714s and J700 rows at the new heads. |
|
@jgoyvaerts This branch now conflicts with
Note: this branch carries 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#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>
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>
What: Stacked on #3683; review only the top three commits. On G17, compute publication no longer allocates. A compute SUBMIT allocates what its publication would need, and a refusal is that SUBMIT's ENOMEM or ENOSPC, before the command is queued. Before, a refusal at publication (the scheduler's kworker, after SUBMIT returned) failed the job, and the client lost its device.
Tested: no Mac at this head yet (e437e7a, which merges main at f02bd68). KUnit (arm64 qemu) at e437e7a: 1117 run, 1116 passed, 1 skipped, 0 failed (built with main's
asahi_g17_m5_pair_windowKUnit test patched locally: at f02bd68 it still setsValidated::Render { attachments, timestamps }, which fb0d404 removed, so main's KUnit build fails on its own; #4382 fixes main). Host tests at e437e7a:--only g17435 of 435 pass;--only asahi-20 of 21 (asahi-m4's test-stream-gate fails to link on this host,__stack_chk_guard, as before the merge). Earlier, at e005b68 (main at 9b8e29f): KUnit 1065 run, 1064 passed, 1 skipped; host--only g17-396 of 396. Before the merge: A partial hardware run on an M4 Pro (J616s) at 2c8dfe7, before the two newest commits: see Evidence. KUnit (arm64 qemu) at 2c8dfe7: with CONFIG_MEMCG=y 955 run, 954 passed, 1 skipped, 0 failed; g17-compute-reserve host test and its 8 mutations pass. 2c8dfe7 differs from c769558 only in buildingSpares::is_emptyandtake_allfor KUnit alone (a non-KUnit build warned they were unused); at c769558, with drivers/gpu/drm/asahi/.kunitconfig (no memory cgroups) 521 run, 517 passed, 4 skipped. Host tests at 9a9efbe (this head but for one KUnit assertion): 845 runs pass; the 29 that fail also fail at #3683's head (apple-dcp, test-m3-uapi, g15-pb-growth x2, g15-retention --mutations, g15-stats-drain x2, sep-suspend-errors x22). Hardware, backport (partial for this PR): 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. Its compute side ran 9 compute-q4 passes at -j2 with compute provisioned at SUBMIT and 0 lost devices; the cage stayed below its limit (11.6 of 25.8 GB), so the reserve at the cgroup limit is still to run.Risk: two-way door · M4 and M5 (G17). Every Mac running the driver: compute publication paths change. A compute owner that has commands keeps its backing, at least 23 MiB of pool pages on G17P, while they are pending. Idle owners hold what they held before.
Not yet:
Details
Where compute publication allocated (main), and where it moved:
Pages::for_compute), descriptor ringrearm_vacant,build_compute,try_add_compute_sibling,grow_computeBackend::provision_backing, charged to the clientcompute::Kit)PoolBacking::new,Backing::new,Queue::newQID split (commit 1). Only stores depend on the QID: the pool control header's buffer slot (
ComputePool::bind), the kick ring's id (kick::Queue::compute), and the owner's queue record (Graph::new).Kit::newallocates without a QID.Device memory. Objects that outlive the client that caused them (the kit, the shared aperture and scheduler) are allocated in the client's ioctl. So that their pages are not charged to that client's memory cgroup, they are allocated under
memacct::device_memory, which makes the root cgroup the active one. That matches what happened when the kworker allocated them.The reserve (commit 3).
Registry::compute_lackschecks whether the owner's spares, or the queues holding its backing (also while they give it back), have pages that fit the command and a ring. If not, SUBMIT allocates them. An owner without a queue of its own also gets a kit.backing_owner). When it gives the backing back, the pages and ring return to that owner's spares, reset and cleared, while the owner has compute commands. A backing comes back from:No deadlock: why a publication waiting for its backing always gets it.
Rebind::Done), or growth takes the queue's pages after draining its siblings;bind_reusablebinds it, or growth asks the queue to give it back (recall_backing);vacate_idle_poolsforces queues marked for fresh backing).keep_backing) and wakes channel and progress waiters.wait_channels,wait_release).So the wait does not depend on its own client: not on a fence the client waits for, nor on a later SUBMIT. A kill or a cancel ends it through the admission check. During recovery, the admission is extended as for every other publication wait. The 30 s admission deadline still bounds it, as it bounds every publication wait.
Evidence
Hardware, backport (hwrow7, partial for this PR): 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.KUnit
asahi_g17_compute_reserve(4 cases): spares move without being freed; the smallest fitting pages are taken; a full owner frees only covered pages; each spare is freed once.KUnit
asahi_memacct:device_memory_is_charged_to_the_root_cgroup.Host tests, red at drm/asahi: g17: charge a client's queue context to that client #3683's head and green here, each with mutations that inject the fault and must be caught:
g17-compute-reserve-tests:keep_backing,stockandtrim_reservesfree every spare exactly once, also when the owner closes with its reserve unused.Mutations: 7.
g17-compute-constructor-tests: SUBMIT prepares the shared objects once as device memory, and a refusal fails it. Publication never builds them, and keeps them on cancel, a stale lease or a crash. Mutations: 3.g17-admission-order-tests: every valid compute SUBMIT provisions, and a refusal fails it.g17-queue-object-charge-tests: exactly QUEUE_CREATE's context and SUBMIT's compute backing name the client. Mutations: 2 new.Fixtures updated for the changed functions: the g17 compute growth, retired, growth, uninstalled cleanup, M5 sibling compute, gate and rearm, object fence and render fast-done tests.
Hardware, partial (containment and a clean run; the reserve under memory pressure did not run): M4 Pro (J616s), the commits up to 2c8dfe7 backported onto a test kernel (not da65b3f or 936c70c), 2026-12-02. dEQP-VK timeline-semaphore cases at 10 jobs with the system Borealis, in a MemoryMax cgroup of 12.99 GB without swap. The cgroup reached its limit 2.5 s in and stayed there about 10 s, until a memcg OOM kill. The kill came from an ordinary GFP_NOFS allocation, and its victim was a deqp-vk with 1.89 GB shmem-rss. systemd then stopped the run, 13 s in. The compute list never started, and no SUBMIT was refused.