mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 12:56:06 +00:00
feat: page the session out to zram before suspending it, and zram is always on where supported
This commit is contained in:
1 parent
aaa2e40def
commit
240b7fcce6
43 files changed
+122
-168
No files matched your search
@@ -14,20 +14,6 @@ class ZramSupportTest {
|
||||
assertFalse(ZramSupport.kernelAtLeast("", 5, 4))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun underTwelveGbFromAdvertisedOrTotalMemory() {
|
||||
val gb = 1_000_000_000L
|
||||
val gib = 1L shl 30
|
||||
assertTrue(ZramSupport.belowTwelveGb(8 * gb, 0))
|
||||
assertTrue(ZramSupport.belowTwelveGb(8 * gib, 0))
|
||||
assertFalse(ZramSupport.belowTwelveGb(12 * gb, 0))
|
||||
assertFalse(ZramSupport.belowTwelveGb(12 * gib, 0))
|
||||
assertTrue(ZramSupport.belowTwelveGb(0, 7_400_000L * 1024))
|
||||
assertTrue(ZramSupport.belowTwelveGb(0, 9_300_000L * 1024))
|
||||
assertFalse(ZramSupport.belowTwelveGb(0, 11_100_000L * 1024))
|
||||
assertFalse(ZramSupport.belowTwelveGb(0, 15_600_380L * 1024))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun swapTotalComesFromMeminfo() {
|
||||
assertEquals(12582908L, ZramSupport.swapTotalKb(listOf("MemTotal: 15600380 kB", "SwapTotal: 12582908 kB")))
|
||||
|
||||
@@ -26,6 +26,30 @@ class SessionSuspendControllerTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun pageOutRunsInPreloadedGuestsBeforeTheyStop() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
fixture.controller.freeze(pageOut = true) { assertTrue(it) }
|
||||
val urgent = fixture.signals.filter { it.signal == URG }
|
||||
assertEquals(listOf(GAME), urgent.map { it.pid })
|
||||
assertTrue(fixture.signals.indexOfFirst { it.signal == URG } < fixture.signals.indexOfFirst { it.signal == STOP })
|
||||
assertEquals("1", fixture.control.readText())
|
||||
assertEquals(listOf(Triple(1, 1_000_000L, 3_000_000L)), fixture.pagedOut)
|
||||
assertTrue(fixture.game.threads.all { it.state == 't' })
|
||||
}
|
||||
|
||||
@Test fun noPageOutWithoutTheRequestOrTheControlFile() {
|
||||
val visible = fixture(17)
|
||||
visible.control.writeText("0")
|
||||
visible.controller.freeze { assertTrue(it) }
|
||||
assertFalse(visible.signals.any { it.signal == URG })
|
||||
assertEquals("0", visible.control.readText())
|
||||
val disabled = fixture(17)
|
||||
disabled.controller.freeze(pageOut = true) { assertTrue(it) }
|
||||
assertFalse(disabled.signals.any { it.signal == URG })
|
||||
assertTrue(disabled.pagedOut.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun cpuMustBeStableAcrossTwoCompleteSnapshots() {
|
||||
val fixture = fixture(17)
|
||||
var changes = 0
|
||||
@@ -253,13 +277,13 @@ class SessionSuspendControllerTest {
|
||||
}
|
||||
|
||||
private fun fixture(count: Int, executor: QueueExecutor = InlineExecutor()) =
|
||||
Fixture(temporary.newFolder(), count, executor)
|
||||
Fixture(temporary.newFolder(), temporary.newFolder(), count, executor)
|
||||
|
||||
private data class Task(val tid: Int, var started: Long, var state: Char, var cpu: Long = 0)
|
||||
private data class Group(val pid: Int, var parent: Int, var tracer: Int, val threads: MutableList<Task>)
|
||||
private data class SentSignal(val pid: Int, val signal: Int)
|
||||
|
||||
private class Fixture(val proc: File, count: Int, executor: QueueExecutor) {
|
||||
private class Fixture(val proc: File, tmp: File, count: Int, executor: QueueExecutor) {
|
||||
val root = Group(ROOT, 9000, 0, mutableListOf(Task(ROOT, 1000, 'S')))
|
||||
val game = Group(GAME, ROOT, ROOT, MutableList(count) { Task(GAME + it, 2000L + it, 'S') })
|
||||
val groups = mutableListOf(root, game)
|
||||
@@ -276,10 +300,17 @@ class SessionSuspendControllerTest {
|
||||
var emptyGameTasks = false
|
||||
var rootGone = false
|
||||
var afterSleep: (() -> Unit)? = null
|
||||
val control = File(tmp, ".bl-zram")
|
||||
val pagedOut = mutableListOf<Triple<Int, Long, Long>>()
|
||||
private var gameResidentKb = 4_000_000L
|
||||
private var gameSwapKb = 0L
|
||||
private var pagingOut = false
|
||||
private var continuing = false
|
||||
val controller = SessionSuspendController(
|
||||
{ rootPid }, { helpers }, { audioSuspends++ }, { audioResumes++ },
|
||||
proc, ::signal, ::threadSignal, ::sleep, { now }, executor,
|
||||
zramControl = control,
|
||||
pagedOut = { processes, resident, swap, _, _ -> pagedOut += Triple(processes, resident, swap) },
|
||||
)
|
||||
|
||||
init { sync() }
|
||||
@@ -293,6 +324,8 @@ class SessionSuspendControllerTest {
|
||||
else group.threads.firstOrNull {
|
||||
it.state !in listOf('T', 't', 'Z', 'X') && !(neverStop && it == game.threads.last())
|
||||
}?.state = 't'
|
||||
} else if (signal == URG) {
|
||||
pagingOut = true
|
||||
} else if (signal == CONT) {
|
||||
continuing = true
|
||||
if (!(pid == GAME && blockGameContinue)) group.threads.forEach { if (it.state != 'Z') it.state = 'S' }
|
||||
@@ -311,6 +344,10 @@ class SessionSuspendControllerTest {
|
||||
|
||||
private fun sleep(millis: Long) {
|
||||
now += millis
|
||||
if (pagingOut && gameResidentKb > 1_000_000L) {
|
||||
gameResidentKb -= 1_000_000L
|
||||
gameSwapKb += 1_000_000L
|
||||
}
|
||||
if (root.threads.first().state != 'T' && !continuing) game.threads.forEach {
|
||||
if (it.state != 'Z') { it.state = 'S'; it.cpu++ }
|
||||
}
|
||||
@@ -326,7 +363,11 @@ class SessionSuspendControllerTest {
|
||||
val stat = File(dir, "stat")
|
||||
if (group == game && missingGameStat) stat.delete()
|
||||
else stat.writeText(stat(group, group.threads.first()))
|
||||
File(dir, "status").writeText("TracerPid: ${group.tracer}\n")
|
||||
File(dir, "status").writeText(
|
||||
"TracerPid: ${group.tracer}\n" +
|
||||
if (group == game) "VmRSS:\t$gameResidentKb kB\nVmSwap:\t$gameSwapKb kB\n" else "",
|
||||
)
|
||||
if (group == game) File(dir, "maps").writeText("7f00000000-7f00001000 r-xp 00000000 fe:05 42 /usr/local/lib/libblsession.so\n")
|
||||
val taskDir = File(dir, "task")
|
||||
if (group == game && missingGameTasks) { taskDir.deleteRecursively(); continue }
|
||||
taskDir.mkdirs()
|
||||
@@ -375,5 +416,6 @@ class SessionSuspendControllerTest {
|
||||
const val GAME = 200
|
||||
const val STOP = 19
|
||||
const val CONT = 18
|
||||
const val URG = 23
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user