mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 20:45:43 +00:00
Wait only on spills whose handler started, and read back a late zram fallback
This commit is contained in:
1 parent
088e9994a0
commit
48f587bb41
2 files changed
+46
-10
No files matched your search
@@ -321,7 +321,9 @@ internal class SessionSuspendController(
|
||||
addSnapshot(records, root, helpers)
|
||||
// A restore that finished after the last resume stopped waiting is counted before its marker goes; one
|
||||
// still reading is not asked to spill again.
|
||||
spilledTargets = spilledTargets.filterNot { settled(control, it) }
|
||||
val (done, still) = spilledTargets.partition { settled(control, it) }
|
||||
release(control, done)
|
||||
spilledTargets = still
|
||||
val targets = preloaded(records.values).filterNot { it in spilledTargets }
|
||||
if (targets.isEmpty()) return
|
||||
targets.forEach { ackFile(control, "ack", it).delete(); ackFile(control, "restored", it).delete() }
|
||||
@@ -342,10 +344,11 @@ internal class SessionSuspendController(
|
||||
total += kb
|
||||
kb > 0L
|
||||
}
|
||||
// A process that answered 0 paged out to zram instead and has no spill to release. One that has not
|
||||
// answered may still be writing: it is waited for like a spilled one, its acknowledgement kept.
|
||||
val unanswered = targets.filter { (acks[it] ?: -1L) < 0L && !isGone(it) }
|
||||
spillAsked = spillAsked.filterNot { acks[it] == 0L }
|
||||
// A process that answered 0 paged out to zram instead and has no spill to release. One whose handler
|
||||
// started (its acknowledgement is there, still empty) may still be writing: it is waited for like a
|
||||
// spilled one, its acknowledgement kept. One with no acknowledgement at all has no handler and was never held.
|
||||
val unanswered = targets.filter { (acks[it] ?: -1L) < 0L && ackFile(control, "ack", it).exists() && !isGone(it) }
|
||||
spillAsked = spillAsked.filterNot { it in targets && (acks[it] == 0L || !ackFile(control, "ack", it).exists()) }
|
||||
spilledTargets = (spilledTargets + written + unanswered).distinct()
|
||||
pagedOutTargets = (pagedOutTargets + targets.filter { acks[it] == 0L }).distinct()
|
||||
targets.filterNot { it in unanswered }.forEach { ackFile(control, "ack", it).delete() }
|
||||
@@ -357,6 +360,17 @@ internal class SessionSuspendController(
|
||||
readAck(ackFile(control, "restored", record)) != null || readAck(ackFile(control, "ack", record)) == 0L ||
|
||||
isGone(record)
|
||||
|
||||
// Settled targets stop being tracked; one that fell back to zram late is read back like any paged-out one.
|
||||
private fun release(control: File, settledTargets: List<ProcessRecord>) {
|
||||
val lateZram = settledTargets.filter { readAck(ackFile(control, "ack", it)) == 0L && !isGone(it) }
|
||||
pagedOutTargets = (pagedOutTargets + lateZram).distinct()
|
||||
spillAsked = spillAsked.filterNot { it in settledTargets }
|
||||
settledTargets.forEach {
|
||||
ackFile(control, "restored", it).delete()
|
||||
ackFile(control, "ack", it).delete()
|
||||
}
|
||||
}
|
||||
|
||||
private fun resumeFile(control: File) = File(control.parentFile, "${control.name}.resume")
|
||||
|
||||
private fun resumeCount(control: File): Long = try {
|
||||
@@ -401,10 +415,7 @@ internal class SessionSuspendController(
|
||||
} catch (_: InterruptedException) {
|
||||
Thread.currentThread().interrupt()
|
||||
}
|
||||
targets.filterNot { it in waiting }.forEach {
|
||||
ackFile(control, "restored", it).delete()
|
||||
ackFile(control, "ack", it).delete()
|
||||
}
|
||||
release(control, targets.filterNot { it in waiting })
|
||||
spilledTargets = waiting.toList()
|
||||
restored(targets.size, waiting.size, memoryKb(targets).first, nowMillis() - start)
|
||||
return waiting.isEmpty()
|
||||
|
||||
@@ -205,6 +205,28 @@ class SessionSuspendControllerTest {
|
||||
assertTrue(fixture.game.threads.none { it.state == 't' || it.state == 'T' })
|
||||
}
|
||||
|
||||
@Test fun aGuestWithoutTheSpillHandlerIsNotWaitedForOnResume() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
fixture.handlerReplaced = true
|
||||
fixture.controller.freeze(pageOut = true, spill = true) { }
|
||||
File(fixture.control.parentFile, ".dd-zram.resume.new").mkdirs()
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
assertTrue(fixture.restores.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun aLateFallbackToZramIsReadBack() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
fixture.spillSilent = true
|
||||
fixture.controller.freeze(pageOut = true, spill = true) { }
|
||||
fixture.spillSilent = false
|
||||
fixture.spillFallsBack = true
|
||||
fixture.advance(1_000L)
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
assertEquals(1, fixture.pagedIn.size)
|
||||
}
|
||||
|
||||
@Test fun aGuestThatFellBackToZramResumesWhenTheCountCannotBeWritten() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
@@ -692,7 +714,10 @@ class SessionSuspendControllerTest {
|
||||
}?.state = 't'
|
||||
} else if (signal == URG) {
|
||||
if (request?.startsWith("4") == true) {
|
||||
spilling = true
|
||||
if (!handlerReplaced) {
|
||||
spilling = true
|
||||
File(control.parentFile, "${control.name}.ack.$GAME").writeText("")
|
||||
}
|
||||
spilledBase = request.substringAfter(' ', "0").trim()
|
||||
}
|
||||
else if (request == "0") { pagingOut = false; pagingIn = true } else pagingOut = true
|
||||
|
||||
Reference in new issue
Block a user