Skip to content

drm/asahi: g17: charge a client's queue context to that client - #3683

Open
jgoyvaerts wants to merge 4 commits into
aurora-silicon:mainfrom
jgoyvaerts:m4pro/g17-kernel-object-charge
Open

jgoyvaerts wants to merge 4 commits into
aurora-silicon:mainfrom
jgoyvaerts:m4pro/g17-kernel-object-charge

Conversation

@jgoyvaerts

@jgoyvaerts jgoyvaerts commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

What: On G17, the objects QUEUE_CREATE builds for a client's queue (the context's scheduler storage and work state) are charged to that client: to its driver accounting (fdinfo, its limits) and to its memory cgroup. A failure there comes back from QUEUE_CREATE as ENOMEM, a normal Vulkan error. The rest of a queue's kernel objects are built at publication, after SUBMIT has accepted the job. They stay uncharged until they are built in QUEUE_CREATE or SUBMIT (follow-up work); charging them where they are now costs a client its device when its cgroup fills.
Tested: no Mac at this head yet. At cf1d0db (main 49424e0 merged): KUnit (arm64 qemu, CONFIG_MEMCG=y) 1121 passed, 1 skipped, 0 failed; the full host run passes every g17 test and the asahi-held-ceiling and asahi-idle-vm-reclaim-feature tests with their mutations. The other failures of the full host run are local toolchain gaps in tests this PR does not touch (rustup 1.93.1 missing for g15-, a __stack_chk_guard link error in sep-suspend-errors and asahi-m4's test-stream-gate); they fail the same way in all three merged trees. Earlier, KUnit at 2dc7fb5: 949 passed, 1 skipped, 0 failed. Host tests at 2dc7fb5: g17-queue-object-charge-tests and its 3 mutations pass, as do the 3 fixtures this change touches; the 29 remaining failures also fail on main (sep-suspend-errors, g15-, apple-dcp, test-m3-uapi). M4 Pro test kernel m4.213 (the earlier, unsplit form of this PR): 0 kernel errors at boot; in a 24 GB memory-capped dq-fast run its publication-time charges lost 4 devices with ENOMEM, which is why this head charges only QUEUE_CREATE's objects.
Risk: two-way door · M4 and M5 (G17); every Mac running the driver also takes one memory-cgroup reference per DRM file.
Not yet: hardware run of this head: gpu_memory user_resident/kernel_resident and the client cgroup's memory.current across queue create and close. The publication half (render pairs, rings, generations, tiler heaps, compute state, timestamps) comes with building those objects in QUEUE_CREATE or SUBMIT.

Details

Charged now (built in the QUEUE_CREATE ioctl):

Object Where
Context scheduler storage (G17P Allocator::kernel, M5 pooled Family::Scheduler) context.rs Context::new ← runtime.rs Backend::new ← mod.rs new_queue
Context work state (Family::WorkState, 2 pages) same

Backend::new is the only Allocator that names a client.

How: KernelObject::queue_backing() commits the bytes to the client whatever the limits (Ledger::commit_kernel) and counts them as its held memory and, since idle reclaim never releases them, as unreclaimable. The pages are populated with the client's memory cgroup active (memacct::Client::charging, set_active_memcg). That cgroup is the one of the task that opened the DRM file, referenced for the client's lifetime. The charge belongs to the object and is released when the object is freed, also after the client's file is gone while the firmware still holds it.

Not charged yet (built at publication, after SUBMIT accepted the job):

  • the render pool and its backing, the render pair (queue state, config, support, generations, timestamps, registers, PB graph, NEO tiler-heap primary, targets, kick rings) and TVB growth;
  • compute growth, build, rearm and sibling channels, the compute timestamp page;
  • lent pairs and recovery replay.

Their Allocators say client: None, and three files build uncharged objects outside an Allocator (buffer.rs, buffer/target.rs, completion.rs). The host test pins exactly this split.

Why not all at once. The first form of this PR charged all of them. On the m4.213 test kernel, a dq-fast timeline-cases run at -j10 in a 24 GB MemoryMax cgroup filled the cgroup with GPU memory. Four clients then lost their device with ENOMEM at publication (g17/runtime/backend.rs:75): a publication-time kernel object's pages could no longer be charged. Before, those objects were charged to no cgroup when the scheduler's kworker built them. The fix is to build them where a failure can be returned from an ioctl, and charge them then.

Left uncharged (device-global): the boot-time firmware structures, heaps and pools (initdata.rs, initdata/m5.rs), the crash buffer, the PM metrics and the M5 metrics (mod.rs), and the shared compute pool.

Overlap with #2724: none any more. This head does not touch Tvb::allocate.

Evidence
  • KUnit asahi_memacct:

    • queue_objects_are_charged_to_their_client_and_released_once: the charge is taken past both limits, counts against the client's and the device's next admissions, survives the client's file, and is released once;
    • charging_restores_the_memory_cgroup.
  • tools/asahi/g17-queue-object-charge-tests.py checks:

    • only Backend::new's Allocator names a client;
    • all other Allocators say None;
    • uncharged kernel objects appear only in object.rs, the global boot files and the publication files.

    Its mutations drop-client, none-client and uncharged-backing are each caught.

  • m4.213 row (a), the earlier form of this PR: kernel log GPU work of a client failed (ENOMEM, reported at g17/runtime/backend.rs:75, ...); the client sees a lost device for 4 clients at the cgroup limit.

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>
@jgoyvaerts
jgoyvaerts force-pushed the m4pro/g17-kernel-object-charge branch from 77c4395 to 2dc7fb5 Compare November 30, 2026 15:42
@jgoyvaerts jgoyvaerts changed the title drm/asahi: g17: charge a client's queue objects to that client drm/asahi: g17: charge a client's queue context to that client Nov 30, 2026
Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr

Copy link
Copy Markdown
Contributor

Fixed cross-client reuse of charged queue backing in da65b3f.

Conflicts resolved as the union:
- Makefile: keep this branch's memcg_scope.o; drop g17/mesh_exclusion.o
  as main's b01db93 did;
- g17/runtime.rs: is_idle() takes main's pub(super) from dc93841
  and keeps this branch's object_pool check, so a batch that still holds
  a client's object pool is not idle;
- g17-object-fence-tests.py: run both this branch's
  client_pool_retirement() and main's cached_queue_lifetimes() from
  6d632d4, whose harness allocator now names no client
  (client: None), like the branch's other uncharged callers.

Main's 6d632d4 also makes a pool entry's fence optional: a cached
queue record (prefix != 0) waits for firmware stop. reap_deferred() now
retires a client-charged entry through main's Retained::ready(), so such
a record stays mapped until firmware stop as main requires, and an entry
with a fence is retired once the firmware has met it, as before.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
@jgoyvaerts
jgoyvaerts marked this pull request as ready for review December 4, 2026 05:24
@jgoyvaerts
jgoyvaerts requested review from a team and DjDeveloperr as code owners December 4, 2026 05:24
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:all 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 4, 2026
@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Merge readiness at cf1d0db1: not ready yet

Check Detail
CI at head running running: host-tests, KUnit asahi
Review no needs one approving review from Core, Omarchy Mac or Aurora Maintainers (not the author)
Requested changes no requested by aurora-silicon-review
Hardware row at head no no line with the head SHA cf1d0db1, a Mac and a result in the PR body or a comment
Conflicts ok none
PR text ok Risk: two-way · M4 and M5 (G17); every Mac running the driver also takes one memory-cgroup reference per DRM file.

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 merge-conflict Conflicts with the base branch (bot) and removed merge-conflict Conflicts with the base branch (bot) labels Dec 4, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

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

  • drivers/gpu/drm/asahi/memacct.rs
  • tools/asahi/run-host-tests.py

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.

Conflicts resolved as the union:
- memacct.rs: main's 5ce50e0 adds the unreclaimable totals and
  limits and a private Ledger::commit(client, bytes, reclaimable) for
  admit()/admit_reclaimable(). This branch's public commit(client,
  bytes), which charges a queue's kernel objects whatever the limits,
  becomes commit_kernel(). Idle reclaim never releases those objects, so
  it now also adds to the unreclaimable totals and returns a Commit with
  reclaimable: false, which main's Commit drop gives back from both. The
  queue-object test checks the unreclaimable total too. Both sides'
  tests stay.
