From fbf17886470b190c248cd2fecd45a5ad99a63e4f Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Sat, 5 Dec 2026 04:21:28 -0500 Subject: [PATCH] Keep a spill without an acknowledgement asked, so a failed resume count still fails --- .../session/SessionSuspendController.kt | 6 ++-- .../session/SessionSuspendControllerTest.kt | 29 ++++++++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionSuspendController.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionSuspendController.kt index d4b3942020..9ace85ec85 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionSuspendController.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionSuspendController.kt @@ -346,9 +346,11 @@ internal class SessionSuspendController( } // 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. + // spilled one, its acknowledgement kept. One with no acknowledgement may have no handler, or one that has + // not got that far: it is not waited for, but stays asked, so a resume count that cannot be written still + // fails (a late spill waits for any count other than the one it was asked with). 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()) } + spillAsked = spillAsked.filterNot { acks[it] == 0L } spilledTargets = (spilledTargets + written + unanswered).distinct() pagedOutTargets = (pagedOutTargets + targets.filter { acks[it] == 0L }).distinct() targets.filterNot { it in unanswered }.forEach { ackFile(control, "ack", it).delete() } diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionSuspendControllerTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionSuspendControllerTest.kt index 33b125bcbe..43a70703f1 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionSuspendControllerTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionSuspendControllerTest.kt @@ -210,11 +210,31 @@ class SessionSuspendControllerTest { 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 aSpillThatStartsAfterTheWaitFailsAResumeCountThatCannotBeWritten() { + 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 { assertFalse(it) } + } + + @Test fun aSpillThatStartsAfterTheWaitIsReleasedByTheNextCount() { + val fixture = fixture(17) + fixture.control.writeText("0") + fixture.handlerReplaced = true + fixture.controller.freeze(pageOut = true, spill = true) { } + fixture.startLateSpill() + fixture.controller.resume { assertTrue(it) } + fixture.advance(1_000L) + assertTrue(File(fixture.control.parentFile, ".dd-zram.restored.$GAME").isFile) + assertTrue(fixture.game.threads.none { it.state == 't' || it.state == 'T' }) + } + @Test fun aLateFallbackToZramIsReadBack() { val fixture = fixture(17) fixture.control.writeText("0") @@ -745,6 +765,13 @@ class SessionSuspendControllerTest { fun advance(millis: Long) = sleep(millis) + // the handler takes the spill request only now, after the controller stopped waiting for it + fun startLateSpill() { + handlerReplaced = false + spilling = true + File(control.parentFile, "${control.name}.ack.$GAME").writeText("") + } + private fun sleep(millis: Long) { now += millis if (spilling && !spillSilent) {