AMM automatic backing is not reclaimed on unmap, exhausting direct memory during HFW loading #854

Closed
opened 2026-11-26 09:35:09 +00:00 by github-bot · 1 comment
Owner

@⁠tototomate123 on GitHub · 2026-09-26 18:43 UTC · original

Summary

Horizon Forbidden West (PPSA01521) eventually exhausts AMM automatic direct-memory backing during loading because unmapped automatic allocations are not returned to the pool.

AllocateAmmAutoDirectMemory advances AmmAutoPoolRange::used, while the AMM unmap path calls KernelMunmap without reclaiming that backing.

Observed on Linux on top of ae39466 / #852.

Reproduction / evidence

Before reclaiming automatic backing:

AMM allocation failed: requested=524288 type=12 result=0x80020023
pool_total=11431575552 pool_used=11431264256 pool_largest_free=311296
direct_total=13421772800 direct_largest_free=65536 availability_result=0

A 512 KiB allocation fails after the pool has been almost completely consumed. After this, HFW remains on the loading screen.

The repeated RUDP calls seen at that point appear to be a consequence of the stalled loading process rather than its cause.

Local experiment

I tested an allocator that:

  • tracks and reuses freed automatic backing;
  • supports partial unmaps and fixed replacements;
  • coalesces free extents;
  • rolls back failed mappings;
  • avoids reuse while physical aliases remain mapped.

With this change, HFW reclaimed backing including a 512 MiB allocation and resumed substantial asset loading. It progressed to VS 11 / PS 9 / CS 55 before stopping later on a separate unresolved audio function (sceAjmDecMp3ParseFrame).

So this does not make HFW boot completely, but it removes the earlier AMM exhaustion blocker.

#780 already implements the same general solution by replacing the cursor allocator with reusable free extents and tracking automatic mappings. This issue mainly provides another reproduction confirming that behavior is required for HFW.

Relevant allocation tests, including repeated reuse, partial unmaps, aliases, fixed mappings and rollback cases, passed locally.

AI assistance was used during investigation, implementation, testing, and preparation of this report. Game runs and logs were manually produced.

**@⁠tototomate123** on GitHub · 2026-09-26 18:43 UTC · [original](https://github.com/KytyPS5/KytyPS5/issues/854) ## Summary Horizon Forbidden West (PPSA01521) eventually exhausts AMM automatic direct-memory backing during loading because unmapped automatic allocations are not returned to the pool. `AllocateAmmAutoDirectMemory` advances `AmmAutoPoolRange::used`, while the AMM unmap path calls `KernelMunmap` without reclaiming that backing. Observed on Linux on top of `ae39466` / #852. ## Reproduction / evidence Before reclaiming automatic backing: ```text AMM allocation failed: requested=524288 type=12 result=0x80020023 pool_total=11431575552 pool_used=11431264256 pool_largest_free=311296 direct_total=13421772800 direct_largest_free=65536 availability_result=0 ``` A 512 KiB allocation fails after the pool has been almost completely consumed. After this, HFW remains on the loading screen. The repeated RUDP calls seen at that point appear to be a consequence of the stalled loading process rather than its cause. ## Local experiment I tested an allocator that: - tracks and reuses freed automatic backing; - supports partial unmaps and fixed replacements; - coalesces free extents; - rolls back failed mappings; - avoids reuse while physical aliases remain mapped. With this change, HFW reclaimed backing including a 512 MiB allocation and resumed substantial asset loading. It progressed to VS 11 / PS 9 / CS 55 before stopping later on a separate unresolved audio function (`sceAjmDecMp3ParseFrame`). So this does not make HFW boot completely, but it removes the earlier AMM exhaustion blocker. ## Related work #780 already implements the same general solution by replacing the cursor allocator with reusable free extents and tracking automatic mappings. This issue mainly provides another reproduction confirming that behavior is required for HFW. Relevant allocation tests, including repeated reuse, partial unmaps, aliases, fixed mappings and rollback cases, passed locally. AI assistance was used during investigation, implementation, testing, and preparation of this report. Game runs and logs were manually produced.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:35:09 +00:00
Author
Owner

@⁠overlordxrz-source on GitHub · 2026-10-06 01:26 UTC · original

Triage note on current main (cdb64bf): the cursor allocator described here (AmmAutoPoolRange::used advancing without reclaim) no longer exists — kernel memory is now PhysicalMemory free-range management (AddFreeRange/RemoveFreeRange incl. automatic-backing tracking), and the release path returns blocks with alias rollback (ReleaseDirectMemoryInternal → PhysicalMemory::Release). The behaviors your experiment validated (reuse of freed backing, partial unmaps, coalescing, rollback, alias safety) are covered by VirtualMemoryAllocationTests — e.g. TestSmallerFlexibleMapReusesReleasedHole, TestPartialFlexibleMunmapAndFindNext, TestFragmentedBackingUnmapRollback, TestFlexibleMemoryReuseIsZeroFilled — all passing locally (x86_64 macOS Release, 6.7s).

So the exhaustion mechanism in this report looks superseded rather than still present. If HFW still dies with AMM allocation failed / pool-exhausted numbers on a current build, please post the fresh figures — that would be a new defect (e.g. a leak keeping ranges pinned rather than the old never-reclaim), and the pool/largest-free numbers will show which.

**@⁠overlordxrz-source** on GitHub · 2026-10-06 01:26 UTC · [original](https://github.com/KytyPS5/KytyPS5/issues/854#issuecomment-6007426630) Triage note on current main (`cdb64bf`): the cursor allocator described here (`AmmAutoPoolRange::used` advancing without reclaim) no longer exists — kernel memory is now `PhysicalMemory` free-range management (`AddFreeRange`/`RemoveFreeRange` incl. automatic-backing tracking), and the release path returns blocks with alias rollback (`ReleaseDirectMemoryInternal` → `PhysicalMemory::Release`). The behaviors your experiment validated (reuse of freed backing, partial unmaps, coalescing, rollback, alias safety) are covered by `VirtualMemoryAllocationTests` — e.g. `TestSmallerFlexibleMapReusesReleasedHole`, `TestPartialFlexibleMunmapAndFindNext`, `TestFragmentedBackingUnmapRollback`, `TestFlexibleMemoryReuseIsZeroFilled` — all passing locally (x86_64 macOS Release, 6.7s). So the exhaustion mechanism in this report looks superseded rather than still present. If HFW still dies with `AMM allocation failed` / pool-exhausted numbers on a current build, please post the fresh figures — that would be a new defect (e.g. a leak keeping ranges pinned rather than the old never-reclaim), and the pool/largest-free numbers will show which.
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/KytyPS5--KytyPS5#854
No description provided.