Skip to content

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

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
jradelmo:feat/flexible-memory-budget
Oct 14, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
jradelmo:feat/flexible-memory-budget

Conversation

@jradelmo

@jradelmo jradelmo commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

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

@oneandonlydean

Copy link
Copy Markdown
Collaborator

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

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

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

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 13, 2026
@jradelmo

Copy link
Copy Markdown
Contributor Author

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)

@oneandonlydean

Copy link
Copy Markdown
Collaborator

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

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Collaborator

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

Read the optional aligned budget from param.json and apply it consistently to configured, available and mapped flexible memory. Add parser and allocation regression coverage.
@jradelmo
jradelmo force-pushed the feat/flexible-memory-budget branch from 6db4f9e to 12851ef Compare October 13, 2026 23:13
@jradelmo

Copy link
Copy Markdown
Contributor Author

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

rebased @oneandonlydean

@oneandonlydean
oneandonlydean merged commit 014f362 into boykopovar:main Oct 14, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants