Skip to content

drm/asahi: evict idle GPU backing past a ceiling on held memory - #3685

Merged
DjDeveloperr merged 12 commits into
aurora-silicon:mainfrom
jgoyvaerts:m4pro/g17-held-ceiling
Dec 4, 2026
Merged

DjDeveloperr merged 12 commits into
aurora-silicon:mainfrom
jgoyvaerts:m4pro/g17-held-ceiling

Conversation

@jgoyvaerts

@jgoyvaerts jgoyvaerts commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

What: GPU memory is bounded the way TTM bounds it. Past a device-wide ceiling on pages the GPU holds (half of RAM by default, TTM's rule), a user VM bind first evicts the idle backing of user VMs, then populates anyway. Only a real allocation failure fails the bind: GEM pages are __GFP_RETRY_MAYFAIL, so that is ENOMEM, never the OOM killer. The fixed shares of allocated bytes (67% device, 50% per client) no longer apply to VM-private buffers on G17 and M5, which idle reclaim can release; by default they stay on everything it never releases (all objects on the other backends, and GEM_USERPTR pins, shareable objects, page tables, GPUVA records and client kernel memory everywhere). It reports this as DRM_ASAHI_FEATURE_IDLE_VM_RECLAIM (uAPI bit 49) on the backends whose user VMs reclaim (G17, M5), so Borealis can drop its own free-memory reserve.
Tested: J616s M4 Pro at e8c9a1a, as a backport on test kernel m4.223 (identical apart from the asahi: prefix our tree adds to three boot-log lines; booted 2026-12-02 with asahi.mem_limit_pct=25): GET_PARAMS features has bit 49; an idle Vulkan client's 4 GiB was evicted when another populated 10 GiB past the 11.9 GiB threshold, then restored at its next submission with its contents intact; nothing refused; 0 recoveries. dEQP-VK (dq-fast, 11,851 cases of the all and mem lists, 4 jobs) on that boot: 0 differ from the system Mesa's baseline. KUnit (arm64 qemu) at e8c9a1a: 952 passed, 1 skipped; host tests: only main's own failures.
Risk: one-way door (uAPI: feature bit 49) · all Macs running the driver; reclaim and the bit only on G17 and M5. User-visible defaults change: VM-private buffers on G17 and M5 have no default per-client or device limit, everything else keeps the 67 % / 50 % shares (counted separately), and asahi.mem_limit_pct only moves the idle-reclaim threshold, never refusing.
Not yet: hardware at the current head: the rows above are from before the limits on unreclaimable memory were added. Also a game run past the threshold (the ceiling itself has been in our test kernels since m4.214 at the default half of RAM).

Details

Commits:

  1. Jonathan Goyvaerts: the ceiling and the eviction.
  2. DjDeveloperr: bit 49 on G17, and evict_idle try_locks the eviction list so a bind never waits behind another walk. It also had an explicit asahi.mem_limit_pct set a refusing device limit.
  3. Jonathan Goyvaerts: bit 49 decided in mmu::idle_vm_reclaim_feature() and reported by G17 and M5, the backends whose new_vm gives user VMs a residency gate (Vm::with_status()), with KUnit and host coverage.
  4. Jonathan Goyvaerts: bit 49's comment in the house form (name first, standard closing sentence).
  5. Jonathan Goyvaerts, follow-up to commit 2 on the owner's rule: asahi.mem_limit_pct only moves the threshold and never refuses (configured()). Refusal stays with asahi.client_mem_limit_pct, the gpu_mem_limit_pct sysfs file and the memory cgroup. Bit 49's comment says so instead of "An explicit allocation limit still applies".

Why this shape. No driver checks free memory when a buffer is created. TTM, i915, msm, panfrost, WDDM and macOS all do two things instead: they let the real allocation fail after the driver has evicted its own idle buffers, and they bound how many pages are held at once. TTM's bound is ttm_pages_limit, half of RAM by default (ttm_global_init()). ttm_tt_populate() calls ttm_global_swapout() while over it, and allocates anyway once nothing is left to swap. The ceiling here is the same: an eviction trigger, never a refusal.

The ceiling. The ceiling is checked against user_resident + kernel_resident from memacct: everything the GPU holds, user and kernel objects alike. Ledger::populate() runs at the one place a user object's pages are populated for the GPU, held_user_sg_table(), which both VM_BIND paths call before taking any GPUVM lock. Past the ceiling it calls mmu::evict_idle(excess), then populates.

  • What is never checked: objects already held, imports and user-memory objects.
  • Counted but never evicting: a submission's restore of an evicted VM, kernel objects and CPU mapping faults. Refusing those would lose the device.

Eviction. mmu::evict_idle() walks a device-wide list of the VMs that have shrinkers. A VM joins the list when its shrinkers are registered and leaves it before they are freed. Each VM is asked reclaim_idle_pages(target, false): what its first shrinker releases under memory pressure, which is only VMs idle for 2 s with no lease. Objects userspace asked to keep resident (GEM_RESIDENCY) stay.

  • Everything is taken with try-locks, so a bind that evicts can't wait on another VM.

Where the bind can still fail. Only in the page allocator or the memory-cgroup charge. Both fail with ENOMEM under __GFP_RETRY_MAYFAIL (memcontrol.c try_charge_memcg goes to nomem before mem_cgroup_oom). Borealis turns a VM_BIND ENOMEM during BO allocation into VK_ERROR_OUT_OF_DEVICE_MEMORY (agx_device.c, hk_device_memory.c). Gallium returns a NULL BO, and some of its callers do not check for it (agx_batch.c, pool.c). That is unchanged by this PR.

Knobs.

knob default what it does
asahi.mem_limit_pct 0 where eviction starts: 0 is half of RAM, 1-99 is that share, 100 or more is never
asahi.client_mem_limit_pct 0 opt-in per-client limit on everything, refusing; 0 is 50 % on unreclaimable memory only
gpu_mem_limit_pct (sysfs) unchanged still sets both refusing limits, and the unreclaimable ones, for tests

On G17 and M5 (bit 49 set) with no limit set, GET_PARAMS reports memory_limit 0 and client_memory_limit 0; the other backends report the limits on unreclaimable memory, which there is all of it. Borealis then sizes its Vulkan heap at half of RAM (hk_resolve_uma_sysmem_heap()), the size the old 50% client limit gave it.

What it changes for the dq-fast OOM. Every dEQP device is active, so there is nothing idle to evict there. The ceiling helps by releasing background clients' idle VMs early. The bind failing with ENOMEM at the memory cgroup's or the system's real limit is what reaches the dEQP clients, as OUT_OF_DEVICE_MEMORY, not as an OOM kill.

Related: #3683 charges G17 queue objects to their client; independent of this PR.

Evidence
  • KUnit asahi_memacct:
    • past_the_ceiling_idle_backing_is_evicted_and_population_proceeds: within the ceiling nothing is evicted; past it the excess is asked of idle backing, which releases it, and population runs; with nothing idle it still runs; population's own ENOMEM fails it, with 0 refusals counted; no ceiling, no eviction;
    • the_held_ceiling_is_half_of_ram_by_default: 8, 16, 24, 48 and 64 GB, plus the override;
    • only_unheld_user_objects_add_held_memory.
  • tools/asahi/asahi-held-ceiling-tests.py fails on main (no populate on the bind path) and passes at head. Its mutations skip-populate, no-unregister, late-unregister and refuse are each caught.

Hardware row, m4.223 (J616s M4 Pro, 48 GB), 2026-12-02 14:15-14:21 UTC:

  • Boot with asahi.mem_limit_pct=25: dmesg asahi: GPU memory: per-client limit 0 MiB (0 = none), idle reclaim above 11910 MiB held (0 = disabled); gpu_memory held_limit 12488880128.
  • GET_PARAMS features 0x4003197a6001dc37: bit 49 (IDLE_VM_RECLAIM) set; memory_limit 0, client_memory_limit 0.
  • Ceiling row, in a memory-capped unit: client A holds 4 GiB and goes idle; client B populates 10 GiB past the threshold. A's drm-resident-system went 4,328,108,512 -> 32,895,456 bytes (evicted); B finished; A then verified its contents through the CPU mapping and submitted again: "restored ok". Second pass, B alone past the threshold: finished. gpu_memory refused 0 -> 0; no asahi failure lines; 0 recoveries.
  • dEQP-VK with dq-fast on the same boot, system Mesa (fbdc69663) against its stored baseline: all (7106) and mem (4745) lists, 0 differ, 0 recoveries.

jgoyvaerts and others added 2 commits November 30, 2026 01:18
GEM pages the GPU holds are pinned: unevictable, and released only by
the driver's own idle reclaim. Two things bounded them:
- **Fixed limits:** 67% of RAM per device and 50% per
  client, counted on allocated bytes. A fixed share of allocated bytes
  is not how other drivers bound GPU memory, and it caps a game at half
  of RAM.
- **Global reclaim:** the per-VM shrinkers release an idle VM's backing
  in step with the rest of reclaim. That is interleaved with swapping
  out other processes.

On an M4 Pro (48 GB), a dq-fast timeline-cases run at -j10 had clients
whose GPU memory, together with the desktop, used up RAM and swap.
systemd-oomd then killed the desktop's apps, while the driver refused
nothing.

Bound held memory the way TTM does instead:
- **The ceiling:** the bytes the GPU holds at once, user and kernel
  objects together, have a device-wide ceiling. It defaults to half of
  RAM, TTM's default limit on the system pages GPU objects may hold
  (ttm_global_init(), ttm.pages_limit).
- **Eviction first:** a user VM bind that populates an object past the
  ceiling first has the idle backing of user VMs released, up to the
  excess, as their shrinkers would release it under memory pressure.
  This uses a device-wide list of the VMs that have shrinkers. Objects
  userspace asked to keep resident are left alone.
- **No refusal:** the bind then populates whatever eviction freed. As
  in ttm_tt_populate(), which calls ttm_global_swapout() while over
  ttm_pages_limit and allocates anyway once nothing is left to swap,
  the ceiling only starts eviction.
- **Where a bind still fails:** only where the page allocator or the
  memory cgroup fails it. GEM shmem pages are allocated with
  __GFP_RETRY_MAYFAIL | __GFP_NOWARN (drm_gem_shmem_init()), so both
  return ENOMEM rather than invoke the OOM killer, and Borealis reports
  VK_ERROR_OUT_OF_DEVICE_MEMORY.
- **Not checked:** restoring an evicted VM at its next submission,
  kernel objects and CPU mapping faults. They count towards the ceiling
  but evict nothing.

The fixed limits become opt-in:
- **asahi.client_mem_limit_pct** now defaults to 0, no limit.
- **asahi.mem_limit_pct** now sets where eviction starts: 0, the
  default, is half of RAM, and 100 or more means never. It no longer
  sets a device limit that refuses.
- **gpu_mem_limit_pct** (sysfs) still sets both refusing limits, for
  testing.

With no limit, GET_PARAMS reports 0 and 0. Borealis then sizes its
Vulkan heap at half of RAM (hk_resolve_uma_sysmem_heap()), the size the
old 50% client limit gave it. gpu_memory reports the ceiling as
held_limit.

Tests:
- **KUnit:** under the ceiling nothing is evicted; past it the excess is
  asked of idle backing and population runs; with nothing idle it still
  runs; only population's own ENOMEM fails it, and that counts no
  refusal; the ceiling is half of RAM at 8, 16, 24, 48 and 64 GB.
- **Host test** (asahi-held-ceiling-tests.py): a user bind populates
  through the ceiling; a VM's shrinker owner joins the eviction list and
  leaves it before its shrinkers are freed; the ceiling refuses
  nothing. Each is checked by a mutation. g15-probe-init-tests also
  checks that the eviction list is ready before the adapters register.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr

Copy link
Copy Markdown
Contributor

J700 (Neo, G17P, 7.3 GiB) boot row at head ba10491f

Kernel: one trial boot (boot 1abbcccc). Stock Fedora -41 was restored and verified afterwards.

Results

  • GET_PARAMS: bit 49 (IDLE_VM_RECLAIM) is set, bit 48 is clear. memory_limit and client_memory_limit read 0 and 0: no refusing limits by default.
  • gpu_memory: held_limit 3,917,193,216 bytes, half of this Neo's RAM; limit and client_limit 0; refused 0 throughout.
  • Explicit cap: writing gpu_mem_limit_pct = 40 set both refusing limits to 3,133,754,572 bytes (40 %) in GET_PARAMS and gpu_memory. mem.buffer (4 KiB-64 MiB allocate/bind/fill/free) still ran under it. Writing back 0 restored the defaults, 0 and 0.
  • Normal submits all completed with correct output:
    • q4 render triangle 42.4 µs and compute.light d1/d16, readbacks ok
    • 4-queue render; 4-queue and 4-process compute
    • concurrent render + compute
    • cross-queue semaphores; queue churn (CRC ok)
  • Multi-queue CTS: sync2 16,680 Pass / 7,080 NotSupported / 0 Fail; sync 12,798 Pass / 9 NotSupported / 0 Fail. Identical to the other boots.
  • Two clients in separate cgroups, run, closed and then reused: kernel_resident 308 → 453 → 298 MB six seconds after close. user_resident went back to its starting level.
  • Health: 0 WARN, 0 GPU faults, 0 AVC, 0 failed units. The only flagged line is the out-of-tree taint from building the module with M=.

Not covered:

DjDeveloperr
DjDeveloperr previously approved these changes Dec 1, 2026

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed ba10491. An explicit device cap reaches admission, and a competing bind skips an active reclaim walk. The seven targeted checks passed. The remaining rows cover G17 eviction and restoration with bit 49 set, plus the explicit cap on G16 with the bit clear.

@DjDeveloperr

Copy link
Copy Markdown
Contributor

Restored explicit device memory caps and exposed G17 idle-VM reclaim as feature bit 49 in ba10491.

DRM_ASAHI_FEATURE_IDLE_VM_RECLAIM (bit 49) says the kernel attempts
idle-VM reclaim before populating new user backing. Userspace can then
drop reserves of its own against free memory. G17 reported it inline
whenever the held-memory ceiling is set. M5 user VMs get the same
residency gate and shrinkers from `Vm::with_status()`, so a bind there
evicts idle backing the same way, but M5 did not report the bit.

Decide it in one place, `mmu::idle_vm_reclaim_feature()`, next to the
eviction it describes:
- it reports the bit while the ceiling is set;
- G17 and M5 call it from get_params;
- every backend without user-VM reclaim reports nothing.

Tests:
- **KUnit:** the bit is set only with a ceiling.
- **Host test** (asahi-idle-vm-reclaim-feature-tests.py): every backend
  whose new_vm reaches `with_status()` reports the bit, and no other
  backend does. Three injected faults are caught.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
Every feature bit defined outside enum drm_asahi_feature opens its
comment with its name and closes with "A feature bit like those of enum
drm_asahi_feature, defined here like bit 32." Bit 49 had neither. Add
both, keeping the description as it was, so userspace headers mirror one
settled text.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
jgoyvaerts added a commit to jgoyvaerts/mesa that referenced this pull request Dec 1, 2026
Copy the DRM_ASAHI_FEATURE_IDLE_VM_RECLAIM comment word for word from
aurora-silicon/linux#3685 (86241547ea66, include/uapi/drm/asahi_drm.h
lines 628-635). Comment only.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
"drm/asahi: honor explicit device limits alongside idle VM reclaim" had an
explicit asahi.mem_limit_pct set two things: the held-memory threshold
where idle reclaim and eviction start, and a device limit that refuses
GEM objects past the same percentage. The owner's rule (11-30) is that
it only sets where reclaim starts and never refuses: past the threshold
the kernel reclaims idle backing and then allocates, as TTM does past
its pages limit.

