fix(libkernel): raise the open file soft limit on Linux #1645

Merged
XairRrR merged 1 commit from upstream-pr/1645 into main 2026-10-10 01:44:55 +00:00
XairRrR commented 2026-10-08 15:31:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-08T15:31:11Z.


What

Each direct memory backing keeps a memfd open, so a title such as Dreaming Sarah (PPSA02929) holds about 1100 descriptors at startup and about 1180 once in game. With the systemd default soft RLIMIT_NOFILE of 1024, later opens fail with EMFILE: memfd_create throws "create direct memory backing: Too many open files", or the title's fopen returns NULL and it faults in fread.

libkernel now raises the soft limit to the hard limit when it is loaded, before the title creates any descriptor, and throws if the limit cannot be read or raised. If the hard limit itself is 1024 the title still runs out of descriptors, as before. Nothing in core uses POSIX select(), so descriptors above 1023 are safe.

Environments that already raise the soft limit (some IDE terminals, CI runners) do not show it; it reproduces from a default desktop terminal or with ulimit -Sn 1024.

Tested

Arch Linux (kernel 7.2, RTX 4070 Ti SUPER), Dreaming Sarah (PPSA02929), soft limit 1024 unless stated:

  • main (4b005b22): crashes at startup on 3/3 runs; the process reaches exactly 1024 open descriptors before it dies
  • main with soft limit 4096: runs, peaking at about 1180 open descriptors
  • this branch: 3/3 runs of 30 s reach gameplay, ~60 fps
  • ctest: 463/463 passed; tools/check_conventions.py --base origin/main passed

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 (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4789142552 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1645). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-08T15:31:11Z. --- ### What Each direct memory backing keeps a memfd open, so a title such as Dreaming Sarah (PPSA02929) holds about 1100 descriptors at startup and about 1180 once in game. With the systemd default soft `RLIMIT_NOFILE` of 1024, later opens fail with `EMFILE`: `memfd_create` throws "create direct memory backing: Too many open files", or the title's `fopen` returns NULL and it faults in `fread`. libkernel now raises the soft limit to the hard limit when it is loaded, before the title creates any descriptor, and throws if the limit cannot be read or raised. If the hard limit itself is 1024 the title still runs out of descriptors, as before. Nothing in `core` uses POSIX `select()`, so descriptors above 1023 are safe. Environments that already raise the soft limit (some IDE terminals, CI runners) do not show it; it reproduces from a default desktop terminal or with `ulimit -Sn 1024`. ### Tested Arch Linux (kernel 7.2, RTX 4070 Ti SUPER), Dreaming Sarah (PPSA02929), soft limit 1024 unless stated: - `main` (4b005b22): crashes at startup on 3/3 runs; the process reaches exactly 1024 open descriptors before it dies - `main` with soft limit 4096: runs, peaking at about 1180 open descriptors - this branch: 3/3 runs of 30 s reach gameplay, ~60 fps - `ctest`: 463/463 passed; `tools/check_conventions.py --base origin/main` passed ### 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 (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-08 19:06:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T19:06:56Z.


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
#1777 core/libs/prx/libkernel/CMakeLists.txt L9
#1860 core/libs/prx/libkernel/CMakeLists.txt L9
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6067087245 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1645#issuecomment-6067087245). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-08T19:06:56Z. --- <!-- 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 | |---|---|---|---| | #1777 | `core/libs/prx/libkernel/CMakeLists.txt` [L9](https://github.com/boykopovar/AnyPS5/blob/c9da0f93cf6b92e8a95143c9ce25ff0800d5be3b/core/libs/prx/libkernel/CMakeLists.txt#L9) | | | | #1860 | `core/libs/prx/libkernel/CMakeLists.txt` [L9](https://github.com/boykopovar/AnyPS5/blob/c9da0f93cf6b92e8a95143c9ce25ff0800d5be3b/core/libs/prx/libkernel/CMakeLists.txt#L9) | | |
popcoder565 commented 2026-10-09 19:43:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T19:43:38Z.


Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head df3aa1a9, merged onto main 8b393b6e in one build with 31 other PRs that had no Windows run.

  • The change is Linux-only, so this only checks that the Windows build is unaffected.
  • Full ctest in that build: 520 of 521. The one failure is guest_offline_imports, broken by #2359 (reported there).

No title was run.

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088036464 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1645#issuecomment-6088036464). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-09T19:43:38Z. --- Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head `df3aa1a9`, merged onto `main` 8b393b6e in one build with 31 other PRs that had no Windows run. - The change is Linux-only, so this only checks that the Windows build is unaffected. - Full ctest in that build: 520 of 521. The one failure is `guest_offline_imports`, broken by #2359 (reported there). No title was run. _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
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!1645
No description provided.