Repository navigation
drm/asahi: g17: charge a client's queue context to that client - #3683
jgoyvaerts wants to merge 4 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>
77c4395 to
2dc7fb5
Compare
Signed-off-by: DjDeveloperr <hey@djdev.me>
|
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>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
@jgoyvaerts This branch now conflicts with
Could you forward-merge |
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>
There was a problem hiding this comment.
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.
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>
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>
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>
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>
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_guardlink 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):
Allocator::kernel, M5 pooledFamily::Scheduler)Context::new← runtime.rsBackend::new← mod.rsnew_queueFamily::WorkState, 2 pages)Backend::newis 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):
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.pychecks:Backend::new's Allocator names a client;Its mutations
drop-client,none-clientanduncharged-backingare 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 devicefor 4 clients at the cgroup limit.