From c6333350aeb5d5079151ff69bafcbb2754e9b197 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Sat, 5 Dec 2026 04:34:25 -0500 Subject: [PATCH] Drop a spill request that reaches the handler after the resume it was asked before --- tools/linuxfs/preload/zram.c | 9 ++++++++- tools/tests/test_zram_spill_preload.py | 11 ++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/tools/linuxfs/preload/zram.c b/tools/linuxfs/preload/zram.c index c2c35b8f6a..b705aaf2b6 100644 --- a/tools/linuxfs/preload/zram.c +++ b/tools/linuxfs/preload/zram.c @@ -745,7 +745,7 @@ static int zr_resumed(void) { // Runs in a process that shares the owner's memory, so it keeps running while every owner thread is stopped. static void zr_helper(void) { zr_sys(SYS_prctl, PR_SET_NAME, "zr-spill"); - if (!zr_seize_all()) { + if (!zr_seize_all() || zr_resumed()) { zr_detach_all(); return; } @@ -816,9 +816,16 @@ static void zr_request(int worker) { int mode = zr_mode(&want); if (mode < 0) return; if (mode == 4) { + // A request that reaches this after the resume it was asked before has nothing left to do: the + // controller no longer waits for it, and holding the process now would stop it after the resume. +#if defined(__aarch64__) + zr_baseline = zr_request_arg; + if (zr_resumed()) return; +#endif zr_ack(-1, ".ack."); #if defined(__aarch64__) if (worker && zr_spill()) return; + if (zr_resumed()) return; #endif zr_visits = worker ? ZR_FAILED : ZR_INLINE_CHUNKS; zr_walk(1, 1, 0, 0); diff --git a/tools/tests/test_zram_spill_preload.py b/tools/tests/test_zram_spill_preload.py index 7deab8d601..17abc87615 100644 --- a/tools/tests/test_zram_spill_preload.py +++ b/tools/tests/test_zram_spill_preload.py @@ -179,9 +179,11 @@ int main(int argc, char **argv) { return 5; } } + int stale = argc > 3 && !strcmp(argv[3], "stale"); + if (stale) put(".resume", "1"); // resumed already: the request below comes too late put(".hold", "4 0"); kill(child, SIGURG); - long spilled = wait_for(".ack.", child, 20000); + long spilled = wait_for(".ack.", child, stale ? 2000 : 20000); long after = rss_kb(child); shared->quiet = 0; long frozen_at = shared->progress; @@ -259,6 +261,13 @@ class ZramSpillPreloadTest(unittest.TestCase): self.assertGreater(r["resumed"], 0) self.assertEqual(r["errors"], 0) + def test_a_request_that_arrives_after_the_resume_is_dropped(self): + r = self.run_spill("stale") + self.assertEqual(r["exit"], 0) + self.assertLess(r["spilled"], 0) # no answer: nothing was held or written + self.assertGreater(r["frozen"], 0) # it kept running throughout + self.assertEqual(r["errors"], 0) + def test_a_process_that_cannot_be_traced_falls_back_to_zram(self): r = self.run_spill("undumpable") self.assertEqual(r["exit"], 0)