From 96a12465e01f50b88a617f72b4fadacc34f7938f Mon Sep 17 00:00:00 2001 From: MaxsTechReview Date: Mon, 9 Nov 2026 02:08:40 -0500 Subject: [PATCH] fix(session): stop re-compressing game memory every 30 s when the game reads it straight back (#2312) * fix(session): stop re-compressing game memory every 30 s when the game reads it straight back On devices with 13 GB or less, the low-memory page-out skipped its read-back backoff whenever memory was nearly exhausted. When the game was actively using what was compressed, it read it straight back, so the session pushed and re-read gigabytes every 30 seconds, pinning all cores and freezing the game for 5-10 s each time. The read-back check now applies on that path too: an effective page-out still repeats every 30 s, an ineffective one backs off as on the normal path. * zRAM: keep the read-back backoff on the nearly-out-of-memory path * zRAM: retry a skipped page-out after 30 s when nearly out of memory --- .../overlay/usr/local/bin/droiddeck-session | 10 +++---- tools/tests/test_memory_pressure.py | 27 ++++++++++++++++++- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session index 415f9472f..907364572 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session @@ -902,21 +902,21 @@ case $mode in bl_session_pressure() { bl_memory_read [ "$_bl_game" = 1 ] && bl_low_ram && bl_memory_critical || return 0 - local _wait=$_bl_tier_backoff _urgent=0 _before _pids _targets - [ "$_bl_available" -ge $((_bl_headroom / 2)) ] || _urgent=1 _wait=30 + local _wait=$_bl_tier_backoff _before _pids _targets + [ "$_bl_available" -ge $((_bl_headroom / 2)) ] || [ "$_bl_tier_pushed" -lt 0 ] || _wait=30 [ "$_bl_tier_at" -lt 0 ] || [ $((SECONDS - _bl_tier_at)) -ge "$_wait" ] || return 0 if [ "$_bl_tier_at" -ge 0 ] && [ "$_bl_tier_pushed" -gt 0 ]; then bl_tier_readback if [ "$_bl_tier_back" -le $((_bl_tier_pushed / 2)) ]; then _bl_tier_backoff=30 - elif [ "$_urgent" = 0 ]; then + else _bl_tier_backoff=$((_bl_tier_backoff * 2 > 300 ? 300 : _bl_tier_backoff * 2)) - _bl_tier_at=$SECONDS _bl_tier_pushed=0 + _bl_tier_at=$SECONDS _bl_tier_pushed=-1 step "zRAM: the game read back most of its last page-out, next try in ${_bl_tier_backoff} s" return 0 fi fi - _bl_tier_at=$SECONDS + _bl_tier_at=$SECONDS _bl_tier_pushed=0 bl_zram_pick game bl_zram_usage "${_pids[@]}" > /dev/null [ "$_bl_rss" -ge $((256 * 1024)) ] || return 0 diff --git a/tools/tests/test_memory_pressure.py b/tools/tests/test_memory_pressure.py index 8aa2d1f2c..2c852a7af 100644 --- a/tools/tests/test_memory_pressure.py +++ b/tools/tests/test_memory_pressure.py @@ -229,9 +229,34 @@ echo "backoff:$_bl_tier_backoff" self.assertEqual(['send:1:game', 'send:1:game'], self.run_policy(''' _bl_tier_backoff=300 SECONDS=0; bl_session_pressure -swap=0 SECONDS=20; bl_session_pressure SECONDS=30; bl_session_pressure +''')) + + def test_nearly_out_of_memory_still_backs_off_when_the_game_reads_its_pageout_back(self): + self.memory(available=512) + self.assertEqual(['send:1:game', 'backoff:60', 'send:1:game'], self.run_policy(''' +SECONDS=0; bl_session_pressure +swap=0 +SECONDS=30; bl_session_pressure +echo "backoff:$_bl_tier_backoff" +SECONDS=59; bl_session_pressure +SECONDS=60; bl_session_pressure +SECONDS=90; bl_session_pressure +''')) + + def test_nearly_out_of_memory_retries_a_skipped_pageout_after_30_seconds(self): + self.memory(available=512) + self.assertEqual(['send:1:game', 'send:1:game'], self.run_policy(''' +SECONDS=0; bl_session_pressure +swap=0 +SECONDS=30; bl_session_pressure +_bl_tier_backoff=300 +saved=$rss; rss=$((128 * 1024)) +SECONDS=330; bl_session_pressure +rss=$saved +SECONDS=359; bl_session_pressure +SECONDS=360; bl_session_pressure ''')) def test_small_swap_headroom_skips_the_pageout(self):