Skip to content

drm/asahi: g17: scale the tiler heap's normal maximum with memory - #2724

Merged
DjDeveloperr merged 10 commits into
aurora-silicon:mainfrom
jgoyvaerts:m4pro/g17-tvb-normal-max-v2
Dec 1, 2026
Merged

DjDeveloperr merged 10 commits into
aurora-silicon:mainfrom
jgoyvaerts:m4pro/g17-tvb-normal-max-v2

Conversation

@jgoyvaerts

@jgoyvaerts jgoyvaerts commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What: The NEO tiler heap's normal maximum (BM+0x80) scales with memory (a 64th of RAM, 1,118..=3,353 blocks) instead of a fixed 1,118 blocks, so big scenes stop partial-rendering every frame on large-memory Macs. To keep that bounded, heap growth is made in 8 MiB extensions, placed only in the growth arenas, and charged to the client through main's KernelObject::client_backing() (#2501). A growth that runs out of memory or room keeps the extensions it made. Supersedes #2186. New since a64f33ae2157:

  • 010c1e0d94e0: compact objects (primary blocks, page lists, views, records, TPC) go to the target window before the growth arenas, so they no longer take heap room there.
  • b004eb6f131c: host growth ahead of need is capped at a fair share of the VM's growth arenas, so three or more heavy render queues in one VM split them instead of the first taking all.
  • 5cf1361ccc52: a host growth that adds no block emits a HEAP event (HEAP_HOST_IDLE/HEAP_HOST_BUSY, no growth).

Tested: J616s (M4 Pro, 48 GiB, 25G83) at head a64f33ae2157 on 7.3.0-m4.195: rows 1-5 below pass (normal maximum 3,353 blocks from the heap trace, the sweep at 27/41/55/82/109-117/412 ms, four heavy clients and three queues in one VM, shrink in 8 MiB steps and to the floor after 10 s idle, and on one boot with a 952 MiB client limit the growth stopping at 2,744 blocks with frames still rendering), 0 GPU recoveries/AVC/failed units, no kernel messages (results). KUnit (arm64 qemu) at a64f33ae2157: 853/854 passed, 1 skipped. g17 host tests at a64f33ae2157: all 220 runs pass. At head 5cf1361ccc52: KUnit (arm64 qemu) 860 tests, 859 passed, 1 skipped, with the new asahi_g17_tvb_share (one, two and three heavy heaps, required blocks above the share); g17 host tests all 220 pass; the asahi module compiles with 0 Rust errors at b004eb6f131c and at the head. The J616s rows above ran at a64f33ae2157, before the three new commits. At head 5cf1361ccc52 on 7.3.0-m4.197, J616s: one VM with three render queues, each heap grows to its fair share of 2,288 blocks and every queue renders (82-109 ms at 30k, 413-425 ms at 45k); with two queues both reach 3,353; dEQP-GLES31.functional.fbo.no_attachments.maximums.* 5/5 Pass, including 16384x16384 at 0x and 4x MSAA; 0 GPU recoveries/AVC/failed units (results).
Risk: two-way door · G17 GPUs: M4 Pro and M4 Max (t6040, t6041), A18 Pro (t8140), M5 (the 8 MiB extensions, the per-extension charging and compact-window room check, and stop-short growth). Below 8.7 GiB the normal maximum stays 1,118 blocks. Fair share (b004eb6f131c): one or two heavy render queues per VM still reach the normal maximum; three or more each get their primary plus (free arena slots + growth the VM's heaps hold) / heaps, 2,288 blocks with three. Required blocks and firmware grow requests are not capped. A heap made after the others grew past the new share gets only the free room until their usage-driven shrinks return it.
Not yet: a J700 (A18 Pro) heavy-GLES run with the BM+0x80 readback; an M5 run of a heap growth that stops short.

Details

On 25G83 the tiler heap grows on the host only. Before a render, the host grows it to 3x the last high-water, capped at the heap's normal maximum, and also writes that cap to the firmware in BM+0x80. A scene bigger than the cap partial-renders on every frame. On main the cap is Variant::tvb_normal_blocks: the full table (3,353 blocks) on the 32-core M4 Max, a fixed 0x45e (1,118 blocks, 140 MiB) on every other NEO heap.

Series

  1. Grow the tiler heap in extensions of at most 8 MiB. A growth used to be one backing object, and a shrink only gives back whole trailing ones. A 900 -> 2,700 jump was one 225 MiB extension. The active shrink returned it only after 450 credit periods, and the idle shrink not at all while its floor stayed above 900. Now the active shrink gives back 8 MiB every 16 periods, and the idle shrink stops within 8 MiB of its floor. A full table is 53 extensions. M5 heaps are never shrunk; their growth is split the same way (64 blocks, 32 MiB), so it can stop short as in 2.
  2. Grow only in the two tiler-heap growth arenas, as far as they go. Growth used to spill from the growth arenas (3,321 + 3,353 blocks per VM) into the render-alias and target-record windows, and the VM's next target record or growth then failed with ENOSPC. Growth now stays in the growth arenas (cfg::tvb_growth_ranges()). A growth that runs out of arena space, M5 compact-window room or memory keeps the whole extensions it made, and the pass partial-renders within that heap, as it does after a refused firmware grow request. An idle growth still fails if the heap would stay below what the render's layout requires. After a growth stops short, the host grows beyond the required blocks again only a shrink period later (defer_growth).
  3. Charge tiler-heap growth to the pair's client. Each extension of a client VM's pair is admitted with memacct::LEDGER.admit() against the client's and the device's limits (defaults 50% and 67% of RAM) before it is allocated, and counted as the client's held memory (fdinfo drm-resident-system, gpu_memory). A refusal ends the growth there, as in 2. Pages are not added to a process's MM_SHMEMPAGES, as for the M5 pools, because growth also runs from the firmware grow worker. The NEO heap's primary backing, sized by the render target, stays a kernel object.
  4. Scale the normal maximum with memory (policy below).
  5. Merge of main and charge tiler-heap growth through KernelObject::client_backing(). Main's drm/asahi: g17: M5: render large passes instead of losing the device after 26 s, refuse those that cannot fit, and account their memory to the client #2501 charges an M5 pair's parameter buffer (primary and growth) through client_backing() and checks the compact window for room before allocating. Growth now uses that one path for both geometries: Tvb::allocate() with the pair's client. On M5 each extension checks the window for room for its own blocks before it is allocated. The series' own Extension wrapper and KernelObject::backing_user_charged() are gone. See the merge comment for the behaviour changes this has on M5.
  6. Place compact objects in the target window before the growth arenas. Compact allocations searched the render-alias window, both growth arenas, then the 320 MiB target window. Once the 2 MiB render-alias window was full, each pair's compact objects (about 108 block slots at 3456x2234) landed in the first growth arena. On main too, but it bites only once a heap can fill a whole arena. They now fall back to the arenas only when the target window is full.
  7. Cap tiler-heap growth ahead of need at a fair arena share. The two arenas hold two heaps at the normal maximum, and a VM has any number of pairs. Host growth beyond a render's required blocks stops at the heap's primary plus (free arena slots, from the VM's address space, + the growth the VM's heaps hold, from its render pool cache) / (the VM's heaps). A heap's own growth or shrink leaves the share unchanged, and no shrink depends on it, so it cannot cause grow/shrink ping-pong. A growth the share cuts to nothing waits a shrink period, as a refused one does.
  8. Trace a host tiler-heap growth that adds no block, from the render preparation, which knows the source (the firmware path already traces HEAP_FIRMWARE_REFUSED).

Policy

The normal maximum is a 64th of si_meminfo() memory, clamped to fw::NORMAL_MAX_BLOCKS..=cfg::TVB_MAX_BLOCKS (1,118..=3,353 blocks), and never below the firmware variant's value (max(variant, scaled)). There is no rounding. The cap is per render pair; 1-3 bound what all pairs of a client and of the device hold together. BM+0x7c (the heap capacity, 3,354 slots) is unchanged. The memory is memacct::total_ram_bytes(), which also sizes the memory limits.

Memory (si_meminfo) Normal maximum
up to 8.7 GiB 1,118 (floor: BM+0x80 stays 0x45e * 4 pages)
24 GiB 3,072
from 26.2 GiB 3,353 (block table)

The A18 Pro (8 GiB) keeps 1,118. The mesh-shading floor (mesh_floor(), aurora.g17_mesh_tvb_floor) stays the variant value and is not raised by memory. An M4 Max gets 3,353 from either rule.

Why a 64th

All three reasons come from our own measurements:

  • Upper bound: on the 48 GiB J616s, macOS 26.6.2 runs the GPU with BM+0x7c = 19,737 and BM+0x80 = 6,579 blocks (read live). That is 1/60 of the memory. The fixed 1,118 is 1/59 of 8 GiB. A 64th stays below both.
  • Floor: at 8 GiB a 64th would be 1,024 blocks, so the clamp keeps 1,118.
  • The J616s's measured behaviour: 46.6 GiB usable gives 5,959 blocks, clamped to 3,353, the cap the sweep below measured. The exact share only matters between 8.7 and 26.2 GiB, which on this backend is the 24 GiB M4 Pro, and there a 64th errs low.

Cleanups: memacct::total_ram_bytes() replaces a duplicate memory helper, and Layout::initialize() (M5 graph) reads GraphArgs::normal_blocks, as fw::Graph::init() does.

J616s rows at this head

Rows 1, 2, 3 and 5 ran on 7.3.0-m4.195 at a64f33ae2157 (results in the comment linked above). All GPU runs go through our GPU queue. 0 GPU recoveries, 0 AVC, 0 failed units and no new kernel warnings in every row.

  1. BM+0x7c / BM+0x80 of a live NEO heap: 13,416 / 13,412 pages (3,354 slots, 3,353 blocks).
  2. The single-client triangle sweep (N = 10k ... 45k): about 32 / 41 / 55 / 83 / 110-138 / 417 ms.
  3. Several heavy clients at once: four triangle-test processes at N = 30,000, plus one process with three render queues in one VM. gpu_memory and each client's fdinfo drm-resident-system show the tiler growth per client. In the one-VM case, the third queue's growth stops at the arena edge, and its frames keep rendering (slower) without ENOSPC.
  4. Client limit: one boot with asahi.client_mem_limit_pct=2 (952 MiB per client), one client with a 700 MiB renderbuffer, then N = 30,000 and 45,000. The heap grew once, 1,400 -> 2,744 blocks, refused went 0 -> 5, the client ended at 970,400 KiB, and every frame rendered (82-89 ms, 413-421 ms), with no kernel messages. The runtime gpu_mem_limit_pct file sets the device limit too, which bites first.
  5. Shrink: after the sweep, the heap returns in 8 MiB steps while active (trace HEAP_SHRINK), and to its floor after 10 s idle.

HW rows wanted on machines we don't have

  • J700 (A18 Pro, 8 GiB): a heavy GLES scene that grows the heap, with BM+0x80 read back as 4,472 pages (1,118 blocks), drm-resident-system rising with the growth, and 0 GPU recoveries / AVC / failed units.
  • M5: a pass whose growth stops at the client limit or the compact window: it renders (partial renders) instead of failing, if its layout's required blocks fit.
  • 24 GiB M4 Pro (nice to have): the scaled range, BM+0x80 about 12,000 pages.

Not done

  • The heap's capacity stays at 3,354 slots. Raising it needs a memory-sized NEO graph and VA layout.
  • The growth arenas are not resized; 7 shares them fairly between a VM's heaps.
Evidence

At head 5cf1361ccc52

  • KUnit, arm64 qemu, asahi/SEP/ISP config: 860 tests, 859 passed, 1 skipped. asahi_g17_tvb_limits (2) and asahi_g17_tvb_share (5) pass.
  • tools/asahi/run-host-tests.py: all 220 g17 runs pass; the same 29 non-g17 runs fail as at a64f33ae2157.
  • Module compile check (running kernel's config) at b004eb6f131c alone and at the head: 0 Rust errors, no warnings in the changed files.

At head a64f33ae2157 (main a851ca0edfc9 merged)

  • KUnit, arm64 qemu, asahi/SEP/ISP config, on the merge 280009109649 and on the head: 854 tests, 853 passed, 1 skipped, each. asahi_g17_tvb_limits passes.
  • tools/asahi/run-host-tests.py: every g17 run passes (220). The 29 failing runs are g15, DCP, M3 uAPI and SEP tests that fail on plain main on this build host too (no rustup 1.93.1 toolchain; a git ref the checkout lacks).
  • The earlier head 001d7834eb78 was compile-checked commit by commit with arm64 defconfig + asahi.config, LLVM=1, W=1.

J616s (M4 Pro, 48 GiB, GPU firmware 25G83), earlier revision #2186

Off-screen GLES: N screen-spanning triangles into a stored 3456x2234 RGBA8 + D24S8 target, waiting for each frame (glFinish). 0 GPU recoveries. "Before" is a 1,118-block cap and "after" a 3,353-block cap, both on our m4.166 test kernel with #2186, which wrote the same 3,353 on this Mac. m4.166 also carries #1902 and #1986, which only affect pairs that never go idle.

N Before (1,118) After (3,353)
10,000 32 ms (3.2 us/tri) 32 ms
15,000 146 ms (9.7 us/tri) 41 ms (2.8 us/tri)
20,000 193 ms 55 ms
30,000 281 ms 83 ms
40,000 395 ms 110-138 ms
45,000 not run 417 ms (past 3,353 blocks: partial renders)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Good writeup. The sizing comes from a memory share measured on the machine, not a per-model table, and the 15k-40k triangle numbers make the case. An adversarial read of 0a2a5c2:

  1. The cap is per heap, so it multiplies. Layout::neo(memory_bytes()?) is evaluated per buffer::Manager, i.e. per render queue's tiler heap. So 1/64 of RAM is the ceiling for each heavy client, not for the GPU. On a 16 GiB Mac, a few heavy GL/Vulkan clients (a game, a browser compositor, a benchmark) can each hold 256 MiB of heap where they held 140 MiB before. Combined with the shrink policy (one 512 KiB step per second, only after 10 s idle), a heap that peaked at 3,353 blocks takes about nine minutes to return to the old cap. Two things would settle it: say whether the growth pages are charged to the client (memacct/memcg), and add a row with several clients at once on a smaller-memory Mac, or argue why that isn't a concern.

  2. The 9-26 GiB range is the untested part, and it's where the formula changes behaviour. At 8 GiB the clamp gives the old value, and at 26+ GiB the block table caps it, both covered by your J616s run. The scaled range in between is 16 and 24 GiB M4 and M4 Pro machines. A 16 GiB M4 (Mac mini J773g or a Mac16 MacBook Pro) running your tiler test, with BM+0x80 read back as 2,048, would show the scaled path itself working.

  3. On the J700: neo_normal_blocks() of anything at or below 8 GiB is NORMAL_MAX_BLOCKS (your KUnit case), and si_meminfo() on an 8 GiB Mac reports less than 8 GiB. So the A18 Pro write is unchanged by construction. A J700 row only needs the BM+0x80 readback and the usual no-regression checks, not the full CTS subset.

Assisted-by: LLM (Claude:Opus 5.5)

@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.

Adversarial review of head 0a2a5c2b8f6543f30ab09bf035d9f621f0581b16 against the pre-PR checklist. Holding approval and requesting changes on the memory-accounting/VA-exhaustion implications and missing hardware evidence on this head.

Code & resource-limit findings

  1. Per-heap RAM multiplication is unattributed to clients and bypasses GPU memory admission limits.
    Following up on Ryan's point #1 directly from gem.rs and memacct.rs: Tvb::prepare_growth() allocates each extension via KernelObject::backing() -> gem::new_kernel_object_wc() -> memacct::Charge::kernel(&memacct::LEDGER, size) (gem.rs:324). In this driver:

    • Kernel objects are not charged to any client (Client) or process mm (MM_SHMEMPAGES), so the OOM killer does not score the offending client for them.
    • Kernel objects bypass both LEDGER.limit and LEDGER.client_limit (memacct.rs:215: "Kernel objects share the device limit but are never refused"), while increasing kernel_resident and shrinking the budget left for other clients' user BOs.
    • set_mapping_held(&gem, true) pins the shmem pages as AS_INACCESSIBLE | AS_UNEVICTABLE (unswappable, unmigratable), and off-lock growth runs in scheduler/workqueue context rather than reliably under the submitting task's memcg.
      Because Layout::neo(memory_bytes()?) applies per physical render pair (RENDER_SLOTS = 64, and one logical queue can hold 2 pairs), raising the cap from 140 MiB to 256 MiB (16 GiB Mac), 384 MiB (24 GiB), or 419 MiB (≥26.2 GiB) multiplies per active heavy pair — e.g., 4–8 heavy pairs on a 16 GiB Mac can pin 1–2 GiB of unswappable, unattributed, limit-bypassing kernel memory.
  2. Whole-extension shrink interacts poorly with the larger 3× growth steps.
    In buffer.rs:1012-1050, 1266-1285:

    • While a client stays active on light frames (now - last_busy < 10s), shrink_target() earns SHRINK_STEP_BLOCKS = 4 (512 KiB/s) and only shrinks once credit >= last (the entire last extension), resetting credit = 0 on any period above 1/4 capacity. A single 3× growth jump from e.g. 900 -> 2,700 blocks creates a 1,800-block (225 MiB) extension that takes 7.5 minutes of uninterrupted low load to release while active.
    • Because Manager::shrink() can only drop whole trailing KernelObject extensions (kept - size < target), if shrink_floor() sits anywhere above the pre-jump size (e.g. 950 blocks after a 900 -> 2,700 jump), that 225 MiB extension cannot be shrunk even after 10 s idle until busy_peak drops below 450 blocks.
      Raising normal_blocks up to 3× makes both the peak footprint and this coarse-granularity retention substantially heavier. Please either bound/attribute TVB growth (or cap individual extension chunk size so shrink can reclaim incrementally) or demonstrate multi-client pressure behavior on a 16 GiB Mac.
  3. Multi-pair compact-VA spillover into TARGETS within a single VM (hw/t8140.rs:346-355).
    compact_ranges() provides TVB_MAX_BLOCKS slots in TVB_GROWTH (pair 0) and TVB_MAX_BLOCKS in second (pair 1), and then falls back to TARGETS (320 MiB, shared with render targets). Previously at 1,118 blocks/pair, up to 6 render pairs in one VM fit in the two TVB arenas without touching TARGETS. At 3,353 blocks/pair (≥26.2 GiB Macs), just 2 heavy pairs in one VM fill both TVB arenas completely, so a 3rd growing render pair in the same VM spills TVB blocks into TARGETS and then fails with ENOSPC.

  4. Minor cleanups:

    • buffer::memory_bytes() (buffer.rs:319) duplicates memacct::total_ram_bytes() (memacct.rs:104).
    • GraphArgs.normal_blocks is populated for both NEO and M5 (buffer.rs:819), validated/used by fw::Graph::init(), and silently ignored by Layout::initialize() (which reads self.normal_blocks instead).

Evidence & checklist blockers

  • No hardware boot or regression run on current head 0a2a5c2b (Checklist §5): the J616s numbers in the PR body are from an older superseded revision (#2186) on m4.166 (which also carried #1902 and #1986), and no regression run (0 SELinux denials, 0 failed units, 0 new kernel errors) is reported for this head.
  • No conformance run for a performance change (Checklist §5): checklist requires a same-machine A/B with conformance unchanged on every GPU generation the change applies to.
  • Untested scaled range (9–26 GiB) & A18 Pro: as noted by Ryan and in the PR body, no 16 GiB / 24 GiB Mac has exercised the non-clamped formula (BM+0x80 = 2,048 / 3,072), and the J700 (A18 Pro) readback/no-regression row is still pending.
  • CI: host-tests passed on 0a2a5c2b.
  • Checklist §1–§4 & §6: Pass on code (RAM-scaled policy with no chip/board/firmware gates, default cmdline, human-only Signed-off-by in commit, clean-room live measurements). Minor attribution nit: PR body ends with Assisted-by: LLM (Claude:Opus 5.5) instead of Anthropic:Claude Opus 5.5.

Assisted-by: LLM (Google:Gemini 4 Neon)

A growth of the tiler heap is one backing object, and a shrink can only
give back whole trailing growth objects. A heap that grew from 900 to
2,700 blocks in one step holds a single 1,800-block (225 MiB) extension:
the active shrink returns it only after 450 periods of shrink credit,
and the idle shrink cannot return it at all while its floor sits above
900 blocks.

Build each growth from extensions of at most 64 blocks (8 MiB). The
active shrink then gives back 8 MiB every 16 periods of credit, and the
idle shrink stops within 8 MiB of its floor. A full block table is 53
extensions.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
… they go

Tiler-heap blocks are placed in the first of the compact client arenas
with room: the render-alias window, the two tiler-heap growth arenas
(3,321 and 3,353 blocks), then the target-record window. Growth that
fills both growth arenas, for instance three pairs of one VM at 3,353
blocks, then takes target-record space, and the next target record or
growth of that VM fails with ENOSPC, and the render with it.

Place growth only in the two growth arenas. A growth that runs out of
them or of memory keeps the whole extensions it made, and the tiling
pass partial-renders within that heap, as it does when a firmware grow
request is refused. An idle growth still fails if the heap would stay
below the blocks the render's layout requires. After a growth stopped
short, the host grows the heap beyond those blocks again only a shrink
period later, as the busy growth already does after a refusal: every
attempt allocates and maps afresh.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Tiler-heap growth is allocated as kernel objects: they count towards the
device total, but are charged to no client, are never refused by the
device or the per-client limit, and are pinned. The client sizes this
growth through its renders, and every render pair of every client can
hold its own, so many heavy pairs can pin a lot of memory that no limit
bounds and no client is accountable for.

Admit each growth extension of a client VM's pair against that client's
and the device's limits, and count it as the client's held memory, as
the M5 pools are. A refused extension ends the growth there: the tiling
pass partial-renders within the heap it has, and an idle growth fails
with ENOMEM only if the heap would stay below what the render's layout
requires. Kernel pairs keep kernel objects.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
The tiler heap of a 25G83 render grows on the host only: before a render
the host grows it to three times the last high-water, capped at the heap's
normal maximum, which also goes to the firmware in BM+0x80. A scene larger
than that cap partial-renders on every frame. The cap is the fixed 0x45e
(1,118 blocks, 140 MiB) on every NEO-layout heap, whatever the memory.

Make the cap a 64th of the memory si_meminfo() reports (memacct's
total_ram_bytes(), which also sizes the memory limits), clamped to
NORMAL_MAX_BLOCKS..=TVB_MAX_BLOCKS (the block table). BM+0x7c, the
heap's capacity, is unchanged. The cap holds for each render pair; the
growth up to it is charged to the pair's client and bounded by its and
the device's memory limits, and by the VM's growth arenas. Both graph
layouts take the normal maximum from GraphArgs.

The share comes from three measurements:

- On the 48 GiB J616s, macOS 26.6.2 runs the GPU with BM+0x80 = 6,579
  blocks (read live), 1/60 of the memory. The fixed 1,118 is 1/59 of
  8 GiB. A 64th stays below both, so above the floor the cap is never a
  larger share of memory than the firmware is known to run with.
- At 8.7 GiB and below the clamp keeps 1,118: BM+0x80 stays
  0x45e * 4 pages, and the 8 GiB A18 Pro (and its mesh floor) is
  unchanged.
- On the J616s (46.6 GiB usable) a 64th is 5,959 blocks, clamped to the
  table's 3,353. An off-screen GLES test draws N screen-spanning
  triangles into a stored 3456x2234 RGBA8 + D24S8 target and waits for
  each frame. With 1,118, a triangle costs 3.0 us up to N = 14,500 and
  9.7 us from N = 15,000. With 3,353, 3.0 us holds up to N = 40,000:
  N = 20,000 takes 55 ms a frame instead of 193 ms, N = 30,000 83 ms
  instead of 281 ms. At N = 45,000 the scene passes 3,353 blocks and
  partial-renders as before.

A 16 GiB Mac gets 2,048 blocks, a 24 GiB Mac 3,072; from about 26.2 GiB
the table's 3,353 is the limit.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
@jgoyvaerts
jgoyvaerts force-pushed the m4pro/g17-tvb-normal-max-v2 branch from 0a2a5c2 to 001d783 Compare November 22, 2026 02:10
@jgoyvaerts
jgoyvaerts marked this pull request as draft November 22, 2026 02:11
@jgoyvaerts

jgoyvaerts commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks both. New head 001d7834eb78 (rebased on integration/aurora 606d37ec77a5) adds three commits in front of the scaling commit:

  1. Shrink granularity: growth is built from extensions of at most 64 blocks (8 MiB), g17/buffer.rs:403. The active shrink gives back 8 MiB every 16 credit periods, and the idle shrink stops within 8 MiB of its floor. Before, 900 -> 2,700 was one 225 MiB extension that took 450 periods to return.
  2. VA: growth is placed only in the two growth arenas (hw/t8140.rs:347, 3,321 + 3,353 blocks per VM), never in RENDER_ALIASES/TARGETS. A growth that runs out of arenas or memory keeps its whole extensions, and the pass partial-renders (g17/buffer.rs:1264). An idle growth still fails only below the layout's required blocks (HostGrowth::Idle { required, target }). Growth beyond that is retried a shrink period later (defer_growth, g17/buffer.rs:1112). A third heavy pair in one VM no longer reaches ENOSPC.
  3. Accounting: each extension of a client VM's pair is admitted against the client's and the device's limits and counted as the client's held memory, as the M5 pools are (g17/buffer.rs:521). A refusal ends the growth there. To Ryan's question: memacct, yes; process RSS, no (as for M5 pools, because the firmware grow worker also grows); memcg charging of the shmem pages is unchanged.

Cleanups: memacct::total_ram_bytes() replaces the duplicate helper (g17/buffer.rs:867), and Layout::initialize() reads args.normal_blocks (g17/buffer/layout.rs:82).

Tests on this head: each commit compile-checked with arm64 defconfig + asahi.config, LLVM=1, W=1; KUnit arm64 qemu 734/736 (1 skip UCLAMP, 1 unrelated ISP sysfs failure); host tests --only g17 90/90. The J616s boot is pending; its plan is in the description (BM+0x80 readback, the sweep, several heavy clients at once, a client-limit refusal run, shrink steps). The PR is a draft until that row lands.

@RyanTheTide, we have no 16 GiB M4 or J700. Could you run the 16 GiB tiler test with BM+0x80 read back as 2,048 blocks, and on the J700 the BM+0x80 = 1,118 readback with 0 recoveries/AVC/failed units?

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks, this answers the earlier review. At 001d783:

  • Charging and the per-pair multiplication: fixed. Each extension is admitted against the client's and the device's limits and counted as held memory (buffer.rs:521-532), so the sum over a client's pairs is bounded by the ledger, not by 1/64 of RAM per pair. The 8 MiB extensions (buffer.rs:403) fix the shrink granularity, and growth no longer spills into the target-record window (t8140.rs:347, buffer.rs:563). The unwind order on a stop-short growth is right: mappings are dropped before their extensions, and a firmware request that gets 0 blocks is answered as refused (grow.rs).
  • The scaled range: my earlier ask was wrong. NEO heaps exist only on the G17 backend (apple,agx-t8140, t6040, t6041; driver.rs:171-179). The M4 (T8132) has no backend here, so no 16 GiB Mac reaches this code, and the 16 GiB row in the table and in "HW rows still wanted" can go. The only real configuration between the floor and the block table is the 24 GiB M4 Pro, which lands at roughly 2,900-3,000 blocks, a little below the 3,353 the J616s sweep measured. A 24 GiB M4 Pro row would be nice to have, but it shouldn't block this.
  • J700: the readback is still wanted, and the series now changes the A18 Pro too: growth in 8 MiB charged extensions, placed only in the growth arenas, which can now be refused. Please add a heavy GLES scene that grows the heap on the J700 at 001d783, with BM+0x80 = 4,472 pages, drm-resident-system rising with the growth, and 0 GPU recoveries.
  • Nothing at this head has run on hardware yet. The J616s list in the body (rows 1-5) covers the new paths. Row 4 (client limit bites, heap stops short, frames keep rendering) is the only test of the stop-short path, because the KUnit tests cover only neo_normal_blocks().

No new code issues found.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

@jgoyvaerts status against integration/aurora daa9e2d: the four commits merge cleanly, nothing in the files they touch has changed on the tip since 606d37e, and nothing equivalent has landed. The g17 host tests pass on the merged tree (90/90). What is still open is hardware evidence at 001d783: the J616s rows 1-5 from the description (row 4, a growth stopped by the client limit, is the only test of the stop-short path) and a J700 run with a heavy GLES scene that grows the heap, with the BM+0x80 readback. The change request on file is against 0a2a5c2, so it also needs a re-review at this head.

Main made the NEO tiler heap's normal maximum a firmware-variant value
(Variant::tvb_normal_blocks, 492ea7e): the full table, 3,353
blocks, on the 32-core M4 Max where all four clusters tile, the fixed
1,118 elsewhere. This branch scales it with memory (a 64th of RAM,
clamped to 1,118..=3,353).

Conflicts in g17/buffer.rs Manager::new() and g17/fw/buffer.rs. Kept
both: main's check of the variant value stays, and the heap's normal
maximum is the larger of the variant value and the memory-scaled one,
so neither lowers the other (J616s 48 GiB: 3,353; 32-core M4 Max:
3,353; 8 GiB A18 Pro: 1,118).

The mesh-shading floor (aurora.g17_mesh_tvb_floor) stays main's
variant value and is not raised by memory: this branch had pinned it
to 1,118, which would have lowered it on the 32-core M4 Max.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
@jgoyvaerts

Copy link
Copy Markdown
Contributor Author

Merged main 70381bd406e0 into the branch; the new head is 6a82d2790444, a plain push on top of 001d7834eb78.

Main's 492ea7e made the NEO heap's normal maximum a firmware-variant value, Variant::tvb_normal_blocks: the full table (3,353 blocks) on the 32-core M4 Max, the fixed 1,118 elsewhere. This branch scales the normal maximum with memory instead. The conflicts are in g17/buffer.rs Manager::new() and g17/fw/buffer.rs. The resolution changes behaviour, so please look at both points:

  • Normal maximum (BM+0x80): the larger of the variant value and the memory-scaled one (layout.normal_blocks.max(args.normal_blocks), after main's check of the variant value). Neither lowers the other: the J616s (48 GiB) gets 3,353, the 32-core M4 Max 3,353, and the 8 GiB A18 Pro 1,118.
  • Mesh-shading floor (aurora.g17_mesh_tvb_floor, on by default): stays main's variant value, not raised by memory. The Manager keeps it as variant_normal_blocks. This branch had pinned it to the fixed 1,118, which after the merge would have lowered it on the 32-core M4 Max.

Checks at the new head: asahi/SEP/ISP KUnit 797/798 (1 skip), and all 93 g17 host tests pass. Some host tests fail on this machine on plain main too: g15/DCP/M3-uAPI/SEP want a rustup 1.93.1 toolchain it doesn't have, and apple/atc-t8132-usb3 fails to compile its dwc3_apple_idle_rpm stub since #2299.

Still open, as before: the J616s rows 1-5 at the head, the J700 heavy-GLES run with the BM+0x80 readback, and your re-review.

Main's aurora-silicon#2501 charges an M5 render pair's parameter buffer to its client
through KernelObject::client_backing(), and checks the M5 compact window
for room before allocating blocks. This branch charges tiler-heap growth
to the client per extension and keeps the extensions made so far when a
growth stops short.

Conflicts in g17/buffer.rs and g17/object.rs, resolved as the union:
- the primary blocks use main's Tvb::allocate(): M5 checked for room and
  charged to the client, NEO kernel memory, as before;
- an M5 block is mapped with main's PairObject::ParameterBlock.map();
- each growth extension of an M5 heap checks the compact window for room
  for its own blocks before it is allocated, so a window without room
  ends the growth with ENOSPC there, as a full growth arena does on NEO;
- growth keeps this branch's charging (Tvb::extension()), so it is
  counted once.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
…_backing()

Since the merge of main, a tiler heap's growth has two ways to charge
its client for the same thing. Tvb::extension() admits each extension
against the client's and the device's limits, allocates it with
KernelObject::backing_user_charged() and keeps the charge beside it in
an Extension. Main's KernelObject::client_backing(), which M5 primary
blocks use, does the same and keeps the charge in the object. It also
admits the page-rounded size of the object, which is what it allocates
and what the ledger later releases.

Allocate every growth extension with Tvb::allocate() and the pair's
client instead, so all parameter-buffer backing comes from one place:
a client's growth through client_backing(), on M5 after checking the
compact window for room for that extension's blocks, which the merge
did inline. Extension, Tvb::extension() and backing_user_charged() go.
A heap's primary blocks are unchanged: charged on M5, kernel memory
on NEO.

No change in behaviour: the same extensions are admitted, checked for
room on M5, allocated and released in the same order. An extension is
a whole number of 16 KiB pages (128 KiB NEO blocks, 512 KiB M5 blocks),
so its admitted size is unchanged.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
@jgoyvaerts

Copy link
Copy Markdown
Contributor Author

Merged main a851ca0edfc9 (with #2501) into the branch. The new head is a64f33ae2157, a plain push on top of 6a82d2790444: the merge 280009109649, then one commit on top.

#2501 and this series both charged tiler-heap growth to the client, by two routes: #2501 through KernelObject::client_backing() (M5 only), this series through its own Tvb::extension() + backing_user_charged() (both geometries). Both admit against memacct::LEDGER before allocating, so they do the same thing. #2501 also checks the M5 compact window for room before allocating and allocates a growth as one backing.

Resolution.

  • The merge 280009109649 keeps both sides: primary blocks through main's Tvb::allocate(); M5 blocks mapped with main's PairObject::ParameterBlock.map(); growth through this series' extensions. Each M5 extension calls check_room() for its own blocks before it is allocated.
  • a64f33ae2157 ("charge tiler-heap growth through KernelObject::client_backing()") drops the duplicate route. Every growth extension is now Tvb::allocate(.., vm.memory_client()), so all parameter-buffer backing goes through client_backing(). Extension, Tvb::extension() and KernelObject::backing_user_charged() are gone. No behaviour change: each extension is a whole number of 16 KiB pages, so client_backing()'s page-rounded admit is the same size.

Behaviour changes against main, please look at these:

  1. NEO growth is charged to the client. On main, NEO growth is kernel memory that is never refused (drm/asahi: g17: M5: render large passes instead of losing the device after 26 s, refuse those that cannot fit, and account their memory to the client #2501 left "other G17 parts unchanged"). Here each 8 MiB extension is admitted against the client's and the device's limits, and drm-resident-system includes it. The NEO primary blocks stay kernel memory, as on main.
  2. M5 growth stops short instead of failing whole. On main, an M5 growth over the client limit or the window's free room fails as a whole: the idle host growth fails the render, even when the render's required blocks would fit, because main's target already includes the 3x feedback, and a firmware request is declined. Here an M5 growth is made of 64-block (32 MiB) extensions, each admitted and checked for room before it is allocated. On ENOMEM or ENOSPC it keeps the extensions it made, and the render fails only if the heap stays below its layout's required blocks. The pass partial-renders, as at the normal maximum. A firmware request that gets 0 blocks is still answered as refused.
  3. The M5 room check is per extension, not once for the whole growth. That follows from 2: a check for the whole growth would refuse a growth that partly fits. It keeps drm/asahi: g17: M5: render large passes instead of losing the device after 26 s, refuse those that cannot fit, and account their memory to the client #2501's guarantee per extension: no backing is allocated for blocks the window has no room for. Like drm/asahi: g17: M5: render large passes instead of losing the device after 26 s, refuse those that cannot fit, and account their memory to the client #2501's check, it is no placement promise, and a mapping that still fails with ENOSPC drops its own extension only.
  4. Consequence of 2 and 3 on M5: a growth can now take the client's last window room or memory budget where main would have taken none. M5 heaps are never shrunk, so that room stays with the pair until it is freed, as for any growth that succeeds on main.

Unchanged from the 11-25 merge: BM+0x80 = max(variant, memory-scaled), and mesh_floor() stays the variant value.

Nothing in the series is redundant after the merge except the charging helpers, which a64f33ae2157 removes. Commits 1-4 are unchanged. Commit 3's message still describes the old helper; the PR description says what replaced it.

Checks at a64f33ae2157: asahi/SEP/ISP KUnit (arm64 qemu) 853/854 (1 skip) on the merge and on the head. All 220 g17 host-test runs pass. The non-g17 host-test failures (g15, DCP, M3 uAPI, SEP) fail on plain main on this build host too. Still open, as before: the J616s rows 1-5 at the head, the J700 heavy-GLES run with the BM+0x80 readback, now also an M5 run of a growth that stops short, and re-review.

@RyanTheTide

Copy link
Copy Markdown
Contributor

@jgoyvaerts checking open drafts today. To come out of draft, this still needs:

  • It conflicts with main. Merge main in or rebase (no force push needed: a merge commit is fine).
  • CI fails at the current head.
  • Review changes requested by @DjDeveloperr are still open.
  • Then a test run at the final head on a Mac with the hardware it touches, and mark it ready for review.

If it's no longer needed, say so here and we'll close it. Otherwise it stays open as a draft until these are done.

@jgoyvaerts

Copy link
Copy Markdown
Contributor Author

J616s (M4 Pro, 48 GiB, GPU firmware 25G83) at head a64f33ae2157: rows 1, 2, 3 and 5 pass; row 4 not run yet.

Kernel 7.3.0-m4.195: main a851ca0edfc9 with #2504 1b0abfeb7e03, #2228 5c529c9e97e5 and this PR at a64f33ae2157 merged in, plus our carried patches. The test is off-screen GLES (EGL surfaceless): N screen-spanning triangles into a 3456x2234 RGBA8 + D24S8 target, with glFinish after each frame. Each run is a fresh process with 10 frames unless noted. Heap sizes come from the asahi_g17_message HEAP events (g17/trace.rs heap()). Memory comes from gpu_memory and each client's fdinfo, sampled every 0.5 s. All runs went through our GPU queue as one chain, on AC. Every row: 0 GPU recoveries, 0 AVC, 0 failed units, and no kernel log lines at all in its window.

  1. Normal maximum: 3,353 blocks (13,412 pages). Nothing exposes BM+0x80 or BM+0x7c of a live heap: no trace event, debugfs file or log line. The recovery dump prints block_capacity (3,354), but not these two. Read through the heap trace instead: every host idle growth at N >= 15k goes 64 -> 3,353 blocks in one step. At N = 10k it goes 64 -> 2,805, the 3x feedback below the cap. The host's idle target is capped at layout.normal_blocks, so the normal maximum is 3,353 blocks. BM+0x7c is the constant 3,354 slots x 4 = 13,416 pages. MemTotal is 46.5 GiB, a 64th is 5,955 blocks, clamped to 3,353. On this Mac 3,353 is also TVB_MAX_BLOCKS, so the trace can't tell the two caps apart. The 15k frame time (41 ms, not 146 ms) shows it isn't the old 1,118.

  2. Sweep. Frames 3-10 (the first two include the growth):

    N drm/asahi: g17: scale the tiler heap's normal maximum with memory #2186 on m4.166 this head on m4.195 heap after growth
    10,000 32 ms 27 ms 2,805
    15,000 41 ms 41 ms 3,353
    20,000 55 ms 55-64 ms 3,353
    30,000 83 ms 82-85 ms 3,353
    40,000 110-138 ms 109-117 ms 3,353
    45,000 417 ms 412-417 ms 3,353 (partial renders)

    At 45k the growth added 3,289 blocks (3,289 x 128 KiB = 420,992 KiB). The client's drm-resident-system rose by 422,016 KiB (72,352 -> 494,368 KiB).

  3. Several heavy clients at once.

    • Four tvbstress processes at N = 30,000 (30 frames each, started together). Each heap grew 64 -> 3,353 within 75 ms of the others. Each client's drm-resident-system went 72,000 -> 494,016 KiB (+412 MiB). gpu_memory user_committed rose by 1,998 MiB, with refused 0. Every frame rendered: 82-394 ms with four clients sharing the GPU, about 1.3 s for the first.
    • One process, three render queues in one VM: three GLES contexts on one EGL display (one DRM file, one VM, one queue per context), frames round-robin, N = 30,000 x 15, then 45,000 x 10.
      • Queue 0 grew 64 -> 3,353. Queue 1 grew 64 -> 3,072 (47 whole extensions, stopped short). Queue 2 didn't grow and stayed at 64 blocks.
      • refused stayed 0, so queues 1 and 2 stopped at the arena edge (ENOSPC), not at a memory limit.
      • The client's drm-resident-system went 214,704 -> 1,022,816 KiB (+789 MiB, the 6,297 growth blocks plus 2 MiB).
      • Frames at 30k: 82 ms on queues 0 and 1, 329 ms on queue 2 (partial renders). At 45k: 412-424, 413-424 and 495-499 ms.
      • No GL error, no ENOSPC or other kernel message, exit 0.
  4. Shrink. One process: N = 45,000 x 10, then N = 2,000 for 50 s, then 20 s idle with the context alive, then 3 more frames.

    • Grown 64 -> 3,353.
    • Active: 3,353 -> 3,328 (the 25-block tail extension) 20.1 s after the growth. Then 3,328 -> 3,264 -> 3,200, 16.0 s apart, 64 blocks (8 MiB) each.
    • Idle: 3,200 -> 320, about 10 s after the last frame.
    • The three frames after the idle shrink took 14, 8 and 6 ms, with no regrowth.

Not covered yet

  • Row 4 (the client limit bites). asahi.client_mem_limit_pct is boot-time only. The runtime gpu_mem_limit_pct file sets the device and the client limit to the same percentage, so there the device limit (every client plus kernel memory) bites first and refuses the desktop too. So it wasn't used here, and this row needs the next boot with asahi.client_mem_limit_pct=2 (953 MiB per client; the desktop clients here hold up to ~490 MiB). The test is one client with a 700 MiB renderbuffer, then N = 30,000 and 45,000. At the default limit that client holds 1,023 MiB with its heap at 3,353 blocks, so at 2 % its growth should stop at about 2,740 blocks, with refused rising and frames still rendering.
  • A growth that stops short before its first extension leaves no HEAP event (Manager::prepare_growth() returns None when no block was added). So in the trace, queue 2's attempts don't show; only the frame times and refused 0 do.
  • The J700 and M5 rows, as before.

… growth arenas

A NEO tiler heap grows only into the two growth arenas, which hold one
heap at TVB_MAX_BLOCKS each (3,321 and 3,353 blocks). Compact
allocations search the render-alias window, then both growth arenas,
and the target window only last. So once the 2 MiB render-alias window
is full, every render pair's primary heap blocks, page-list alias,
scratch, discard, deflake and fragment views, target records and TPC
land in the first growth arena, and the heaps of that VM lose that room.

On a 3456x2234 target that is about 17 MiB of VA per pair (64 primary
blocks, 32 generations' views, 32 records and a 3.3 MiB TPC), about 108
block slots. Now that a heap's normal maximum fills a whole arena on a
48 GiB M4 Pro, a VM with three pairs cannot hold its second heap at the
normal maximum: on the J616s the second heap stopped at 3,072 blocks
and the third at 64; by the count above, compact objects of the three
pairs took about 310 slots of the arenas.

Search the target window before the growth arenas. It is 320 MiB, holds
the compact objects of about eighteen such pairs, and is reserved from
user binds like the arenas, so nothing user-visible moves. An object
that does not fit there still falls back to the growth arenas as before.
Growth itself is placed as before.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
…hare

A VM's NEO tiler heaps grow into two growth arenas of 3,321 and 3,353
block slots: room for the heaps of two render pairs at the normal
maximum of a 48 GiB M4 Pro. A VM can have any number of render pairs,
and the host grows a heap ahead of need as far as its automatic target,
so the heaps that grow first take all of the arenas. With three render
queues in one process on the J616s, the first heap reached 3,353
blocks, the second stopped short, and the third stayed at 64 and
partial-rendered every frame.

Cap the host's growth beyond what a render requires at the heap's fair
share of the arenas: its primary backing plus the room the VM's heaps
can use, divided by the number of heaps. That room is the free slots
of both arenas, measured from the VM's address space, plus the growth
the VM's heaps hold, which the VM's render pool cache now counts as
the blocks each pool grew by after it was installed. Nothing in the
share is tuned to a chip or a board: it follows from the arena layout
and the heaps the VM has. One heap can still grow to the full normal
maximum (3,353 blocks), as can two; three get 2,288 blocks each
(64 + 6,674 / 3).

Required blocks are never capped: a render that needs more than its
share still gets it if it fits, and the busy path passes its required
blocks through for this, still without failing the render. Firmware
grow requests serve a render that has run out and are not capped.
Growth that stops short and shrink work as before. A growth the share
cuts to nothing is retried a shrink period later, as a refused one is,
which also bounds how often the arenas are walked.

A share recomputed as heaps come and go cannot make heaps grow and
shrink in turn:
- A heap's growth or shrink moves slots between the free and the held
  part of the room and leaves the share unchanged. Only a heap coming
  or going, or another object taking or leaving arena room, changes it.
- The share only lowers a growth target. No shrink depends on it: a
  heap above a share that fell keeps its blocks until the existing,
  usage-driven policy gives them back, and that policy's floor already
  keeps a heap above the size its automatic growth would grow back to.
- A heap that shrank regrows only when its usage asks for it, and then
  at most to its share.
A heap made after the others grew beyond the new share gets only the
free room until their usage-driven shrinks give room back.

The cap is computed after the pair is taken, outside the device lock,
where the growth itself is allocated and mapped into the VM.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
A host growth whose first extension already finds no room or memory
stops short at 0 blocks. Manager::prepare_growth then returns no
growth, and nothing reaches the HEAP trace: in a VM with three render
queues on the J616s, the third heap's attempts did not show at all.
A growth the heap's arena share cuts to nothing looks the same.

Emit a HEAP event of the host source, idle or busy, without growth and
with the heap's unchanged size, where the render preparation knows the
source. Manager does not know it, and the firmware path already traces
its refusals as HEAP_FIRMWARE_REFUSED, so tracing there would emit
those twice.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
@jgoyvaerts

Copy link
Copy Markdown
Contributor Author

Three commits on top of a64f33ae2157; the new head is 5cf1361ccc52, a plain push. They fix what row 3b showed: in one VM with three render queues, queue 0 reached 3,353 blocks, queue 1 stopped at 3,072, and queue 2 stayed at 64 and partial-rendered every frame.

  1. 010c1e0d94e0 place compact objects in the target window before the growth arenas. Compact allocations searched the render-alias window, then both growth arenas, and the 320 MiB target window last. Once the 2 MiB render-alias window was full, every pair's primary blocks, page-list alias, generation views, target records and TPC landed in the first growth arena: about 17 MiB, or 108 block slots, per pair at 3456x2234. They now go to the target window first and fall back to the arenas only if they don't fit there. Growth placement is unchanged. This bug was on main too, but it only showed once a heap could fill a whole arena.
  2. b004eb6f131c cap tiler-heap growth ahead of need at a fair arena share. A VM has two growth arenas (3,321 + 3,353 slots) and any number of render pairs, so the heaps that grow first took all of them. Host growth beyond a render's required blocks is now capped at the heap's primary plus (free arena slots + growth the VM's heaps hold) / (the VM's heaps). Free slots come from the VM's address space; the held growth and the heap count come from the VM's render pool cache. There are no chip or board gates: one heap, or two, still reach 3,353 blocks, and three get 2,288 each.
    • Required blocks are never capped, on the idle or the busy path. Firmware grow requests are not capped either.
    • A heap's own growth or shrink doesn't change the share, which changes only as heaps come and go. The share never drives a shrink, so it can't cause grow/shrink ping-pong. A growth the share cuts to nothing waits a shrink period, like a refused one.
    • Limit: a heap created after the others have grown past the new share gets only the free room until their usage-driven shrinks give room back.
  3. 5cf1361ccc52 trace a host tiler-heap growth that adds no block. A host growth that stopped short at 0 blocks emitted no HEAP event, so queue 2's attempts didn't show in the trace. It now emits HEAP_HOST_IDLE or HEAP_HOST_BUSY without growth, from the render preparation, which knows the source. The firmware path already traces HEAP_FIRMWARE_REFUSED.

Behaviour changes: three or more heavy render queues in one VM now split the growth arenas instead of the first one taking them. Fewer than three see no change. Small objects no longer take room in the growth arenas.

Tested: at 5cf1361ccc52, KUnit (arm64 qemu): 860 tests, 859 passed, 1 skipped, with the new asahi_g17_tvb_share (one, two and three heavy heaps in one VM, and a heap whose required blocks exceed its share). All 220 g17 host tests pass; the same 29 non-g17 runs fail as before (build-host link errors). The asahi module compiles with 0 Rust errors at b004eb6f131c and at the head. No hardware run yet at this head.

Not yet: the J616s rows at this head: tvbmulti row 3b with three queues (expected: each heap at 2,288 blocks, 0 refused) and with two (both at 3,353), plus dEQP-GLES31.functional.fbo.no_attachments.maximums.* for the target-window fallback.

@jgoyvaerts

Copy link
Copy Markdown
Contributor Author

J616s row 4 (client limit) at a64f33ae2157: PASS.

Kernel: the same m4.195 test kernel (aurora main a851ca0edfc9 with this PR at a64f33ae2157), booted once at 2026-11-26 20:52 UTC with asahi.client_mem_limit_pct=2. The kernel log reports "GPU memory limits: device 31919 MiB, per client 952 MiB". The desktop (Hyprland, quickshell) started and ran normally under that limit. The parameter was used for this boot only.

Run: one process (one VM, three render queues), with a 700 MiB renderbuffer ballast first, then 20 frames at N = 30,000 and 10 at N = 45,000. 20:53:09-20:53:15 UTC.

  • The tiler heap grew once, 1,400 -> 2,744 blocks (heap trace). Its primary started at 1,400 blocks, sized by the ballast's large target. The growth stopped there: gpu_memory refused went 0 -> 5, and the client's drm-resident-system ended at 970,400 KiB, under the 952 MiB limit.
  • Every frame rendered: 82-89 ms at 30k (the first 287 ms), 413-421 ms at 45k. 0 GL errors, exit 0.
  • 0 GPU recoveries, 0 AVC lines, 0 failed units, and 0 kernel log lines in the run window. Before the run: 0 err-level lines, 0 WARN.

This completes rows 1-5 on the J616s. Not yet: the J700 (A18 Pro) heavy-GLES run, and an M5 run of a growth that stops short.

@jgoyvaerts

Copy link
Copy Markdown
Contributor Author

J616s rows at 5cf1361ccc52: PASS for the arena placement, fair-share growth and trace commits.

Kernel: our m4.197 test kernel, on its second boot (2026-11-27 04:20:56 UTC, after an unrelated firmware-crash test on the first boot ended in a guard reboot): aurora main a851ca0edfc9 with this PR at a64f33ae2157 plus 010c1e0d94e0, b004eb6f131c and 5cf1361ccc52 (the three new commits), #2504 and #2228, plus our carried patches. Default command line (client limit 50 %). Runs 04:21-04:25 UTC, one guarded chain.

Row Result
One VM, three render queues (tvbmulti, N = 30,000 then 45,000, all heaps created before any growth) Each heap grew once, 64 -> 2,288 blocks, the fair share (64 + 6,674 / 3). 39 more host attempts at the share traced as no-growth events (the new 5cf1361ccc52 event). refused 0. Every queue renders: 82-109 ms at 30k, 413-425 ms at 45k. On m4.195 without these commits the same run gave 3,353 / 3,072 / 64, and the third queue partial-rendered at 329 ms.
One VM, two render queues Both heaps grew 64 -> 3,353. refused 0. 82-99 ms at 30k, 414-428 ms at 45k.
Target-window fallback: dEQP-GLES31.functional.fbo.no_attachments.maximums.* (EGL surfaceless) 5/5 Pass, including 16384x16384 with 0x and 4x multisampling, and 128x16384 / 16384x128.

0 GPU recoveries, 0 AVC lines, 0 failed units and no GPU kernel lines in any row window (the only kernel lines were two firewall messages). 0 GL errors.

Not covered: the heap trace doesn't show which window the big target's records and TPC landed in, so the fbo row shows that the reordered compact search still fits or falls back cleanly at the largest target, not which of the two happened. Not yet: the J700 (A18 Pro) heavy-GLES run, and an M5 run of a growth that stops short.

@jgoyvaerts
jgoyvaerts marked this pull request as ready for review November 28, 2026 15:47
@jgoyvaerts
jgoyvaerts requested review from a team as code owners November 28, 2026 15:47
@jgoyvaerts
jgoyvaerts requested a review from a team as a code owner November 28, 2026 15:47
@jgoyvaerts

Copy link
Copy Markdown
Contributor Author

@DjDeveloperr this is ready for re-review at 5cf1361ccc52. Your 11-21 review was at an older head. Since then:

J616s rows 1-5 pass at a64f33ae2157. The arena, fair-share and fbo-maximums rows pass at the head (results above). KUnit and the g17 host tests pass at the head.

Still open, and they need other Macs: the J700 (A18 Pro) heavy-GLES run with the BM+0x80 readback, and an M5 run of a growth that stops short.

@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 5cf1361c (once the superseded 0a2a5c2b changes-requested review is cleared and re-triggered pr-text/readiness complete)

Blockers: none

Checked:

  • Audited all 9 files (g17/buffer.rs, g17/buffer/layout.rs, g17/fw/buffer.rs, g17/queue/render.rs, g17/runtime/render/{grow,prepare}.rs, hw/t8140.rs, memacct.rs, mmu/lifetime.rs) against all prior findings from 0a2a5c2b:
    1. Client accounting & admission: Tvb::prepare_growth() allocates every extension via KernelObject::client_backing(..., vm.memory_client()), honoring per-client and device limits. Partial ENOMEM/ENOSPC drops only the failed chunk (mappings before backing via declaration order), records stopped, defers speculative retries by SHRINK_PERIOD_NS, and fails only if target < required.
    2. Incremental shrink granularity: EXTENSION_BLOCKS = 64 (8 MiB max per extension) allows Manager::shrink() to reclaim in 8 MiB steps; extensions.reserve(count) and commit_growth capacity checks match the multi-extension vector cleanly.
    3. Arena isolation & single-VM fair share: tvb_growth_ranges() confines NEO growth strictly to the two growth arenas (TVB_GROWTH + second), while compact_ranges() puts RENDER_ALIASES and TARGETS ahead of them (compact_objects_reach_the_growth_arenas_last). Manager::host_target() + growth_target() cap speculative growth beyond required to primary + (free + grown) / heaps.max(1) using Vm::render_pool_growth(), never capping required or firmware grow requests, and emitting HEAP_HOST_IDLE/HEAP_HOST_BUSY when no block is added.
    4. Cleanups & invariants: uses crate::memacct::total_ram_bytes() directly; Layout::initialize() uses args.normal_blocks; fw::Graph::init() validates NORMAL_MAX_BLOCKS..=TVB_MAX_BLOCKS and uses TVB_PAGES_PER_BLOCK; mesh_floor() retains variant_normal_blocks (not raised by RAM).
  • Verified CI & hardware at 5cf1361ccc52: all build/host/KUnit CI checks green (asahi_g17_tvb_limits 2/2, asahi_g17_tvb_share 5/5, 220/220 g17 host tests); J616s (M4 Pro, 48 GiB, 25G83) rows PASS at 5cf1361c (3-queue VM fair share 2,288 blocks each, 2-queue VM 3,353 each, dEQP-GLES31.functional.fbo.no_attachments.maximums.* 5/5, 0 recoveries/AVCs/failed units) plus prior client-limit (952 MiB) and shrink rows at a64f33ae.
Evidence
  • Risk: two-way door · G17 GPUs present.
  • Note: J700 (A18 Pro) BM+0x80 readback and M5 stop-short run remain listed in **Not yet:** as follow-up coverage (below 8.7 GiB neo_normal_blocks() clamps to the existing 1,118 blocks).

@RyanTheTide

Copy link
Copy Markdown
Contributor

code-owner ping <@422957901716652033> / @DjDeveloperr: merge train at 5cf1361c. The App approved this head (NEON-PR-REVIEW2), all hosted CI is green, and the J616s exact-head rows pass. Your 0a2a5c2b change request is on an older head, and the App verified each finding is resolved here. One more GPU family at this head (J700 or K114s: a short GL/VK smoke plus fbo.no_attachments.maximums) and it merges under the 6-point rule, unless you object.

@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:m4 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) blast:neo Macs affected, from Merge risk (bot) changes-requested A reviewer requested changes (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 28, 2026
@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Merge readiness at 5cf1361c: ready to merge

Check Detail
CI at head ok 22 checks passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok in the PR body at 5cf1361c
Conflicts ok none
PR text ok Risk: two-way · G17 GPUs: M4 Pro and M4 Max (t6040, t6041), A18 Pro (t8140), M5 (the 8 MiB extensions, the per-extension charging and compact-window room check, and stop-short growth). Below 8.7 GiB the normal maximum stays 1,118 blocks. Fair share (b004eb6f131c): one or two heavy render queues per VM still reach the normal maximum; three or more each get their primary plus (free arena slots + growth the VM's heaps hold) / heaps, 2,288 blocks with three. Required blocks and firmware grow requests are not capped. A heap made after the others grew past the new share gets only the free room until their usage-driven shrinks return it.

Areas: area:gpu
Merge: gh pr merge 2724 --merge (Owners and Core through the bypass: add --admin).

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

@jgoyvaerts

Copy link
Copy Markdown
Contributor Author

On the 27.2 question from #2186 (#2186 (comment)): the J616s (M4 Pro, 48 GiB) now runs macOS 27.2.1 (26B131, iBoot1 mBoot-20457.41.3). I read the heap header live there, as for 26.6.2, during a 3456x2234 render on a fresh queue:

Word macOS 26.6.2 (25G83) macOS 27.2.1 (26B131)
BM+0x7c 0x13464 pages (19,737 blocks) 0x13464 pages (19,737 blocks)
BM+0x80 0x66cc pages (6,579 blocks) 0x66cc pages (6,579 blocks)
BM+0x38 19,737 19,737

0 GPU recoveries. The values are unchanged, so the upper bound in "Why a 64th" holds on 27.2 too: macOS gives the normal maximum 1/60 of memory there; this PR gives a 64th.

The Linux half of the ask still can't run here. Main admits 26B123 only for the T6041; hw/t6040.rs admits 25G83 only. On 26B123 the T6041 runs V26B123, which is ..V25F84, which is ..V25G83. So 27.2 takes the same path this PR changes: host-only growth (unk_892 = 0) and the same BM+0x80 write. Once there is a T6040 26B123 build, I'll rerun the J616s rows on it.

@github-actions github-actions Bot removed the ci-failing A check failed at the PR head (bot) label Nov 30, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor

J700 (Neo, A18 Pro, 7.3 GiB): tiler heap with this change

What was tested: this PR's diff (head 5cf1361c) applied to main dbfbced7's asahi driver, built warm as aurora.ko (installed sha256 9a5f2506) on the J700 kernel 7.3.0-neo-fence-kclean (Image sha256 a2c0a040). The head itself is about 1,170 commits behind main, so this is the change on current main, not the exact head. One-shot trial boot 5b93af15; stock Fedora -41 restored and verified afterwards.

Heavy render with the heap trace: asahi_g17_message HEAP events while running:

  • render.tvb at d1 and d4
  • render.tvb on three queues in one VM
  • render.heavy in four processes
  • render.deferred (CRC valid)

All runs completed.

  • 388 HEAP events: 384 firmware-granted growths in 10-block steps, plus 4 host-idle growths.
  • The largest heap reached exactly 1,118 blocks and never went beyond it. That is the normal maximum this PR keeps below 8.7 GiB.
  • No shrink events during 12 s of idle: the heaps went away with their processes, and kernel_resident fell from 202 MB to 177 MB.

Render CTS against stock: dEQP-VK.draw.renderpass.*, 12,466 cases, same CTS and flags. The trial kernel and stock -41 (boot ca543ddf) both gave 11,517 Pass / 949 NotSupported / 0 Fail, with 0 differing cases.

Health: 0 GPU faults, 0 WARN, 0 AVC, 0 failed units. The only flagged boot line is "loading out-of-tree module taints kernel", from building aurora.ko with M=.

Not covered: a heavy GLES run and a direct BM+0x80 register readback. The cap was read from the host-side heap trace instead.

@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.

Approved at 5cf1361. The earlier accounting and placement findings are resolved. Growth allocations charge the VM client, stop at an admission failure and release incomplete mappings before their backing. The 64-block extensions can shrink in 8 MiB steps. Growth uses the two tiler arenas, and speculative growth accounts for the other heaps in the VM. The new J616s runs cover arena placement and multi-queue sharing. The J700 or K114s shared-path smoke and framebuffer-maximums row still gates merge.

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed changes-requested A reviewer requested changes (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 1, 2026
@DjDeveloperr
DjDeveloperr merged commit d5e9949 into aurora-silicon:main Dec 1, 2026
27 of 30 checks passed
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:m4 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) blast:neo Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants