Repository navigation
drm/asahi: g17: charge client_backing() pages to the client's memory cgroup - #3956
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>
Signed-off-by: DjDeveloperr <hey@djdev.me>
…cgroup KernelObject::client_backing() admits an object to its client's limits and counts it as the client's held memory, but it populated the pages in whatever task called it. Its callers run in workers too: tiler heap growth at publication (runtime/render/grow.rs, runtime/render/prepare.rs) and M5 render targets. A worker has no memory cgroup of its own, so those pages were charged to the root cgroup while the driver's ledger said they were the client's: a MemoryMax limit on the client did not bound them, and the OOM killer and systemd-oomd could not see them in the client's cgroup. Build the object through charged(), as queue_backing() does: it populates the pages under client.charging(), so they are charged to the memory cgroup of the task that opened the client, whichever task builds the object. g17-queue-object-charge-tests now checks that client_backing() goes through charged() and that charged() populates inside client.charging(), with two mutations that restore each fault. 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. - runtime.rs: DeferredBatch::is_idle() is main's pub(super) form with the object_pool check. - 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 a7551b33c04b. I'll merge after the J714s and J700 rows pass. They use the same combined kit as #3704 and #3976.
client_backing() now goes through charged(), so tiler heap growth and M5 render targets put their pages in the client's memory cgroup even when a worker builds them. The admission and the commit are unchanged. The main merge resolves its three conflicts the same way #3704 does (Makefile, DeferredBatch::is_idle, the object-fence test) and picks up main's entry.ready().
One consequence to keep in mind: at the client's cgroup limit, a worker's allocation can now fail where it used to go to the root cgroup. The J714s row has a memory-capped phase that checks that a client under a cap only ever stops with an out-of-memory error or a memcg kill, never a lost device.
Local checks, on current main 35ddf947:
- main + this PR merges cleanly (tree
257710b6).run-host-tests.py --only g17-in the host-tests container: 410/410 pass. - On main
a16156f8, the driver of #3704 + #3976 + this PR together built with no new W=1 warnings. - Hosted CI is green.
For landing: this conflicts with #3704 and #3976 only in tools/asahi/g17-queue-object-charge-tests.py and run-host-tests.py; the driver merges cleanly. If #3704 lands first, this PR needs a forward merge that keeps both sides:
- the docstring, the
--mutationchoices and therun-host-tests.pyentry list all seven mutations (drop-client,uncharged-backing,none-client,uncharged-compute,charged-kit,uncharged-pages,root-populate); sources()keeps both pairs of mutation branches;check()keeps this PR'sclient_backing()/charged()check and takes #3704's allocator list (Backend::newandBackend::provision_backing) instead of "only one allocator".
I tried exactly that resolution on main 35ddf947 + all three PRs. The g17 host tests pass 427/427, including the queue-object test and all seven mutations. The resolved files are blobs a76992a9d4ff (g17-queue-object-charge-tests.py) and cac6cf8e331e (run-host-tests.py). If you make the same resolution, they should match.
|
@jgoyvaerts This branch now conflicts with
Note: this branch sits on Could you forward-merge |
What: Stacked on #3683; review only the top commit. On G17,
KernelObject::client_backing()charges an object to its client's limits and held memory, but it filled the pages in whatever task called it. Its callers include kernel workers: tiler heap growth at publication and M5 render targets. A worker has no memory cgroup, so those pages went to the root cgroup while the driver counted them as the client's. Nowclient_backing()builds the object throughcharged(), which fills the pages underclient.charging(), so they are charged to the client's memory cgroup whichever task builds them.client_backing()comes from f587245 ("drm/asahi: g17: M5: account render target memory to the client that sizes it", Jeff Queisser) and is used for tiler heaps since a64f33a ("drm/asahi: g17: charge tiler-heap growth through KernelObject::client_backing()").Tested: no Mac at this head yet (a7551b3, which merges main at 9b8e29f). KUnit (arm64 qemu) at a7551b3: 1060 run, 1059 passed, 1 skipped, 0 failed. Host tests
--only g17-at a7551b3: 388 of 388 pass. Before the merge: KUnit (arm64 qemu) at d3c2096: 950 run, 949 passed, 1 skipped, 0 failed. Host tests--only g17-at d3c2096: 297 of 297 pass; the new check in g17-queue-object-charge-tests fails on the unfixed source and catches its two mutations.Risk: two-way door · M4 and M5 (G17). Tiler heap growth and M5 render targets of a client in a memory-capped cgroup now count against that cgroup, so growth can fail with ENOMEM at the cgroup's limit where its pages used to go to the root cgroup. The growth paths already handle an error from
client_backing(): the client's memory limit could already refuse it.Not yet:
Allocator::lower_user_charged()(compute pool pages, wrapped at its call site in drm/asahi: g17: allocate compute objects in SUBMIT, not at publication #3704's stack), and the G14-G16 and G18 user-charged kernel objects (alloc.rs,g16/object.rs,g18/buffer/object.rs), which are not changed here.Details
client_backing()keeps its admission (LEDGER.admit) and then callsSelf::charged(dev, size, CpuMap::WriteCombined, client, commit), the helperqueue_backing()already uses: the same write-combined user-charged object,with_object()insideclient.charging(..),Charge::user(commit)held. On a failure the commit is dropped as before.buffer.rsTvb::allocate(reached fromruntime/render/grow.rsandruntime/render/prepare.rs, which run in workers) andbuffer/target.rsObject::newfor M5 targets.Evidence
g17-queue-object-charge-tests:client_backing()goes throughcharged(), andcharged()fills its pages insideclient.charging(). Mutationsuncharged-pages(fill in the calling task again) androot-populate(dropclient.charging()) must be caught, and are.charge_memcgfiltered to the root memory cgroup saw all root charges come from unbound workqueue workers, up to 2.2 M per second while system shmem rose about 16 GB above what the cgroups held. Root charges stopped when the test's cgroup was killed. This commit fixes one worker path that charges client memory to the root cgroup; it is not yet shown to be the whole of that.