Repository navigation
drm/asahi: g17: cut allocations and copies in the submit path - #2228
jgoyvaerts wants to merge 3 commits into
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 <jonathan.goyvaerts@gmail.com>
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) |
DjDeveloperr
left a comment
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.
Assisted-by: LLM (Gemini 4 Neon)
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 <jonathan.goyvaerts@gmail.com>
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 <jonathan.goyvaerts@gmail.com>
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) |
DjDeveloperr
left a comment
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 <jonathan.goyvaerts@gmail.com>) 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 (
Assisted-by: LLM (Gemini 4 Neon)
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
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: head
9c73f8ef6bebhas not been booted. J616s M4 Pro (T6040, 25G83) with the previous head1c3306581218(all three commits patch-id equal; commit 2 was still the KVec/GFP_KERNEL version) in our combined kernel 7.3.0-m4.179, default command line, boot 2026-11-22 23:51 to 2026-11-23 01:43 UTC: 0 GPU recoveries, 0 kernel lines at err level, 0 failed units, no SELinux/AppArmor loaded (0avc:lines); the 7synchronization.timeline_semaphorecases that hit order-3 OOM kills on m4.177, 3 rounds, 21/21 Pass, 0invoked oom-killer(that kernel has compaction on, so this says nothing about the KVVec change). At this head: KUnit 697/698 (1 skipped), host tests--only g1790/90, checkpatch 0 errors, CIhost-testsgreen.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: only the J616s.
Not yet: any boot of head
9c73f8ef6beb(commit 2's KVVec +GFP_KERNEL_ACCOUNTversion); a clean standaloneintegration/aurora+ this PR J616s run; one more G17 Mac (M4 or M5) with gpubench and a deqp-vk subset. The submit ioctl CPU time change is not measurable 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.