feat: adjustable RAM and VRAM caps for the container (#1537)

* feat: adjustable RAM and VRAM caps for the container

Performance > Memory gets two sliders:

- RAM cap (soft, Steam sessions): when the session is resident above the
  cap, the session watcher compresses the Steam client into zRAM, waits for
  its page-out acknowledgment, then compresses the rest of the session
  (processes that loaded libblsession) if still over. Nothing is closed.
  Measured at most every 30 s; the client is read back once usage drops
  below the cap. Invalid values leave the cap off. Needs zRAM swap.
- VRAM cap: sets dxgi.maxDeviceMemory ahead of the game's own DXVK_CONFIG,
  so Direct3D games budget for less video memory. A game profile still
  wins. Applies from the next session.

* fix: back off the RAM cap when paging out cannot get under it

A cap below the game's working set was never met, so the watcher paged out
the client and the whole session every 30 s for the rest of the session.
Usage is still measured every 30 s, but after a page-out that leaves the
session over the cap the next one waits twice as long (60 s up to 10 min),
resetting once usage is under the cap. The client step is skipped while the
client is already under 512 MB resident.

* fix: RAM cap covers desktop Steam, signals each group once, no idle churn

- Steam opened from the desktop runs the same session watcher, so the cap
  is exported whenever the Steam client runs, not only in Steam mode.
- The second page-out goes to the rest of the session only; Steam was
  signalled again even when its own step had been skipped as already small.
- A cap page-out while no game runs stays paged out. Reading the client back
  right away pushed it over the cap again and repeated every minute; only a
  game closing while over the cap still defers a read-back.

* fix: RAM cap marks the client packed only when it compressed it

When the cap skipped the client as already small during a game, it still
recorded the client as packed, so the regular in-game client page-out
waited up to 300 s for a page-out that never happened.

---------

Co-authored-by: jazzyjames <182448902+jazzyjamesgames@users.noreply.github.com>
This commit is contained in:
Jamison Prineandjazzyjames authored and GitHub committed 2026-10-25 12:06:45 -04:00
1 parent dfe8227f49
commit 2be08bc67d
10 files changed
+180 -13

No files matched your search

@@ -28,6 +28,8 @@ import com.droiddeck.launcher.session.SessionPrefs
class CoreRow(val core: Int, val label: String)
private const val MEMORY_CAP_STEP_MB = 256
@Composable
fun PerformancePage(
cores: List<CoreRow>,
@@ -44,6 +46,10 @@ fun PerformancePage(
fsyncFirst: Boolean,
gamescopeRealtime: Boolean,
gpuClockPin: Boolean,
ramCapMb: Int,
vramCapMb: Int,
deviceRamMb: Int,
ramCapAvailable: Boolean,
prootNoSeccomp: Boolean,
prootFastPath: Boolean,
cursorComposite: Boolean,
@@ -60,6 +66,8 @@ fun PerformancePage(
onFsyncFirst: (Boolean) -> Unit,
onGamescopeRealtime: (Boolean) -> Unit,
onGpuClockPin: (Boolean) -> Unit,
onRamCapMb: (Int) -> Unit,
onVramCapMb: (Int) -> Unit,
onProotNoSeccomp: (Boolean) -> Unit,
onProotFastPath: (Boolean) -> Unit,
onCursorComposite: (Boolean) -> Unit,
@@ -123,6 +131,22 @@ fun PerformancePage(
gpuClockPin, onChange = onGpuClockPin,
)
}
SettingsGroup(stringResource(R.string.perf_memory)) {
val top = (deviceRamMb / MEMORY_CAP_STEP_MB * MEMORY_CAP_STEP_MB).coerceAtLeast(MEMORY_CAP_STEP_MB)
val off = stringResource(R.string.perf_cap_off)
val auto = stringResource(R.string.perf_cap_auto)
SliderRow(
stringResource(R.string.perf_ram_cap),
if (ramCapAvailable) stringResource(R.string.perf_ram_cap_hint) else stringResource(R.string.perf_ram_cap_unavailable),
ramCapMb.coerceAtMost(top), 0..top, step = MEMORY_CAP_STEP_MB, enabled = ramCapAvailable,
format = { if (it == 0) off else "$it MB" }, onChange = onRamCapMb,
)
SliderRow(
stringResource(R.string.perf_vram_cap), stringResource(R.string.perf_vram_cap_hint),
vramCapMb.coerceAtMost(top), 0..top, step = MEMORY_CAP_STEP_MB,
format = { if (it == 0) auto else "$it MB" }, onChange = onVramCapMb,
)
}
SettingsGroup(stringResource(R.string.perf_fixes)) {
ToggleRow(
host, "sysmem", stringResource(R.string.perf_sysmem),