- g17/runtime.rs: main's 9583ee4 builds ComputeShared without
  backing, so it needs no allocator; this branch's uncharged allocator
  there goes.
- run-host-tests.py: both sides' entries stay.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FINISH at cf1d0db

Failure: A charged M5 scheduler allocation can keep its pool lease even though the mapping skips cache conversion. If queue construction unwinds before firmware exposure, PooledObject::drop still takes the lease-return branch. That ignores the unexposed marker and assigns the next control record as the fence. In the exact pool fixture, an unexposed Scheduler with a fully consumed control ring stayed mapped and charged after drop and reap. It released only after a later control record, which an unused or failed queue does not publish. Apply the existing unexposed-object release behavior to these charged, unconverted leases and keep the witness check for exposed objects.

Checked: The exact object-fence suite passed. The extra scheduler control used the same production pool and mocked control ring. The current hosted checks and native accounting row remain on the existing route.

jgoyvaerts added a commit to jgoyvaerts/linux that referenced this pull request Dec 5, 2026
Brings aurora-silicon#3683's merge of main at 49424e0 (cf1d0db), so this branch matches its
base. Conflicts resolved keeping both sides:
- memacct.rs: both merges of main renamed aurora-silicon#3683's commit() for queue objects; aurora-silicon#3683 named it
  commit_kernel(), so this branch takes that name and aurora-silicon#3683's test asserts on the
  unreclaimable total; this branch's device_memory test stays.
- object.rs: queue_backing() calls commit_kernel().
- run-host-tests.py: this branch's g17-queue-object-charge mutations beside main's
  g17-submit-refusal-untouched entry.
- runtime.rs: this branch's shared_compute(), as in its merge of main at d0684a0.

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#3704's merge of aurora-silicon#3683 (cf1d0db, main at 49424e0). One conflict, in
run-host-tests.py: main's g17-submit-refusal-untouched-tests entry beside this branch's
g17-lower-window-tests, both kept.

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's merge of aurora-silicon#3704, which brings aurora-silicon#3683 (cf1d0db, main at 49424e0).
No conflicts.

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#3683's merge of main at 49424e0 (cf1d0db), so this branch matches its
base. One conflict, in run-host-tests.py: this branch's g17-queue-object-charge mutations
beside main's entries, both kept.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
@github-actions github-actions Bot added changes-requested A reviewer requested changes (bot) needs-hw-row No hardware row at the PR head (bot) and removed merge-conflict Conflicts with the base branch (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:all Macs affected, from Merge risk (bot) changes-requested A reviewer requested changes (bot) door:two-way Revertible or not, from Merge risk (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