fix(kernel): honor the declared flexible memory budget #4508

Merged
jradelmo merged 2 commits from upstream-pr/4508 into main 2026-10-14 00:13:04 +00:00
jradelmo commented 2026-10-12 13:49:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jradelmo on 2026-10-12T13:49:44Z.


What

Read the optional kernel.flexibleMemorySize value from param.json and apply it consistently to configured, available and mapped flexible memory. Keep the 448 MiB default when the field is absent, and reject values that are not positive 16 KiB-aligned unsigned integers.

Add parser and guest-memory regression coverage for declared, limited, default, missing and invalid budgets, including accounting for loaded guest module segments.

Tested

Windows, MinGW-w64 GCC 15.2.0, Release.

  • Built param_json_parser_tests and guest_flexible_memory_budget_tests.
  • Ran param_json_parser and the five guest_flexible_memory_* cases: 6/6 passed.
  • python tools/check_conventions.py --base origin/main passed.
  • git diff --check passed.
  • Black Myth: Wukong (PPSA23226) declares kernel.flexibleMemorySize: 838860800 (800 MiB) in param.json.
  • With the 448 MiB default, a controlled startup reproduced:
    [memory] flexible memory exhausted: request 0x80000 with 0x21ad8000 of 0x1c000000 in use
  • With the declared 800 MiB budget, startup logged [memory] configured flexible memory: 0x32000000 bytes (800 MiB) and continued loading for about 73 seconds before being stopped; reaching the menu was not confirmed.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation files or images added to the repository
  • No new third-party code
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: PPSA23226 (Black Myth: Wukong; declares 800 MiB flexible memory)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4830358887 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4508). Originally posted by [jradelmo](https://github.com/jradelmo) on 2026-10-12T13:49:44Z. --- ### What Read the optional `kernel.flexibleMemorySize` value from `param.json` and apply it consistently to configured, available and mapped flexible memory. Keep the 448 MiB default when the field is absent, and reject values that are not positive 16 KiB-aligned unsigned integers. Add parser and guest-memory regression coverage for declared, limited, default, missing and invalid budgets, including accounting for loaded guest module segments. ### Tested Windows, MinGW-w64 GCC 15.2.0, Release. - Built `param_json_parser_tests` and `guest_flexible_memory_budget_tests`. - Ran `param_json_parser` and the five `guest_flexible_memory_*` cases: 6/6 passed. - `python tools/check_conventions.py --base origin/main` passed. - `git diff --check` passed. - Black Myth: Wukong (PPSA23226) declares `kernel.flexibleMemorySize: 838860800` (800 MiB) in `param.json`. - With the 448 MiB default, a controlled startup reproduced: `[memory] flexible memory exhausted: request 0x80000 with 0x21ad8000 of 0x1c000000 in use` - With the declared 800 MiB budget, startup logged `[memory] configured flexible memory: 0x32000000 bytes (800 MiB)` and continued loading for about 73 seconds before being stopped; reaching the menu was not confirmed. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation files or images added to the repository - [x] No new third-party code - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: PPSA23226 (Black Myth: Wukong; declares 800 MiB flexible memory) - [x] AI-assisted: yes
oneandonlydean commented 2026-10-13 00:23:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T00:23:54Z.


Which title declares kernel.flexibleMemorySize and runs out at 448 MiB on main? With the title ID, its param.json value and the [memory] flexible memory exhausted line this can go in; otherwise I'll close it until one does.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6135215546 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4508#issuecomment-6135215546). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T00:23:54Z. --- Which title declares `kernel.flexibleMemorySize` and runs out at 448 MiB on main? With the title ID, its param.json value and the `[memory] flexible memory exhausted` line this can go in; otherwise I'll close it until one does.
github-actions[bot] commented 2026-10-13 00:36:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T00:36:34Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#4725 core/libs/prx/libkernel/CMakeLists.txt L1157
#5021 docs/dev/debt/libkernel.md L40
#5143 core/libs/prx/libkernel/CMakeLists.txt L1157
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6135375433 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4508#issuecomment-6135375433). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T00:36:34Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #4725 | `core/libs/prx/libkernel/CMakeLists.txt` [L1157](https://github.com/boykopovar/AnyPS5/blob/d1670009fbfdfe57f8f26ee09ced77fe6b18c2ca/core/libs/prx/libkernel/CMakeLists.txt#L1157) | | | | #5021 | `docs/dev/debt/libkernel.md` [L40](https://github.com/boykopovar/AnyPS5/blob/d1670009fbfdfe57f8f26ee09ced77fe6b18c2ca/docs/dev/debt/libkernel.md#L40) | | | | #5143 | `core/libs/prx/libkernel/CMakeLists.txt` [L1157](https://github.com/boykopovar/AnyPS5/blob/d1670009fbfdfe57f8f26ee09ced77fe6b18c2ca/core/libs/prx/libkernel/CMakeLists.txt#L1157) | | |
jradelmo commented 2026-10-13 00:56:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jradelmo on 2026-10-13T00:56:39Z.


Which title declares kernel.flexibleMemorySize and runs out at 448 MiB on main? With the title ID, its param.json value and the [memory] flexible memory exhausted line this can go in; otherwise I'll close it until one does.

Hey @oneandonlydean

The title is Black Myth: Wukong, PPSA23226, master version 02.00, content version 01.000.010 (content ID HP6545-PPSA23226_00-GAME000000000000).

Its installed /app0/sce_sys/param.json declares:

{
  "titleId": "PPSA23226",
  "kernel": {
    "flexibleMemorySize": 838860800
  }
}

838860800 is 0x32000000, or 800 MiB. The original file was not edited for these tests; its SHA-256 is 403B75F52A5765135BAE3B663BC2A4D8A04EA16E229137B0F4964CFBC65EABD1.

The pre-fix startup log contains this failure at line 154:

[memory] flexible memory exhausted: request 0x80000 with 0x21ad8000 of 0x1c000000 in use

I also reproduced the same failure today in a controlled regression run, using the integrated Wukong branch and changing only the configured budget back to the 448 MiB default used by main. The unchanged installation produced:

[memory] configured flexible memory: 0x1c000000 bytes (448 MiB)
[memory] flexible memory exhausted: request 0x80000 with 0x21ad8000 of 0x1c000000 in use

The request is 512 KiB; image segments and tracked flexible mappings already account for 538.84375 MiB, exceeding the hardcoded 448 MiB budget. _mapFlexible consequently returns SCE_KERNEL_ERROR_ENOMEM. A guest access violation follows in both logs.

With the fix restored, the startup log prints the requested diagnostic at line 154:

[memory] configured flexible memory: 0x32000000 bytes (800 MiB)
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6135702999 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4508#issuecomment-6135702999). Originally posted by [jradelmo](https://github.com/jradelmo) on 2026-10-13T00:56:39Z. --- > Which title declares `kernel.flexibleMemorySize` and runs out at 448 MiB on main? With the title ID, its param.json value and the `[memory] flexible memory exhausted` line this can go in; otherwise I'll close it until one does. Hey @oneandonlydean The title is **Black Myth: Wukong**, **PPSA23226**, master version **02.00**, content version **01.000.010** (content ID `HP6545-PPSA23226_00-GAME000000000000`). Its installed `/app0/sce_sys/param.json` declares: ```json { "titleId": "PPSA23226", "kernel": { "flexibleMemorySize": 838860800 } } ``` `838860800` is `0x32000000`, or **800 MiB**. The original file was not edited for these tests; its SHA-256 is `403B75F52A5765135BAE3B663BC2A4D8A04EA16E229137B0F4964CFBC65EABD1`. The pre-fix startup log contains this failure at line 154: ```text [memory] flexible memory exhausted: request 0x80000 with 0x21ad8000 of 0x1c000000 in use ``` I also reproduced the same failure today in a controlled regression run, using the integrated Wukong branch and changing only the configured budget back to the 448 MiB default used by main. The unchanged installation produced: ```text [memory] configured flexible memory: 0x1c000000 bytes (448 MiB) [memory] flexible memory exhausted: request 0x80000 with 0x21ad8000 of 0x1c000000 in use ``` The request is 512 KiB; image segments and tracked flexible mappings already account for **538.84375 MiB**, exceeding the hardcoded 448 MiB budget. `_mapFlexible` consequently returns `SCE_KERNEL_ERROR_ENOMEM`. A guest access violation follows in both logs. With the fix restored, the startup log prints the requested diagnostic at line 154: ```text [memory] configured flexible memory: 0x32000000 bytes (800 MiB) ```
oneandonlydean commented 2026-10-13 01:16:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T01:16:09Z.


Two things left before this goes in:

  • docs/dev/debt/libkernel.md: add a line for the budget. The direct memory size is not reduced when a title declares more than 448 MiB, and rejecting zero or a value that is not a multiple of 16 KiB is not measured on the console. Line 43 there still says "the 448 MiB flexible budget".
  • The description still says "Unblocks: none" and that the title was not run. Put PPSA23226, its 800 MiB value and the flexible memory exhausted line there.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6135948754 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4508#issuecomment-6135948754). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T01:16:09Z. --- Two things left before this goes in: - `docs/dev/debt/libkernel.md`: add a line for the budget. The direct memory size is not reduced when a title declares more than 448 MiB, and rejecting zero or a value that is not a multiple of 16 KiB is not measured on the console. Line 43 there still says "the 448 MiB flexible budget". - The description still says "Unblocks: none" and that the title was not run. Put PPSA23226, its 800 MiB value and the `flexible memory exhausted` line there.
fdfawef324 commented 2026-10-13 07:25:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-13T07:25:35Z.


Tested on Windows with Black Myth: Wukong (PPSA23226). Its param.json declares kernel.flexibleMemorySize 838860800 (800 MiB).

Without this PR, the title stops 12.5 s after launch:

[memory] flexible memory exhausted: request 0x80000 with 0x21ad8000 of 0x1c000000 in use
FATAL: unhandled exception 0xc0000005

With this PR merged into the same build, there is no flexible memory exhausted line. The title sets its window title and runs for 270 s. It then stops on an unrelated engine watchdog: GameThread timed out waiting for RenderThread after 120.00 secs. That run started with a cold shader cache.

The build was main plus several of my open PRs, including #4960, which this title needs to start.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6140523198 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4508#issuecomment-6140523198). Originally posted by [fdfawef324](https://github.com/fdfawef324) on 2026-10-13T07:25:35Z. --- Tested on Windows with Black Myth: Wukong (PPSA23226). Its `param.json` declares `kernel.flexibleMemorySize` 838860800 (800 MiB). Without this PR, the title stops 12.5 s after launch: ``` [memory] flexible memory exhausted: request 0x80000 with 0x21ad8000 of 0x1c000000 in use FATAL: unhandled exception 0xc0000005 ``` With this PR merged into the same build, there is no `flexible memory exhausted` line. The title sets its window title and runs for 270 s. It then stops on an unrelated engine watchdog: `GameThread timed out waiting for RenderThread after 120.00 secs`. That run started with a cold shader cache. The build was `main` plus several of my open PRs, including #4960, which this title needs to start.
oneandonlydean commented 2026-10-13 22:38:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T22:38:00Z.


Both points are in. The branch now has a merge commit (afd245256d); please rebase onto main and force-push instead.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6156706679 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4508#issuecomment-6156706679). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T22:38:00Z. --- Both points are in. The branch now has a merge commit (`afd245256d`); please rebase onto main and force-push instead.
jradelmo commented 2026-10-14 00:12:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jradelmo on 2026-10-14T00:12:14Z.


Both points are in. The branch now has a merge commit (afd245256d); please rebase onto main and force-push instead.

rebased @oneandonlydean

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6157914928 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4508#issuecomment-6157914928). Originally posted by [jradelmo](https://github.com/jradelmo) on 2026-10-14T00:12:14Z. --- > Both points are in. The branch now has a merge commit (`afd245256d`); please rebase onto main and force-push instead. rebased @oneandonlydean
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
boykopovar/AnyPS5!4508
No description provided.