mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 13:05:47 +00:00
Release zram fallbacks on resume and count late restores before another spill
This commit is contained in:
1 parent
7ad52166a2
commit
644f8e655f
3 files changed
+52
-5
No files matched your search
@@ -319,7 +319,10 @@ internal class SessionSuspendController(
|
||||
// the resume counter changes; its acknowledgement is the kB it wrote, 0 when it paged out to zram instead.
|
||||
private fun spill(control: File, records: MutableMap<Pair<Int, Long>, ProcessRecord>, root: Int, helpers: List<Int>) {
|
||||
addSnapshot(records, root, helpers)
|
||||
val targets = preloaded(records.values)
|
||||
// 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 { readAck(ackFile(control, "restored", it)) != null || isGone(it) }
|
||||
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() }
|
||||
val start = nowMillis()
|
||||
@@ -333,11 +336,14 @@ internal class SessionSuspendController(
|
||||
sleep(PAGE_OUT_POLL_MS)
|
||||
}
|
||||
var total = 0L
|
||||
val acks = targets.associateWith { readAck(ackFile(control, "ack", it)) }
|
||||
val written = targets.filter { record ->
|
||||
val kb = readAck(ackFile(control, "ack", record)) ?: 0L
|
||||
val kb = acks[record] ?: 0L
|
||||
total += kb
|
||||
kb > 0L
|
||||
}
|
||||
// a process that answered 0 paged out to zram instead and has no spill to release
|
||||
spillAsked = spillAsked.filterNot { acks[it] == 0L }
|
||||
spilledTargets = (spilledTargets + written).distinct()
|
||||
pagedOutTargets = (pagedOutTargets + targets.filterNot { it in written }).distinct()
|
||||
targets.forEach { ackFile(control, "ack", it).delete() }
|
||||
|
||||
@@ -191,6 +191,30 @@ class SessionSuspendControllerTest {
|
||||
assertFalse(File(fixture.control.parentFile, ".dd-zram.resume").isFile)
|
||||
}
|
||||
|
||||
@Test fun aGuestThatFellBackToZramResumesWhenTheCountCannotBeWritten() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
fixture.spillFallsBack = true
|
||||
fixture.controller.freeze(pageOut = true, spill = true) { assertTrue(it) }
|
||||
File(fixture.control.parentFile, ".dd-zram.resume.new").mkdirs()
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
assertTrue(fixture.game.threads.none { it.state == 't' || it.state == 'T' })
|
||||
}
|
||||
|
||||
@Test fun aRestoreThatFinishedLateDoesNotHoldBackTheNextResume() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
fixture.controller.freeze(pageOut = true, spill = true) { assertTrue(it) }
|
||||
fixture.restoreDelayMs = 60_000L
|
||||
fixture.controller.resume { assertFalse(it) }
|
||||
fixture.restoreDelayMs = 0L
|
||||
fixture.advance(1_000L)
|
||||
assertTrue(File(fixture.control.parentFile, ".dd-zram.restored.$GAME").isFile)
|
||||
fixture.spillFallsBack = true
|
||||
fixture.controller.freeze(pageOut = true, spill = true) { assertTrue(it) }
|
||||
fixture.controller.resume { assertTrue(it) }
|
||||
}
|
||||
|
||||
@Test fun aGuestThatCouldNotSpillIsReadBackFromZram() {
|
||||
val fixture = fixture(17)
|
||||
fixture.control.writeText("0")
|
||||
@@ -680,6 +704,8 @@ class SessionSuspendControllerTest {
|
||||
sync()
|
||||
}
|
||||
|
||||
fun advance(millis: Long) = sleep(millis)
|
||||
|
||||
private fun sleep(millis: Long) {
|
||||
now += millis
|
||||
if (spilling && !spillSilent) {
|
||||
|
||||
@@ -32,6 +32,7 @@ struct shared {
|
||||
volatile long errors;
|
||||
volatile int stop;
|
||||
volatile int quiet; // readers leave the blocks alone (a page-out they would undo is being measured)
|
||||
volatile int quieted; // readers that have stopped reading
|
||||
};
|
||||
|
||||
static const char *ctl;
|
||||
@@ -58,8 +59,19 @@ static void *work(void *arg) {
|
||||
pthread_sigmask(SIG_BLOCK, &set, NULL);
|
||||
}
|
||||
unsigned seed = (unsigned)id * 77u + 1u;
|
||||
int idle = 0;
|
||||
while (!shared->stop) {
|
||||
if (shared->quiet) continue;
|
||||
if (shared->quiet) {
|
||||
if (!idle) {
|
||||
idle = 1;
|
||||
__atomic_add_fetch(&shared->quieted, 1, __ATOMIC_RELEASE);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (idle) {
|
||||
idle = 0;
|
||||
__atomic_sub_fetch(&shared->quieted, 1, __ATOMIC_RELEASE);
|
||||
}
|
||||
if (!same(blocks[id], size, seed)) __atomic_add_fetch(&shared->errors, 1, __ATOMIC_RELAXED);
|
||||
__atomic_add_fetch(&shared->progress, 1, __ATOMIC_RELAXED);
|
||||
}
|
||||
@@ -156,7 +168,10 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
while (shared->progress < 50) nap(10);
|
||||
long before = rss_kb(child);
|
||||
if (undumpable) shared->quiet = 1;
|
||||
if (undumpable) {
|
||||
shared->quiet = 1;
|
||||
for (int waited = 0; __atomic_load_n(&shared->quieted, __ATOMIC_ACQUIRE) < THREADS && waited < 5000; waited += 1) nap(1);
|
||||
}
|
||||
put(".hold", "4 0");
|
||||
kill(child, SIGURG);
|
||||
long spilled = wait_for(".ack.", child, 20000);
|
||||
@@ -167,7 +182,7 @@ int main(int argc, char **argv) {
|
||||
long frozen_now = shared->progress;
|
||||
put(".resume", "1");
|
||||
long restored = spilled > 0 ? wait_for(".restored.", child, 20000) : 0;
|
||||
nap(300);
|
||||
for (int waited = 0; shared->progress == frozen_now && waited < 10000; waited += 10) nap(10);
|
||||
long resumed = shared->progress;
|
||||
long back = rss_kb(child);
|
||||
shared->stop = 1;
|
||||
|
||||
Reference in new issue
Block a user