Keep the threshold and drop the refusal:
- `configured()` derives both settings: no device limit from the
  percentage, the threshold from it as before. Its default (0) is
  unchanged: half of RAM, no device limit.
- **What still refuses:** asahi.client_mem_limit_pct (opt-in per client),
  the gpu_mem_limit_pct sysfs file (sets device and client limits), and
  the caller's memory cgroup.
- **Bit 49's header comment** says so plainly, in place of "An explicit
  allocation limit still applies."

The other parts of that commit stay: evict_idle's try_lock, and bit 49
on G17.

Tests:
- **KUnit:** an explicit percentage moves the threshold, sets no limit,
  and a population past it asks for eviction and is refused nothing. The
  per-client limit stays the one that refuses.
- **Host test** (asahi-held-ceiling-tests.py) now requires the percentage
  to reach only the threshold; the mem-pct-refuses fault is caught.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
jgoyvaerts added a commit to jgoyvaerts/mesa that referenced this pull request Dec 2, 2026
Copy the DRM_ASAHI_FEATURE_IDLE_VM_RECLAIM comment word for word from
aurora-silicon/linux#3685 (e8c9a1aed023, include/uapi/drm/asahi_drm.h
lines 628-636): the held-memory threshold itself never refuses an
allocation. Comment only.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
@jgoyvaerts
jgoyvaerts marked this pull request as ready for review December 2, 2026 14:22
@jgoyvaerts
jgoyvaerts requested review from a team as code owners December 2, 2026 14:22
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) door:one-way Revertible or not, from Merge risk (bot) merge-conflict Conflicts with the base branch (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Merge readiness at f160c53a: not ready yet

Check Detail
CI at head ok 9 checks passed
Review no approved by DjDeveloperr, but GitHub does not count it yet (code owner from Core or Omarchy Mac needed, or approval went stale)
Requested changes ok none
Hardware row at head no no line with the head SHA f160c53a, a Mac and a result in the PR body or a comment
Conflicts ok none
PR text ok Risk: one-way · (uAPI: feature bit 49) · all Macs running the driver; reclaim and the bit only on G17 and M5. User-visible defaults change: VM-private buffers on G17 and M5 have no default per-client or device limit, everything else keeps the 67 % / 50 % shares (counted separately), and asahi.memlimitpct only moves the idle-reclaim threshold, never refusing.

Areas: area:gpu

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

Conflict in drivers/gpu/drm/asahi/memacct.rs: main counts an object's held
bytes instead of a held flag, since CPU faults in revocable mappings can
hold some of its pages. Keep both: adds_held() compares the held bytes
with the object's size.

Signed-off-by: DjDeveloperr <hey@djdev.me>
CPU faults in a revocable mapping hold single pages of an object, which
are counted as held already. A bind that populates the rest counted the
whole object again, and asked idle backing for more than the bind adds.

Have Charge::adds_held() return the bytes that are not held yet, and pass
those to Ledger::populate().

Signed-off-by: DjDeveloperr <hey@djdev.me>
The held-memory ceiling replaces the default limits (67% of RAM for the
device, 50% per client) with eviction. Eviction only releases objects
private to a user VM that has idle reclaim. Without the limits, nothing
bounds the rest:

- On G13 to G16, G18 and M3, user VMs have no idle reclaim. The ceiling
  evicts nothing there, and one client could take all memory.
- GEM_USERPTR pins are not charged to RLIMIT_MEMLOCK on the grounds that
  the GPU memory limits bound them.
- Page tables, GPUVA records, bound objects, heap blocks and queue
  objects grow with a client's requests and are charged to no process,
  so the OOM killer does not find their owner.

Keep the old default shares for what idle reclaim never releases, counted
separately from the objects it does release. GEM_CREATE already knows
whether the object's VM has idle reclaim: such an object is subject only
to the opt-in limits, as before. asahi.mem_limit_pct still refuses
nothing, and a G17 or M5 game's own buffers have no default limit.
asahi.client_mem_limit_pct, if set, replaces the default per client.

GET_PARAMS reports the limits on a client's objects: none where idle
reclaim is reported, the default shares elsewhere, as without the
ceiling. gpu_mem_limit_pct sets every limit, so 0 still disables all.
gpu_memory shows the new totals.

Signed-off-by: DjDeveloperr <hey@djdev.me>
Past the ceiling, every bind that populates pages looked for idle backing
in every user VM. A look visits every mapping of each VM and holds that
VM's reservation and the UAT lock meanwhile, also for a VM in use, whose
advised contents it may purge. A game past the ceiling with nothing idle
left paid for that at each new buffer.

A VM in use is not idle before RECLAIM_QUIET_NS after its last job. Once
a look has released less than it was asked for, populate right away for
that long before looking again.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@github-actions github-actions Bot added needs-hw-row No hardware row at the PR head (bot) and removed merge-conflict Conflicts with the base branch (bot) labels Dec 3, 2026
DjDeveloperr
DjDeveloperr previously approved these changes Dec 3, 2026

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed at 3cf6a87e1138: the author's five commits, merged with main 13dc5a79c0ec, plus three small commits of ours. No finding is left in the code. The hardware rows below are owed.

Checked

  • Merge: one conflict. main now counts the held bytes of an object, not a flag (CPU faults can hold single pages); both sides are kept.
  • Bit 49: free on main, in every open linux PR that touches the header (48, 50 and 51 are taken) and in Mesa. Only mesa#1416 uses it, for this.
  • Locks: a bind that evicts takes only try-locks on other VMs and on the list, so it never waits for a busy VM. Its own lease keeps its own VM out of eviction. VM create and close can wait for a running walk; nothing in reclaim takes the list lock.
  • Firmware and an evicted VM: same path as the shrinkers on main. A submit takes its lease before parsing, every accepted command keeps one until exact retirement (queued and held-back ones too), and a failed published job quarantines the VM, which can_reclaim() refuses.

Found, and fixed on the branch

  1. c6468ddcb987: an object with some pages already held was counted whole against the ceiling. Only the missing part counts now.
  2. 5ce50e0ea12f: with the default limits gone, nothing bounded what eviction can't release: every object on G13 to G16, G18 and M3, and on all Macs GEM_USERPTR pins (no RLIMIT_MEMLOCK), shareable objects, page tables, GPUVA records and a client's kernel memory. That memory keeps the old 67 % / 50 % shares, counted separately. A G17 or M5 client's VM-private buffers still have no default limit, and asahi.mem_limit_pct still refuses nothing.
  3. 3cf6a87e1138: past the ceiling, every new buffer walked every mapping of every VM under its reservation, even with nothing idle. A walk that came up short is not repeated for the 2 s a VM needs to become idle.

For the author: please check that (2) fits what you want, and update the PR text ("no per-client or device limit is set by default" is only true for VM-private objects on G17/M5). Bit 49's comment gained a clause, so mesa#1416 needs the new copy.

Ran: arm64 LLVM W=1 of drivers/gpu/drm/asahi/: 0 new warnings (complete main baseline at 5f32aa72fa7e; the one at 13dc5a79c0ec printed the same warnings and was stopped in code generation). A build with KUNIT=y compiles; the asahi_memacct tests pass built for the host with stubs (19/19, without the mm test). KUnit did not run on arm64. Host tests on the merged tree: g17 337/337, m5 114/114, g15 18/18, asahi 14/14, g18 4/4, g16 2/2. A full run just before #3681 landed: 988 ok, 55 not, all 55 because the checkout had no history for their old-commit controls; the GPU ones passed once it had. checkpatch --strict: clean on our commits.

Owed before merge

  • J700 and J714s (G17): idle client evicted past the ceiling and restored with its contents checked, also across a sleep; a busy client never evicted; 0 recoveries; CTS against the recorded base. On J714s also GTA V, with one pass past the threshold.
  • J773g (G16, bit clear): limits equal to base, the same refusal at 50 % of RAM, no OOM kill, CTS and mem.* no-regression.
  • The rows at ba10491f and e8c9a1ae don't carry, since the limits changed.
  • We pushed last, so someone other than DjDeveloperr has to approve our commits.

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The new quiet interval can still admit a duplicate full walk under concurrent binds. A bind can pass the NEXT_LOOK check and be descheduled before try_lock. If another bind then scans, comes up short and publishes the quiet deadline, the first bind can resume, acquire the lock and immediately scan again. I reproduced two walks in one quiet interval using the exact evict_idle body with a controlled pause. A deadline check after acquiring the existing lock would enforce the intended interval.

@DjDeveloperr

Copy link
Copy Markdown
Contributor

J773g (Apple M4 Mac mini, T8132, G16G B0, 24 GB RAM, os-fw 27.2) row at head 3cf6a87e1138: PASS

  • Kernel: 7.3.0-j773g-main3685+ (main f7e3388dd07d + #3685 3cf6a87e1138), boot a748096f-d244-4f1d-b55b-ada499e08c58, 0 sleeps, 0 GPU recoveries.
  • Default boot (gpu_mem_limit_pct=0): gpu_memory reports limit 0, client_limit 0, held_limit 0, unreclaimable_limit 0, client_unreclaimable_limit 0, refused 0; asahi-mem params: features 0x41026001fc07 idle_vm_reclaim 0 memory_limit 0 client_memory_limit 0. (Note: G16 does not call LEDGER.configure() on main either; this is pre-existing and not a #3685 regression, so default stays 0/0 and idle_vm_reclaim stays 0.)
  • Limit enforcement (gpu_mem_limit_pct=50): limit / client_limit / unreclaimable_limit / client_unreclaimable_limit set to 12394078208 bytes (~11,820 MiB, 50% RAM; ~1,795 MiB baseline plasmalogin):
    • asahi-mem gem 14000: admitted 9984 MiB, then Cannot allocate memory (clean ENOMEM, refused 0 -> 1).
    • asahi-mem userptr 14000: admitted 0 MiB, then Operation not supported (userptr unsupported on G16, 0 faults).
    • heldvk 14000 64: stopped cleanly at allocation 154 of 64 MiB: VkResult -2 (VK_ERROR_OUT_OF_DEVICE_MEMORY, holding 9856 MiB, refused 1 -> 3), verified 2583691264 words with 0 wrong, exit 0.
  • Restore (gpu_mem_limit_pct=0): limits restored to 0/0; 0 GPU recoveries, 0 OOM lines.
  • Single-process Vulkan CTS memory subset (stock ICD): dEQP-VK.memory.allocation.basic.* 102/102 Pass, dEQP-VK.memory.requirements.* 25/77 Pass (52 NotSupported), dEQP-VK.memory.mapping.dedicated_alloc.* 2844/2844 Pass — total 2971 Pass, 52 NotSupported, 0 Failed, refused delta 0 during CTS, 0 GPU recoveries, 0 OOM kills.

evict_idle() checks NEXT_LOOK before it takes the list lock. A bind can
pass that check and be scheduled out before try_lock(). If another bind
then looks, comes up short and sets NEXT_LOOK, the first one takes the
lock and walks every mapping of every user VM again at once, although
nothing it could release is idle yet.

NEXT_LOOK is stored with the lock held, so check it again after taking
the lock. The check before the lock stays: it keeps binds within the
quiet time off the lock.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@github-actions github-actions Bot added the needs-hw-row No hardware row at the PR head (bot) label Dec 3, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor

Reply to this review: confirmed, and fixed the way you suggested. Thanks.

  • What changed (7ae56e51538b, one commit on top): evict_idle() checks NEXT_LOOK again after it takes IDLE_VMS, before the walk. NEXT_LOOK is stored under that lock, so a bind that passed the first check late now returns. The check before the lock stays, as the cheap path.
  • Test: asahi-held-ceiling-tests.py now also wants the second check, between the lock and the walk, and has a new mutation (unlocked-look-check) that removes it. It fails on the old code. Host tests of the PR: 14 of 14 (held ceiling 8, idle VM reclaim feature 4, g15 probe 2). aurora.ko builds (arm64, LLVM) with the same warnings as before; checkpatch --strict is clean.
  • Approval: the last push is ours, so someone other than DjDeveloperr has to approve it.

Earlier rows

  • The J773g row still counts. The only driver change since is inside evict_idle(), and that Mac never gets there: the G16 probe does not call LEDGER.configure(), so held_limit stays 0 (as it did in the row), and Ledger::populate() calls evict_idle() only for a nonzero held_limit. Writing gpu_mem_limit_pct does not set it. The list of VMs is empty there too, since only G17 and M5 user VMs get a residency gate.
  • J700 and J714s do reach the changed code. Neither has run the eviction case yet, so nothing is lost; both will be taken with this commit in.

@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: MERGE at 7ae56e5

Checked: The original review's overlapping-bind case now rechecks the quiet deadline while holding the mutex that protects its update. In a deterministic host run of the exact eviction routine, two overlapping binds produced one idle walk during the quiet interval, and a bind after expiry produced the next walk. Removing the new recheck led to two walks during the quiet interval. The held-ceiling suite passed and detected all seven mutations. Hosted Apple build, host tests and Asahi KUnit passed at this head. The existing J773g row names the earlier head 3cf6a87.

Follow-ups: Please keep future changes of this size split into independently reviewable patches where practical.

@DjDeveloperr

Copy link
Copy Markdown
Contributor

J700 (G17P) row at 7ae56e51: not run yet. The kit refused itself before arming, on the stock kernel, and the reason matters for anyone testing this PR.

On stock (no ceiling), the base rehearsal saw an idle client's drm-resident go from 195 to 3 MiB while a busy client and a new one kept theirs. It came back intact at its next check. That is main's own idle-VM shrinker (aurora-idle-vm in mmu/residency.rs, there since 9afbd44): whenever reclaim of the whole system runs (kswapd here, after the Mac had just read a few GB of files), it releases every VM that has been idle for 2 s. It isn't memcg reclaim or swap: held pages are pinned, and the shrinkers aren't memcg-aware.

evict_idle() calls the same reclaim_idle_pages(), so "the idle client shrank" doesn't show the ceiling on its own. The J616s row in the description has no base arm, so it doesn't separate the two either (with 48 GB there was probably no system reclaim, but nothing measured it).

What separates them: drop clean page cache before the hold (echo 1 > /proc/sys/vm/drop_caches runs no shrinker), then read /proc/vmstat around the eviction. A shrink counts for the ceiling only if pageoutrun, pgscan_kswapd, allocstall_* and drop_slab didn't move. The new J700 kit does that on both arms, and the Neo lead has it now.

One thing the description could say: the release only unpins. The pages stay in RAM as shmem until reclaim swaps them out, so the ceiling frees no memory by itself. What it adds over main is that idle backing becomes reclaimable before there is pressure, and pinned memory stays near the ceiling.

@github-actions github-actions Bot removed the needs-hw-row No hardware row at the PR head (bot) label Dec 4, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor

J700 (MacBook Neo, A18 Pro, T8140, G17P, 8 GB) row at the exact head 7ae56e51538b: PASS. The head meets the bar.

Past its ceiling, this PR evicts the backing of an idle client and keeps the busy client resident. Main evicts nothing. Nothing else changes.

Setup:

  • Both arms boot the same Image 7.3.0-main571a6c45 and differ only in aurora.ko.
    • base: main's driver, boot b98b8972.
    • head: this PR, boot a3ff4b9d.
  • Head boots with aurora.mem_limit_pct=25. Before any GPU work, its held-memory ceiling read back as 1866 MiB (25 % of RAM).
  • Base keeps main's defaults. On main this parameter is a hard limit that refuses allocations, so 25 % would break the control.
  • The J700 was verified back on stock after each boot.

Eviction (the point of the PR). Three clients, sized from the 25 % ceiling (a and c 704 MiB, b 384–448 MiB). a goes idle, c stays busy, then b pushes the total past the ceiling:

run base: resident a, c (MiB) head: resident a, c (MiB)
(m) 772 → 772, 772 → 772 772 → 260, 772 → 772
(z) 708 → 708, 708 → 708 772 → 324, 772 → 772
  • Every buffer was checked after the round: 0 wrong words on any client, either arm.
  • In all four eviction windows the whole system did no reclaim. pageoutrun, pgscan_kswapd/khugepaged/proactive, allocstall_*, drop_slab and pswpout all stayed at +0, so the eviction is this PR's own, not the kernel's.
  • MemFree after the page-cache drop stayed above the footprint plus the zone watermark margin.

No regression (head vs base, same Mesa):

  • Vulkan CTS, every case recorded, 0 case differences:
    • memory: 2,122 cases
    • object management: 457 cases
    • sparse buffers: 249 cases
    • synchronization: 12,807 cases
    • synchronization2: 23,760 cases
  • Multi-queue memory CTS: 12,000 of 12,000 pass on both arms. During the run base refused 110 GPU allocations, head 0.
  • The 16 GPUBench rows are inside their bars.
  • Identity, the other memory and sleep checks, dmesg and the watchdog all PASS on both arms.

Not measured:

  • The default ceiling (half of RAM). An 8 GB J700 can't hold clients past it without the whole system reclaiming; an earlier version of this row showed that.
  • Head ran its whole boot at 25 %, so its other checks are this PR at 25 %, not at its default.
  • A game past the threshold.
  • Other GPU generations: the PR also touches shared driver files.

No conflicts. Main now has linux#4246, whose host test of the driver-map
charge builds Ledger::reserve() from memacct.rs; the next commit updates
it for this branch.

Signed-off-by: DjDeveloperr <hey@djdev.me>
…edger

asahi-driver-map-charge-tests.py (linux#4246) pastes Ledger::reserve(),
Usage and their helpers from memacct.rs into a host harness. With the limits
on memory that idle reclaim never releases, reserve() also calls limits(),
unreclaimable_limits(), release() and try_add_both(), and Usage counts a
client's unreclaimable bytes, so the harness no longer compiled.

Take those functions too when the tree has them, and give the model client
its unreclaimable counter. The test and all five of its mutations pass on
this branch and on main.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@github-actions github-actions Bot added the needs-hw-row No hardware row at the PR head (bot) label Dec 4, 2026

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed at f160c53ab761. That is 7ae56e51538b plus two commits of mine:

  • d132adfab6a2 merges main d2a4949f3013, with no conflicts.
  • f160c53ab761 changes a host test only.

The driver code is yours, unchanged. I found nothing in it that needs a change. The merge now waits only for the J773g row (below).

Checked

  • The quiet interval (the earlier review's point): fixed in 7ae56e51. evict_idle() reads NEXT_LOOK again after it takes IDLE_VMS, and the time is only written under that lock. The held-ceiling test checks this, and its unlocked-look-check mutation fails without the second read.
  • Locking:
    • A bind only try-locks the list and each VM, so it never waits behind a running walk.
    • Each listed VmShrinker owns a Vm. Nothing inside the walk can drop the last reference to a listed VM and take the list lock again.
    • An owner leaves the list before its shrinkers are freed.
  • Merged-code rules:
    • No new module parameter. mem_limit_pct and client_mem_limit_pct already exist; their new meaning is in the parameter text and the ABI doc.
    • The 67 % / 50 % shares are main's old defaults, now named constants. Half of RAM follows TTM's default, which the code cites.
    • Bit 49 is reported by the backends whose user VMs have a residency gate, not by SoC. It is still free on main and on aurora-wip.
  • Per generation:
    • G17 and M5 get the ceiling and the bit.
    • G15, T8122 and G18 call configure(). Their objects all go through admit() under the 67 % / 50 % shares, so they are refused where main refuses them. The ceiling walk finds no listed VM there.
    • G16 has its own probe and never calls configure(), on main as here. Nothing changes on G16.

Changed on the branch: main now has linux#4246. Its asahi-driver-map-charge-tests.py pastes Ledger::reserve() and Usage from memacct.rs into a host harness. The harness stopped compiling once reserve() called limits(), unreclaimable_limits(), release() and try_add_both(). f160c53ab761 takes those too when the tree has them, and adds the model client's unreclaimable counter. The test and its 5 mutations pass on this branch and on main.

Ran on the merge with main d2a4949f:

  • W=1 build: arm64 LLVM of drivers/gpu/drm/asahi/, aurora_defconfig with G15/G16/G17/M5/G18. It builds with the same 43 warnings as main.
  • Host tests (pinned container): 1184 of 1185 pass. ave-recovery-old fails the same way on main here: the source tree has no history for its old-commit control.

Rows

  • J700 (G17P): passed at 7ae56e51 (comment).
  • J773g (G16), owed:
    • The kit is sealed and handed to the M4 lead. Both arms boot one kernel and differ only in aurora.ko: main c042c5f9 against main c042c5f9 + 7ae56e51.
    • It checks:
      • GET_PARAMS and gpu_memory at default;
      • the 50 % sysfs limit with asahi-mem and heldvk;
      • 12,000 multi-queue CTS cases at 25 %;
      • the memory CTS subset;
      • gpubench and the kernel log.
    • The merge follows when it passes.

Follow-up, not for this PR: G16 never calls LEDGER.configure(). On the M4, nothing bounds memory that idle reclaim can't release, neither on main nor here.

mesa#1416's copy of the bit-49 comment now matches this branch word for word (fc0cf6a3a0bc there).

@DjDeveloperr

Copy link
Copy Markdown
Contributor

J773g (Apple M4 Mac mini, T8132 / G16) second-generation verification: PASS

  • Driver commits tested: 7ae56e51538b merged with main c042c5f9a8e6 on 7.3.0-j773g-w4248 (1.0.0b19-g06c581d1), module-only swap (a1: 28a0903b7319, b1: 31a3b547e1ea).
  • Note on current PR head: the PR head is now f160c53ab761, which adds only a conflict-free main merge and a host-test-only commit, with the driver commits unchanged.
  • Kit seal (sha256sum SHA256SUMS): f0e7a2b0efd89917026dcbe5e7256dcb67f8c78f4da7957c79a800bbebf8faa0
  • Retained run: work/j773g-linux3685-7ae56e51-20261204/results/run-20261204T085603Z
a1 (main c042c5f9): ok
b1 (main + #3685): ok
gem admitted at 50 %: a1 11584 b1 11584 MiB; heldvk held a1 11520 b1 11520 MiB; memq a1 {'NotSupported': 9156, 'Pass': 2844} b1 {'NotSupported': 9156, 'Pass': 2844}; CTS b1 [(102, 0), (25, 52), (2844, 0)]
VERDICT #3685 7ae56e51 J773g: PASS

@DjDeveloperr

Copy link
Copy Markdown
Contributor

Merge check of head f160c53ab761 with current main, before landing:

  • Driver range check: this PR's hunks in 13dc5a79c0ec..7ae56e51538b and in d2a4949f3013..f160c53ab761 are identical in all 11 driver, uapi and ABI-doc files (line offsets aside). Only tools/asahi/asahi-driver-map-charge-tests.py differs, which is the test-only commit. So the J700 v4 PASS and the J773g PASS at 7ae56e51538b cover this head.
  • Merged with main 85777c1c2e74: no conflicts (merge base d2a4949f3013). A warm arm64 Image.gz modules dtbs build with the J714s config gave 0 errors. make W=1 drivers/gpu/drm/asahi/ gave 53 warnings, the same set as main alone. run-host-tests.py in CI's ubuntu 24.04 image: 1191/1191, including asahi-driver-map-charge, held-ceiling, idle-vm-reclaim and the g16/g17 suites.
  • Merged with main 1675a62307d2 (32 commits later, with g16/g17 compute changes and a run-host-tests.py change): no conflicts. W=1 of drivers/gpu/drm/asahi/: the same 53 warnings as main alone. Host tests: 1197/1197.
  • Overlap with main: main's edits to g17/mod.rs (idle hold) and sysfs.c (idle-delay override bit) are in different functions from this PR's (the feature bit in get_params, the new gpu_memory fields). Main's newer g17 commits change compute-pool kill handling and don't touch GEM, VM residency or memory accounting. Bit 49 has no other user in the merged tree.

Merging.

@DjDeveloperr
DjDeveloperr merged commit 16a732e into aurora-silicon:main Dec 4, 2026
11 checks passed
@RyanTheTide

Copy link
Copy Markdown
Contributor

GPU throughput regression on G17P after this merge (A18 Pro, J700).

A/B with one variable, the kernel. Both arms used the same Stage 2 (aura 1.0.0b19 + main's t8140-j700.dtb + U-Boot 5c0d5fe1), the same boot path and a default cmdline. glmark2 ran on zink/Borealis, three runs per arm:

kernel glmark2
main 1675a62 (parent of this merge) 10256 / 10335 / 10124
main 16a732e (this merge) 7846 / 8409 / 7877

That is about -22%. The other rows came out equal on both arms: 0 failed units, 0 kernel errors or oopses, DCP 2/2, s2idle 1/1, ANE. The device has 8 GB, and glmark2 stays far below half of RAM, so the ceiling itself should never trigger. The slowdown more likely comes from the per-bind ledger and eviction path that this change adds. I haven't profiled it.

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) door:one-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