Repository navigation
drm/asahi: charge and reclaim the CPU-faulted pages of revocable mappings - #3224
Conversation
A charge counted the object's backing as held in full or not at all. Record the bytes held instead, so that a part of the backing can be counted: set_held_bytes() counts the difference to what was counted before, up to the object's size, and set_held() holds all or nothing as before. Signed-off-by: DjDeveloperr <[email protected]>
CPU faults in revocable mappings populate an object's pages one at a time while no device mapping holds its page array. Those pages stay referenced and the mapping unevictable until the mappings are revoked or closed, but pages_changed() reported only the page array, so a driver could not account for them. Report the number of pages that back the object instead of whether its array exists: all of its pages while the array does, otherwise the populated CPU pages, after each change to either. The Rust binding passes the count on and gains resident_pages_locked(), which reads the same number under the reservation lock. drm/asahi charges the pages reported, so the client and the process that created a VM-private object are charged for the pages its CPU mappings fault in, and the mapping is marked held while any are. Signed-off-by: DjDeveloperr <[email protected]>
Idle reclaim counted and released only objects with a device SG table. Once it had released an object's table, pages that CPU faults then populated in the object's revocable mappings stayed held until the VM's next job or until the mappings were closed. Count the pages that back an idle object, its page array or its CPU pages, and release whichever it has: releasing idle backing revokes the CPU mappings as well. Signed-off-by: DjDeveloperr <[email protected]>
Check that each page CPU faults populate in a VM-private object is charged to its client and creating process until the mapping goes. With ASAHI_RESIDENCY_DROP_CACHES=1, check that reclaim releasing an idle object's backing moves it off the unevictable LRU, that it then revokes the pages CPU faults populate in the object as well, and that their contents fault back in. Signed-off-by: DjDeveloperr <[email protected]>
|
J773g (M4 Mac mini, G16G) at How it was run: one guarded one-shot of main
Also on this boot: one s2idle passed, and Wi-Fi did 200 MB and 50 MB each way with 0 rx errors. The Mac went back to the stock kernel, and the kit was removed from it. |
|
J714s (MacBook Pro 14" M5 Pro, G17S B1) row at
|
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
There was a problem hiding this comment.
Verdict: REQUEST CHANGES at fbd98d12
Blockers:
- Branch is
CONFLICTINGwithmain(and CI did not complete green). Rebase/merge currentmainacross the 8 touched files (+275/-85) so the PR isMERGEABLE, verify all build/KUnit/host test CI checks pass, and confirm exact-head hardware verification at the rebased head.
Checked:
- Metadata and diff summary (
+275/-85, 8 files),CONFLICTINGagainstmain.
Evidence
- Resolve
CONFLICTINGagainstmainso CI builds/KUnit can execute cleanly on the current tree.
Resolve memacct.rs tests: keep the partial-hold case from this branch beside the usage-limit case from main. Signed-off-by: DjDeveloperr <[email protected]>
There was a problem hiding this comment.
The forward merge resolves the conflict and retains the partial-hold and usage-limit tests. The earlier J714s and J773g results support the reclaim path. Current checks still need to exercise the combined accounting code inherited from main, particularly partial holds unwinding without a charge leak.
RyanTheTide
left a comment
There was a problem hiding this comment.
Reviewed the conflict-pass merge commit f10faee only: single-file union, no hand edits. The resolution keeps what each side had and adds nothing outside the conflict. Approved for the merge-up; merging still waits on CI and the rows at this head.
There was a problem hiding this comment.
Verdict: MERGE at f10faee7a935
Converts this App's earlier review at the same head to an approval under the 12-01 merge bar (better than before and doesn't break; block only on a shown failure). No code blocker was found in it. The merge gate (a row on one Mac at this head + fast CI) is tracked by pr-readiness, not held here.
Checked: Code reviewed in the earlier App review at this head (6122660634).
Follow-ups (not blocking): checks exercising combined accounting, partial-hold unwind without charge leak
|
J616s (MacBook Pro 14", M4 Pro, T6040, G16) at |
|
Merging at |
What: CPU-faulted pages of VM-private objects are now charged, and idle reclaim releases them. These objects have revocable CPU mappings on G17: while no device mapping holds an object's page array, each CPU fault populates and pins one page. Those pages stayed unevictable but were not charged to the client (
drm-resident-system) or to the creating process (RssShmem). Idle reclaim never released them either, since it considered only objects with a device SG table.pages_changedcallback (from drm/asahi: hold an object's backing for every holder of its pages #3193) now reports how many pages back an object: all of them while the page array exists, otherwise the CPU-faulted pages.Tested: the host build with the asahi profile and
CLIPPY=1is clean: 0 errors and no warning on any changed line. J773g (G16) passes as a no-regression row: the residency selftest, Vulkan smoke, the dma-buf CTS and thegpu_memoryleak check are clean, and the kernel log has no faults. The new cases need G17 and skip there. The G17 row is pending.Risk: two-way door · every Mac with drm/asahi, since the shmem callback and the charge type change for all; the new charges and reclaim act only on G17 (M5), the only GPU whose user VMs have revocable mappings
Not yet
CI; the G17 row
Details
This PR is stacked on #3193 and changes the callback that PR adds. It retargets to
mainonce #3193 merges.shmem helper.
drm_gem_shmem_pages_changed()reportspages ? npages : cpu_pages_count, under the reservation lock, at four points:The Rust binding passes the count on. It also gains
resident_pages_locked(), which reads the same number.Charging.
memacct::Chargenow counts held bytes instead of a held flag.set_held_bytes()counts the difference to what it counted before, up to the object's size.set_held()stays all-or-nothing for kernel and user-memory objects.set_mapping_held()marks the mapping held while any page is held, and chargesresident * PAGE_SIZE. A one-page fault in a large heap therefore charges one page, not the whole heap.Reclaim.
idle_reclaim_count()andreclaim_idle_pages()now take objects that have either an SG table or CPU pages (resident_pages_locked() != 0). They count the pages that actually back the object.release_idle_pages_locked()already zaps revocable VMAs and drops their pages before it returns early for an object without an SG table.Unevictable LRU. Releasing the page array goes through
drm_gem_put_pages(). That clearsAS_UNEVICTABLEand moves the folios back to the evictable LRU before the callback clearsAS_INACCESSIBLE. Releasing the CPU pages does the same when no array remains. The reclaim selftest checks thatUnevictablein/proc/meminfodrops after the release.Tests.
asahi.cpu_faults_charge_their_pages: an unbound, 64-page VM-private object takes faults at 3 distinct pages. The client andRssShmemgrow by exactly 3 pages and return to baseline at munmap. Before this change they stay at baseline.asahi.reclaim_revokes_cpu_faulted_pages(needsASAHI_RESIDENCY_DROP_CACHES=1and root):Unevictabledrops by at least half its size.rust_drm_gem_shmempages_changed_spans_every_holderchecks the reported counts againstresident_pages_locked().asahi_memacctaddssome_pages_are_charged_as_they_are_held.Evidence
Host build of
rust/,drm_gem_shmem_helper.oanddrivers/gpu/drm/asahi/with the asahi profile andCLIPPY=1: 0 errors. The 14 clippy warnings in the touched files are all on unchanged lines. checkpatch reports 0 errors and 0 warnings on all four commits. The selftest builds with-Walland no warnings under gcc and clang.J773g (M4 mini, G16G), combined boot of main with this PR, see the row comment:
residency: 2 pass, 9 skip. The twoasahi.*cases are new and need GEM_RESIDENCY, which G16 lacks.dEQP-VK.api.smoke.*: 8/8dEQP-VK.api.external.memory.dma_buf.*: 44 pass, 6 not supported, 0 failgpu_memoryuser_resident and user_committed delta: 0 / 0