mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 13:55:58 +00:00
feat(session): manage memory automatically and remove the manual memory controls (#2853)
Memory in the Steam session is kept above a floor by a monitor instead of the zRAM, RAM cap and VRAM cap settings, which are removed.
This commit is contained in:
1 parent
123c431b8e
commit
adf13d0bdd
60 files changed
+1117
-2264
No files matched your search
@@ -234,8 +234,6 @@ object SessionFiles {
|
||||
val gpuLoad = listOf(
|
||||
"usr/local/lib/droiddeck-gpuload/libVkLayer_droiddeck_gpuload.so" to "usr/local/lib/droiddeck-gpuload/libVkLayer_droiddeck_gpuload.so",
|
||||
"usr/local/lib/droiddeck-gpuload/VK_LAYER_DROIDDECK_gpu_load.json" to "usr/share/vulkan/implicit_layer.d/droiddeck_gpu_load.json",
|
||||
"usr/local/lib/droiddeck-gpuload/libVkLayer_droiddeck_vramcap.so" to "usr/local/lib/droiddeck-gpuload/libVkLayer_droiddeck_vramcap.so",
|
||||
"usr/local/lib/droiddeck-gpuload/VK_LAYER_DROIDDECK_vram_cap.json" to "usr/share/vulkan/implicit_layer.d/droiddeck_vram_cap.json",
|
||||
)
|
||||
val fexPreloads = listOf("x86_64", "i386").flatMap { arch ->
|
||||
listOf("libddsession.so", "libfakeinput.so", "libfaultreport.so").map { "$arch/$it" to "usr/local/lib/droiddeck-fex/$arch/$it" }
|
||||
@@ -282,6 +280,8 @@ object SessionFiles {
|
||||
if (installed) ledger.staged(relative, target) else Log.e(TAG, "$relative NOT staged")
|
||||
}
|
||||
File(root, "usr/local/bin/bannerlator-steam-compat").delete()
|
||||
File(root, "usr/local/lib/droiddeck-gpuload/libVkLayer_droiddeck_vramcap.so").delete()
|
||||
File(root, "usr/share/vulkan/implicit_layer.d/droiddeck_vram_cap.json").delete()
|
||||
LegacyNames.migrateRootfs(root)
|
||||
ComponentsManager.migrateLaunchDir(context)
|
||||
EsyncPacks.stageBundled(context, root)
|
||||
|
||||
@@ -932,29 +932,6 @@ object SessionPrefs {
|
||||
prefs(context).edit().putBoolean("gamescopeRealtime", on).apply()
|
||||
}
|
||||
|
||||
fun ramCapMb(context: Context): Int = prefs(context).getInt("ramCapMb", 0).coerceAtLeast(0)
|
||||
|
||||
fun setRamCapMb(context: Context, mb: Int) {
|
||||
prefs(context).edit().putInt("ramCapMb", mb.coerceAtLeast(0)).apply()
|
||||
}
|
||||
|
||||
fun zramClient(context: Context): Boolean = prefs(context).getBoolean("zramClient", true)
|
||||
|
||||
fun setZramClient(context: Context, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("zramClient", on).apply()
|
||||
}
|
||||
|
||||
fun zramIdle(context: Context): Boolean = prefs(context).getBoolean("zramIdle", true)
|
||||
|
||||
fun setZramIdle(context: Context, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("zramIdle", on).apply()
|
||||
}
|
||||
|
||||
fun vramCapMb(context: Context): Int = prefs(context).getInt("vramCapMb", 0).coerceAtLeast(0)
|
||||
|
||||
fun setVramCapMb(context: Context, mb: Int) {
|
||||
prefs(context).edit().putInt("vramCapMb", mb.coerceAtLeast(0)).apply()
|
||||
}
|
||||
|
||||
fun gpuClockPin(context: Context): Boolean = prefs(context).getBoolean("gpuClockPin", false)
|
||||
|
||||
|
||||
@@ -911,10 +911,9 @@ class SessionService : Service() {
|
||||
))
|
||||
}
|
||||
},
|
||||
readBackAllowed = { SessionPrefs.ramCapMb(this) == 0 },
|
||||
pagedIn = { processes, swapKb, swapBeforeKb, availableKb, millis ->
|
||||
if (processes == 0) {
|
||||
Log.i(TAG, "left ${swapBeforeKb / 1024} MB in zram after resume (RAM cap, or ${availableKb / 1024} MB available is too little)")
|
||||
Log.i(TAG, "left ${swapBeforeKb / 1024} MB in zram after resume (${availableKb / 1024} MB available is too little)")
|
||||
} else {
|
||||
Log.i(TAG, "read back $processes processes in $millis ms: zram ${swapBeforeKb / 1024} -> ${swapKb / 1024} MB")
|
||||
}
|
||||
@@ -1085,11 +1084,7 @@ class SessionService : Service() {
|
||||
relativeMouseForSession().takeIf { it != 0 }?.let { guest.add("gamescope_relative_mouse=$it") }
|
||||
if (com.droiddeck.launcher.core.ZramSupport.supported()) {
|
||||
guest.add("DD_ZRAM=1")
|
||||
if (steamHere) SessionPrefs.ramCapMb(this).takeIf { it > 0 }?.let { guest.add("DD_RAM_CAP_MB=$it") }
|
||||
if (!SessionPrefs.zramClient(this)) guest.add("DD_ZRAM_CLIENT=0")
|
||||
if (!SessionPrefs.zramIdle(this)) guest.add("DD_ZRAM_IDLE=0")
|
||||
}
|
||||
SessionPrefs.vramCapMb(this).takeIf { it > 0 }?.let { guest.add("DD_VRAM_MB=$it") }
|
||||
guest.add("AUDIO_DIRECT_DECAY=0")
|
||||
val extra = extraEnv() + agentEnvironment
|
||||
guest.addAll(TurnipEnvironment.gameEnvironment(tuOverride, tuDriver, SessionPrefs.tuSysmem(this), extra))
|
||||
|
||||
@@ -27,7 +27,6 @@ internal class SessionSuspendController(
|
||||
private val nowNanos: () -> Long = System::nanoTime,
|
||||
private val pagedOut: (processes: Int, unacknowledged: Int, residentKb: Long, swapKb: Long, swapBeforeKb: Long, millis: Long) -> Unit =
|
||||
{ _, _, _, _, _, _ -> },
|
||||
private val readBackAllowed: () -> Boolean = { true },
|
||||
private val pagedIn: (processes: Int, swapKb: Long, swapBeforeKb: Long, availableKb: Long, millis: Long) -> Unit =
|
||||
{ _, _, _, _, _ -> },
|
||||
) {
|
||||
@@ -278,12 +277,21 @@ internal class SessionSuspendController(
|
||||
|
||||
private fun pageOut(records: MutableMap<Pair<Int, Long>, ProcessRecord>, root: Int, helpers: List<Int>) {
|
||||
val control = zramControl?.takeIf { it.isFile } ?: return
|
||||
val hold = holdFile(control)
|
||||
try {
|
||||
addSnapshot(records, root, helpers)
|
||||
control.writeText("1")
|
||||
hold.writeText(PAGE_OUT_REQUEST)
|
||||
sleep(PAGE_OUT_POLL_MS)
|
||||
pageOut(control, records, root, helpers)
|
||||
} catch (_: IOException) {
|
||||
return
|
||||
} finally {
|
||||
hold.delete()
|
||||
}
|
||||
}
|
||||
|
||||
private fun holdFile(control: File) = File(control.parentFile, "${control.name}.hold")
|
||||
|
||||
private fun pageOut(control: File, records: MutableMap<Pair<Int, Long>, ProcessRecord>, root: Int, helpers: List<Int>) {
|
||||
addSnapshot(records, root, helpers)
|
||||
val targets = records.values.filter { record ->
|
||||
try {
|
||||
File(procRoot, "${record.pid}/maps").useLines { lines -> lines.any { it.endsWith("/libddsession.so") } }
|
||||
@@ -301,16 +309,22 @@ internal class SessionSuspendController(
|
||||
val waiting = targets.toMutableList()
|
||||
while (!closing && !cancelled && nowMillis() - start < PAGE_OUT_TIMEOUT_MS) {
|
||||
val started = nowMillis() - start >= PAGE_OUT_START_MS
|
||||
waiting.removeAll { val ack = acks.getValue(it); ack.length() > 0 || (started && !ack.exists()) || isGone(it) }
|
||||
waiting.removeAll { val ack = acks.getValue(it); pagedOut(ack) || (started && !ack.exists()) || isGone(it) }
|
||||
if (waiting.isEmpty()) break
|
||||
sleep(PAGE_OUT_POLL_MS)
|
||||
}
|
||||
val unacknowledged = targets.count { acks.getValue(it).length() == 0L && !isGone(it) }
|
||||
val unacknowledged = targets.count { !pagedOut(acks.getValue(it)) && !isGone(it) }
|
||||
acks.values.forEach { it.delete() }
|
||||
val after = memoryKb(targets)
|
||||
pagedOut(targets.size, unacknowledged, after.first, after.second, before.second, nowMillis() - start)
|
||||
}
|
||||
|
||||
private fun pagedOut(ack: File): Boolean = try {
|
||||
ack.readText().trim() == PAGE_OUT_ACK
|
||||
} catch (_: IOException) {
|
||||
false
|
||||
}
|
||||
|
||||
private fun readBack() {
|
||||
val targets = pagedOutTargets.filterNot { isGone(it) }
|
||||
pagedOutTargets = emptyList()
|
||||
@@ -318,13 +332,15 @@ internal class SessionSuspendController(
|
||||
if (targets.isEmpty() || closing) return
|
||||
val before = memoryKb(targets).second
|
||||
val (total, available) = meminfoKb()
|
||||
if (!readBackAllowed() || !canTake(before, total, available)) {
|
||||
if (!canTake(before, total, available)) {
|
||||
pagedIn(0, before, before, available, 0)
|
||||
return
|
||||
}
|
||||
val hold = holdFile(control)
|
||||
try {
|
||||
control.writeText("0")
|
||||
hold.writeText(READ_BACK_REQUEST)
|
||||
} catch (_: IOException) {
|
||||
hold.delete()
|
||||
return
|
||||
}
|
||||
val start = nowMillis()
|
||||
@@ -341,6 +357,8 @@ internal class SessionSuspendController(
|
||||
}
|
||||
} catch (_: InterruptedException) {
|
||||
Thread.currentThread().interrupt()
|
||||
} finally {
|
||||
hold.delete()
|
||||
}
|
||||
pagedIn(targets.size, swap, before, available, nowMillis() - start)
|
||||
}
|
||||
@@ -456,6 +474,9 @@ internal class SessionSuspendController(
|
||||
const val SIGSTOP = 19
|
||||
const val SIGCONT = 18
|
||||
const val SIGURG = 23
|
||||
const val PAGE_OUT_ACK = "1"
|
||||
const val PAGE_OUT_REQUEST = "1"
|
||||
const val READ_BACK_REQUEST = "0"
|
||||
const val PAGE_OUT_POLL_MS = 100L
|
||||
const val PAGE_OUT_START_MS = 2_000L
|
||||
const val PAGE_OUT_TIMEOUT_MS = 12_000L
|
||||
|
||||
@@ -20,7 +20,7 @@ object SettingsReset {
|
||||
"gamepadLeft", "gamepadRight", "pipAutoEnter", "unfoldedControls", "unfoldedControlsWithController",
|
||||
"stretch16x9", "picturePosition", "integerScaling", "railLabels", "developerTools", "navTabOrder", "navTabShelved", "navTabHidden", "pcKeyboardSize", "pcKeyboardOpacity", "pcKeyboardHiddenKeys",
|
||||
"gpuDriverMode", "androidDriver", "linuxDriver", "linuxDriver.steam", "linuxDriver.desktop",
|
||||
"tuSysmem", "glThread", "noGlError", "zinkLazy", "mangoapp", "gpuClockPin", "gamescopeRealtime", "paceCores", "ramCapMb", "vramCapMb", "zramClient", "zramIdle",
|
||||
"tuSysmem", "glThread", "noGlError", "zinkLazy", "mangoapp", "gpuClockPin", "gamescopeRealtime", "paceCores",
|
||||
"directAudio", "mic", "wifiDiscovery", "clientCpusOverride", "clientCpus", "gameCpus",
|
||||
"noXalia", "fastSync", "fsyncFirst", "syncFallback", "prootNoSeccomp", "prootFastPath", "nativeUserland", "cursorComposite",
|
||||
"guestHostname", "fexPreset", "forceSsbs", "logs", "gameDebugLogsEnabled", "enhancedDiagnosticsNext", "storageDiagnostics", "buildWatermark",
|
||||
|
||||
Reference in new issue
Block a user