Repository navigation
drm/asahi: g17: charge client_backing() pages to the client's memory cgroup - #3956
Draft
jgoyvaerts wants to merge 3 commits into
Draft
jgoyvaerts wants to merge 3 commits into
jgoyvaerts wants to merge 3 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>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 (d3c2096). 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.