Repository navigation
drm/asahi: g17: cut allocations and copies in the submit path - #2228
Conversation
Every publication allocated a DeferredBatch with room for two rings of completions (64 entries, about 3.5 KB through kvmalloc) and freed it when the publication ended: on the direct compute and render paths this was a kvmalloc and a kvfree in every submit ioctl. The backend now keeps the batch of its last publication once it is finished and lends it to the next one. A batch that still holds work is dropped as before, and concurrent publishers of one queue (the two engines' scheduler workers and the ioctl) each get their own: the first one back is kept. The batches are created and used exactly as before. Signed-off-by: Jonathan Goyvaerts <[email protected]>
954fc9b to
1c33065
Compare
|
Commit messages only, for the pre-PR checklist: the commits no longer carry Assisted-by: LLM (Claude:Opus 5.5) |
|
Looks good; approve once the HW row below is in. I checked the three changes. PublicationBatch (drivers/gpu/drm/asahi/g17/runtime.rs:917-925, 1586-1597) takes the spare before allocating, so nothing is allocated under the mutex. It returns a batch only when is_idle() holds, after finish() has drained every vector and cleared has_source_completions, and it is dropped at the end of each publisher with no other lock held. No path replaces a lent batch's vectors, so the room checks (render/tvb/vacated) behave as before. In queue/mod.rs the scratch vectors are taken out of the queue for the ioctl and cleared before
HW row: one more G17 Mac other than the J616s (M4 or M5) on a kernel with only these commits on top of integration/aurora: gpubench compute/render rows plus a deqp-vk subset with no new failures and 0 GPU recoveries, and a regression row on the J616s (0 SELinux denials, 0 failed units, 0 new kernel errors). Assisted-by: LLM (Claude:Opus 5.5) |
|
I tried the nit and left the code as it is; the head stays With the arm64 The J616s regression row will follow the next kernel build of our tree. We'd take your offer to run the other G17 Mac row (M4 or M5) in your lab. Assisted-by: LLM (Claude:Opus 5.5) |
There was a problem hiding this comment.
Adversarial review at 1c3306581218 against the pre-PR checklist.
No code, CI, attribution, or policy blockers found:
- CI & Attribution/Policy (§1–§4, §6):
host-testsis green on1c3306581218; all three commits carry human author/committer and humanSigned-off-by:only; PR body disclosure is clean; no model gating or naming issues. - PublicationBatch reuse (
drivers/gpu/drm/asahi/g17/runtime.rs:917-925, 1429-1436, 1571-1597):spare_batchis a leaf mutex never held across allocation (DeferredBatch::publication()?),kvfree(when a competing batch drops because*spareis already populated, the guard drops beforebatch), orshared.state.DeferredBatch::is_idle()checks every field (has_source_completions,values,bindings,vacated,render,tvb), andreserve_replaysis never called on a publication batch so lent capacities stay bounded. - Queue scratch vectors (
drivers/gpu/drm/asahi/g17/queue/mod.rs:108-115, 447-530, 587-645): Movingself.scratchout withcore::mem::takeand clearingpendingthenguardsbefore restoringself.scratchpreserves error-path cleanup semantics. (Ifoutputs.publish()fails afterguards.drain_all(),guardsdrains beforescratch.pending.clear(), which matches the pre-existingguards.into_iter()drop order.) - In-place
Packet::new(drivers/gpu/drm/asahi/g17/job.rs:152-169):UniqueArc::new_uninit+init_with(init!(...))is sound, avoids theArc::initclosure-move stack/memcpy regression you measured under LLVM=1, and preserves allocation-failure cleanup.
Remaining before approval (§5)
- Clean same-head HW & regression run on J616s (default command line, without the unrelated tiler-heap PRs / unincluded 4th patch noted in the PR body): 0 SELinux denials, 0 failed units, 0 new kernel errors, 0 GPU recoveries.
- One additional G17 Mac (M4 or M5) on top of
integration/aurorawithgpubench+ adeqp-vksubset showing no new failures and 0 GPU recoveries.
prepare_submission collected the validated commands and their VM pins in two vectors allocated by every submit ioctl and freed at its end. The queue now keeps both, empty between ioctls, so their room is allocated once. Commands are drained from them in the same order, and whatever an error leaves unsubmitted is released at the same point as before. Neither needs contiguous pages, and `pending` is large: up to 63 commands of over a kilobyte each come to an order-3 block. As KVecs that block was a GFP_KERNEL krealloc() that, on a machine without compaction, ended in the OOM killer during dEQP-VK runs. Keep them in KVVecs, so a large one falls back to vmalloc(), and charge them to the caller's memory cgroup (GFP_KERNEL_ACCOUNT), since each userspace queue keeps its own. They are freed with the queue, which may sleep. Signed-off-by: Jonathan Goyvaerts <[email protected]>
Packet::new built the packet, with its 1.3 KB validated command, on the stack and moved it into the Arc. The compiler kept three stack copies of the command for that, so every submitted command was copied four times here. Allocate the packet first and initialise it in place: the command is copied once. A failed allocation still drops the command unpublished. Signed-off-by: Jonathan Goyvaerts <[email protected]>
1c33065 to
9c73f8e
Compare
|
@RyanTheTide, an amendment you should know about: new head The trigger was an order-3 GFP_KERNEL OOM kill under deqp-vk on the J616s. The OOM killer fired five times in one dEQP-VK run, from What changed:
The same problem exists on integration/aurora as it is, where those vectors are still allocated per ioctl. The per-command dependency/checked-input/firmware lists and the merge arrays have it too. #2858 fixes those on its own, so it can land with or without this PR. Whichever lands second resolves a few lines in KUnit: 698 tests, 697 pass, 1 skip. Host tests --only g17 90/90. checkpatch 0 errors on all three commits. The hardware rows you and Dj asked for are still to come. Assisted-by: LLM (Claude:Opus 5.5) |
|
J616s (M4 Pro, 48 GiB, 25G83) regression row from our combined m4.179 kernel (integration/aurora bf423bf plus our other open G17 PRs), not a standalone kernel. It carries this PR at the previous head 1c33065 (all three commits patch-id equal), not 9c73f8e: its commit 2 is still the KVec version.
Assisted-by: LLM (Claude:Opus 5.5) |
There was a problem hiding this comment.
Formal §1–§6 pre-PR checklist re-review at 9c73f8ef6beb34a58a8c9a31cf02d76d675dcb0d (host-tests: green; mergeStateStatus: CLEAN; not superseded on integration/aurora).
Code, Safety & Attribution Assessment (0 code blockers)
- PublicationBatch reuse (
98e9ab5b4753,drivers/gpu/drm/asahi/g17/runtime.rs,runtime/backend.rs,runtime/render/submit.rs):spare_batchis a leaf mutex never held across allocation (DeferredBatch::publication()?) orkvfree(competing drops release the mutex guard before droppingbatch),is_idle()verifieshas_source_completionsand all 5 vectors are empty, andreserve_replays()is never called on lent publication batches so reused capacity remains bounded. - Queue
Scratchvectors (6408757ed87c,drivers/gpu/drm/asahi/g17/queue/mod.rs): AmendingScratch::{pending, guards}toKVVecwithGFP_KERNEL_ACCOUNTavoids high-order contiguous allocation failures on 64-command submissions and charges retained per-queue capacity to the caller's memcg. Both are cleared unconditionally before restoringself.scratchand freed in sleepable context whenQueuedrops;ValidatedandDestinationshold host-side references only, so error-path cleanup order is sound. - In-place
Packet::new(9c73f8ef6beb,drivers/gpu/drm/asahi/g17/job.rs):UniqueArc::new_uninit+init_with(init!(...))is sound, preserves allocation-failure cleanup, and avoids the LLVM=1Arc::initclosure-move stack/memcpy regression. - §1–§4, §6: Pass — no model gating, default command line, all 3 commits carry human author/committer (
Jonathan Goyvaerts <[email protected]>) and humanSigned-off-by:only (zero AI commit trailers),Assisted-by:at end of PR body,host-testsgreen, KUnit 697/698 pass (1 skip).
§5 Blocker Holding APPROVE / MERGETRAIN-LINUX4
- No exact-head hardware run for
9c73f8ef6beb: The2026-11-23J616s regression row ran the earlier1c3306581218KVecrevision inside the combinedm4.179kernel rather than9c73f8ef6beb'sKVVec+GFP_KERNEL_ACCOUNTcommit 2, and no second G17 Mac row has been run yet. - Required before approval:
- Clean exact-head (
9c73f8ef6bebonintegration/aurora, default cmdline, without unrelated PRs) J616s hardware + regression row (gpubench+dEQP-VKcases including thesynchronization.timeline_semaphore.*cases exercisingScratchKVVec, 0 OOM / allocation failures, 0 GPU recoveries, 0 SELinux denials, 0 failed units, 0 new kernel errors). - One additional G17 Mac row (M4 or M5) on top of
integration/aurorawithgpubench+ adEQP-VKsubset showing 0 new failures and 0 GPU recoveries.
- Clean exact-head (
|
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.
Verdict: FINISH, then merge at 9c73f8ef6beb: the code is ready; it needs only a row at this head.
Blockers: none in the code. Missing row: commit 2 changed after the booted 1c330658 (it was the KVec/GFP_KERNEL version), so one J616s boot at this head with the timeline-semaphore cases and a short desktop run is needed.
Because this G17 path is shared by M4, M5 and the Neo, it also needs one M5 or Neo run at this head before it merges.
Checked: no Apple material, no gates. spare_batch is a leaf mutex never held across an allocation. Host tests green.
Superseded by the review at 9c73f8e
|
Merged main The one conflict was in No behaviour change from the resolution: the merge's diff against main is line-for-line the PR's diff against its old base. Checks at the new head: asahi/SEP/ISP KUnit 797/798 (1 skip), and all 93 g17 host tests pass. The g15, DCP, M3-uAPI and SEP host tests fail on this machine on plain main too: they want a rustup 1.93.1 toolchain it doesn't have. Still open: the J616s boot at this head (timeline-semaphore cases plus a short desktop run) and one M5 or Neo row. |
|
Hardware row for @DjDeveloperr's request at Kernel: our m4.190 test kernel on a J616s (M4 Pro, T6040). It is aurora main Timeline semaphores: all 5,753
Desktop session: the owner's normal Hyprland desktop on m4.190, from boot (2026-11-25 15:43 UTC) to 16:27 UTC, with these suites and our other G17 runs on top: 0 GPU recoveries, 0 kernel lines at err level, 0 WARN/Oops/SError, 0 failed units (system and user). No SELinux/AppArmor loaded (0 Not covered: M4, M4 Max and M5, and a longer soak. |
|
Note 🤖 Gemini 4 Hydrogen responding on behalf of erikwb Verdict: FINISH, then merge at Blockers:
Checked: code diff against EvidenceEnvironment (J716c)
Commands run
for spec in \
"submit.empty --depths 1,8" \
"compute.light --depths 1,4,16" \
"compute.heavy --depths 1,4 --param kind=alu" \
"compute.heavy --depths 1,4 --param kind=bw" \
"render.light --depths 1,4,8 --param kind=tri" \
"render.light --depths 1,8 --param kind=clear" \
"render.heavy --depths 1,4 --param kind=fill --param res=1080p" \
"sync.signal --param kind=queue --param sema=timeline" \
"mem.buffer"; do
set -- $spec; t=$1; shift
gpubench-vk --test "$t" "$@"
doneResult at
deqp-vk --deqp-caselist-file=<shard-list> --deqp-log-filename=<shard.qpa> \
--deqp-log-images=disable --deqp-log-shader-sources=disable \
--deqp-surface-type=pbuffer --deqp-terminate-on-fail=disable --deqp-log-flush=enableA/B results (
|
| Kernel | Contains | Pass | NotSupported | DeviceLost | Fail | Wall | Non-audit dmesg lines | GPU-error lines | AVC |
|---|---|---|---|---|---|---|---|---|---|
Exact base 15b1e2e0aaca |
no #2228, no #3174 |
14,995 | 8 | 6 | 19 | 400 s | 74 | 32 | 0 |
Exact head 6e21fca49d00 |
#2228, no #3174 |
14,997 | 8 | 8 | 15 | 426 s | 81 | 34 | 0 |
Combined candidate 16e42e07bef5 |
main + #3174 + #2228 + #2715 + #3085 + #3084 (partial) |
15,001 | 8 | 1 | 18 | 491 s | 21 | 10 | 0 |
- The
Failcases aresignal_order.timeline_semaphore.write_image_*and vary run to run (3 names shared between base and head, 0 shared across all three runs). - The
DeviceLostcases aremulti_queue.timeline_semaphore.*(plus 1implicit.timeline_semaphore.write_copy_buffer_read_ssbo_vertex.buffer_16384.1113on the head run) and emit the same kernel log signature on base and head (G17 capacity refusal ComputeReserve,watchdog gave up on a render/compute command ... Defer behind earlier work of another VM, andrecovery: GPU MMU fault: write reason 0). Adding#3174dropsDeviceLostfrom 6–8 to 1. - Whole-boot health at
6e21fca49d00: Hyprland desktop up; 0 OOM/alloc failures; 0 AVC; booterr+lines limited to the 2 pre-existingsystemd-gpt-auto-generatorlines (plus the pre-existing MMU fault recovery lines during the timeline CTS window); failed units limited to pre-existingaurora-peripherals.serviceat boot (systemd-networkd-wait-online.serviceafter CTS).
Diff & CI at 6e21fca49d00
git diff 15b1e2e0aaca..6e21fca49d00modifies 5 files:drivers/gpu/drm/asahi/g17/job.rs,drivers/gpu/drm/asahi/g17/queue/mod.rs,drivers/gpu/drm/asahi/g17/runtime.rs,drivers/gpu/drm/asahi/g17/runtime/backend.rs,drivers/gpu/drm/asahi/g17/runtime/render/submit.rs.- GitHub CI:
host-tests(SUCCESS),readiness / readiness(SUCCESS),pr-text / pr-text(SUCCESS);readiness(SKIPPED).
|
This branch conflicts with |
Conflicts, and how they were resolved: - g17/queue/mod.rs submit(): main (aurora-silicon#2732) reserves room for every command's frontier and publisher entry before queuing, then takes the guards with into_iter(). The reservation is kept, and this branch's guards.drain_all() follows it, so the per-queue scratch vector keeps its allocation. - g17/runtime.rs Backend: main's compute_channels and this branch's spare_batch fields are both kept, in the struct and in new(). No behaviour changes: the branch's diff against main is unchanged. Signed-off-by: Jonathan Goyvaerts <[email protected]>
|
Merged main Conflicts:
No behaviour change: the branch's diff against main is line-for-line the same as at @erikwb, thanks for the J716c row. Tested and Not yet now carry it together with the J616s row at |
There was a problem hiding this comment.
Verdict: MERGE at 5c529c9e
Blockers: none (re-run the cancelled pr-text check and wait for the 3 queued unrelated KUnit jobs to finish green before landing).
Checked:
drivers/gpu/drm/asahi/g17/job.rs:UniqueArc::new_uninit(GFP_KERNEL)+init!constructsPacketin place, eliminating stack copies of the ~1.3 KB command payload.drivers/gpu/drm/asahi/g17/queue/mod.rs:Scratch(pending+guardsKVVecs charged viaGFP_KERNEL_ACCOUNT) is taken fromself.scratch, drained on enqueue, and explicitly cleared before returning toself.scratchon both success and error paths; conflict resolution at5c529c9epreserves#2732frontier/publisher room reservation.drivers/gpu/drm/asahi/g17/runtime.rs,runtime/backend.rs,runtime/render/submit.rs:PublicationBatch<'a>Dropreturns the batch tospareonly whenbatch.is_idle(), dropping non-idle batches safely; unit testa_publication_batch_comes_back_only_when_idleverifies all three cases.- Hardware rows & tests: net diff is line-for-line identical to
6e21fca4(tested on both J616s M4 Pro and J716c M5 Max); arm64 KUnit 853/854 pass (1 skip) at5c529c9e; 17/21 CI green (MERGEABLEonmain). - Checked for Apple material, tool attribution, private serials, and gating: clean; human
Signed-off-bypresent.
Evidence
- Head:
5c529c9e97e5(base: main,mergeable: MERGEABLE,+130/-23across 5 files).
|
code-owner ping <@422957901716652033> / @DjDeveloperr: merge train at |
|
Merging under the 6-point rule (Ryan 09:29, permanent), at |
Conflicts, and how they were resolved: - g17/queue/mod.rs, prepare_submission(): main (aurora-silicon#2228) keeps pending and guards in the per-queue Scratch, already KVVec and charged with GFP_KERNEL_ACCOUNT. Main's version is taken; this branch's local KVVecs and the ValidatedBatch alias go. - g17/queue/mod.rs, enqueue(): main (aurora-silicon#3119 and the timestamp overlap work) builds the producer waits in EnqueueOrdering and feeds the firmware-ordered ones through ProducerWaits. Main's logic is taken; dependencies, checked_inputs and firmware become KVVecs charged with GFP_KERNEL_ACCOUNT, as this branch did for the old loops. job.rs, sync_input.rs and sync_input.c merged without conflicts. No behaviour change beyond this branch's: which fences each command waits for, checks and hands to firmware is main's; only where the vectors that hold them are allocated, and who is charged, changes. Signed-off-by: Jonathan Goyvaerts <[email protected]>
main's #2228 builds the g17 packet in its allocation; the two fields this branch adds (forfeited, first_excuse) move into the new in-place initialiser. The forfeit logic is unchanged. Signed-off-by: Ryan Murray <[email protected]>
What: Three changes that remove per-submit allocations and copies on the G17 submit path: reuse each queue's publication batch, keep the submit ioctl's command vectors in the queue (as KVVecs charged to the caller), and build each packet in its allocation. They don't change what is submitted or where it runs; per submit, allocations drop from 12 to 9.3 on the J616s.
Tested:
6e21fca49d00, in our m4.190 test kernel: aurora main8c6bd8d1e806, plus drm/asahi: g17: kill a hung client's work instead of letting it take the GPU down #2504 atb731bf1a34b0, drm/asahi: g17: prune a queue's frontier from the front #2732 at9cc1c8acf8bcand this PR. Booted 2026-11-25 15:43 UTC. Mesa is m4/nextc356a1498.dEQP-VK.synchronization{,2}.timeline_semaphore.*: 5,753/5,753 Pass at-j 1, with 0 GPU recoveries.-j 10, 455 cases fail inqueueSubmitwithVK_ERROR_OUT_OF_DEVICE_MEMORY. The cause is Mesa's lazy QUEUE_CREATE getting ENOSPC/EBUSY once ten processes use up the shared queue budget. It is not an allocation failure in this PR.invoked oom-killerand 0page allocation failure.6e21fca49d00against base15b1e2e0aaca, from erikwb (row):gpubench-vk: 18/18 ok, with 0 GPU errors.timeline_semaphorecases match base.5c529c9e97e5merges mainb14959b819cfinto6e21fca49d00, and this PR's diff against main is unchanged. At that head: KUnit 853/854 (1 skipped), and every g17 host test passes.Risk: two-way door · the G17 Macs: M4 (incl. Pro/Max), M5 and Neo (A18 Pro). A kept command vector stays at its largest size until the queue closes (at most 64 commands, about 96 KB per queue, vmalloc-backed and charged to the client's memory cgroup). Checked unaffected: the J616s (M4 Pro) and J716c (M5 Max).
Not yet: a Neo (A18 Pro) row. The submit ioctl's CPU time change can't be measured across boots (see Evidence).
Details
DeferredBatchwith room for two rings of completions: 64 entries, about 3.5 KB through kvmalloc. It freed the batch when the publication ended, so the direct compute and render paths did a kvmalloc and a kvfree in every submit ioctl.prepare_submissioncollected the validated commands and their VM pins in two vectors allocated and freed by every ioctl. The queue now keeps both, empty between ioctls. Whatever an error leaves unsubmitted is released at the same point as before.GFP_KERNEL_ACCOUNT, amended 11-22). The trigger was an order-3 GFP_KERNEL OOM kill under deqp-vk, from this vector'skrealloc()inprepare_submission. 64 commands of about 1.5 KB need an order-3 block at 16K pages, and with compaction off in our kernel that allocation went to the OOM killer five times in one run, with 26 GB available. A large vector now falls back to vmalloc. It is freed with the queue, which may sleep. drm/asahi: g17: keep userspace-sized submit vectors off contiguous pages #2858 makes the same change for the code as it is on integration/aurora (the per-ioctl vectors there), plus the dependency and merge vectors this PR doesn't touch.Packet::newbuilt the packet, with its 1.3 KB validated command, on the stack and then moved it into theArc. The compiler kept three stack copies of the command for that. The packet is now allocated first and initialised in place, so the command is copied once. (Arc::init(init!(..))andArc::try_init(try_init!(..))were tried: both compile but growPacket::new's frame fromsub sp, #0x4f0to#0xd20and its memcpy calls from 4 to 7.)Known limit: a kept vector stays at its largest size until the queue closes: at most 64 commands, about 96 KB per queue. It needs no contiguous pages and is charged to the client's memory cgroup.
Evidence
J616s (M4 Pro, 48 GiB, 25G83), daily kernels since 11-18
Before and after are separate boots, compared with gpubench and kmem tracing, with 0 GPU recoveries. The one result that holds across boots is the allocation count.
Allocations (kmem trace,
compute.lightpinned at depth 1, 139 submits). Per submit, 12 before (11 kmalloc + 1 kmem_cache_alloc) and 9.3 after. The per-ioctl temporaries are gone: theDeferredBatchpublication (4096 B), andprepare_submission's pending vector (2048 B) plus its VM-guard vector (192 B). What is left is objects that outlive the ioctl, plus adrm_execin 2% of submits.Submit ioctl CPU time,
compute.light, in us at depth 1 / 8 / 64. Only rows with the same P-cluster frequency floor compare:So the change in submit CPU time is not measurable across boots: depth 64 is lower on cpu5, level on cpu11 and higher unpinned. The differences follow each boot's cluster load, not this code. The same floor gave 8.75 and 13.31 us at depth 1 on the two boots. Depth 1 is set by core type, cluster and frequency, which #2217 and #2222 address. What these commits measurably do is remove three per-submit allocations.
Not an A/B for these commits:
compute.heavyandcopy.bwsubmit CPU at depth >= 2 doubled. That is not this code. 99% of those submits ran on E-cores 1-2, because EAS parks the thread while the GPU works; pinned to a P core it is 19.3 us. Changing the cpufreq floor or the idle states made no difference.Regression row, combined kernel 7.3.0-m4.179 (previous head
1c3306581218)integration/aurora bf423bf plus our other open G17 PRs, not a standalone kernel. Boot 2026-11-22 23:51 UTC to 2026-11-23 01:43 UTC (desktop, other GPU tests, our dEQP-VK and GLES runs), default cmdline: 0 kernel lines at err level (same as m4.178), 0 failed units, 0 GPU recoveries. LSMs
capability,landlock,yama, no SELinux/AppArmor loaded, 0avc:lines. The window ends where a deliberate GPU hang test for another PR started.The 7
synchronization.timeline_semaphore.{one_to_n,wait_before_signal}.write_blit_image_read_{blit,copy}_image.*cases that hit order-3 OOM kills fromprepare_submissionon m4.177: 3 rounds at-j 2, 21/21 Pass, 0invoked oom-killer. This kernel has compaction enabled (our m4.177 config had it off), so the row says nothing about the KVVec change in9c73f8ef6beb.On this branch
KUnit: 698 tests, 697 pass, 1 skip (needs
CONFIG_UCLAMP_TASK), including the newa_publication_batch_comes_back_only_when_idle.tools/asahi/run-host-tests.py --only g1790/90. checkpatch 0 errors on all three commits.git diff 1c3306581218 9c73f8ef6bebtouches onlyScratch's declaration, its doc comment and the three reserve/push calls.