diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session index b44d74599..0f99643ee 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session @@ -552,6 +552,7 @@ case $mode in } # Proton starts its reaper before the game window; compressing during launch stalls it. # Desktop Steam has no focus.json, so it still uses the game process as its trigger. + # A configured RAM cap can still force compression while a game is launching. bl_game_focused() { if [ "${BL_DESKTOP:-}" = 1 ] || [ -z "${BL_LAUNCH_DIR:-}" ]; then return 0 @@ -575,7 +576,7 @@ case $mode in bl_cap_due() { [ "$_bl_ram_cap" -gt 0 ] && { [ "$_bl_measured" -lt 0 ] || [ $((SECONDS - _bl_measured)) -ge 30 ]; } } - _bl_since=-1 _bl_packed=-1 _bl_measured=-1 _bl_unpack=0 _bl_capped=-1 _bl_backoff=30 + _bl_since=-1 _bl_since_apps= _bl_packed=-1 _bl_measured=-1 _bl_unpack=0 _bl_capped=-1 _bl_backoff=30 while kill -0 $$ 2>/dev/null; do bl_zram_scan if bl_cap_due; then @@ -607,7 +608,9 @@ case $mode in fi fi if [ "$_bl_game" = 1 ] && bl_game_focused; then - [ "$_bl_since" -ge 0 ] || _bl_since=$SECONDS + if [ "$_bl_since" -lt 0 ] || [ "$_bl_since_apps" != "$_bl_apps" ]; then + _bl_since=$SECONDS _bl_since_apps=$_bl_apps + fi if [ "${BL_ZRAM_CLIENT:-1}" = 1 ] && [ $((SECONDS - _bl_since)) -ge 20 ] && [ "${#_bl_pids[@]}" -gt 0 ] && { [ "$_bl_packed" -lt 0 ] || [ $((SECONDS - _bl_packed)) -ge 300 ]; }; then bl_zram_send 1 "compressing the client" client diff --git a/tools/tests/test_client_zram_focus.py b/tools/tests/test_client_zram_focus.py index c542f21a2..b35902e7f 100644 --- a/tools/tests/test_client_zram_focus.py +++ b/tools/tests/test_client_zram_focus.py @@ -25,7 +25,7 @@ class ClientZramFocusTest(unittest.TestCase): stop = source.index(' nap 5', start) body = source[start:stop] harness = ''' -_bl_since=-1 _bl_packed=-1 +_bl_since=-1 _bl_since_apps= _bl_packed=-1 _bl_apps=" 413150" _bl_pids=(123) bl_game_focused() { [ "$focused" = 1 ]; } bl_over_cap() { return 1; } @@ -53,8 +53,10 @@ tick 60 0 0 start = source.index(' bl_zram_scan\n if bl_cap_due; then') stop = source.index(' nap 5', start) return ''' -_bl_since=-1 _bl_packed=-1 _bl_measured=-1 _bl_unpack=0 _bl_capped=-1 _bl_backoff=30 +_bl_since=-1 _bl_since_apps= _bl_packed=-1 _bl_measured=-1 _bl_unpack=0 _bl_capped=-1 _bl_backoff=30 +_bl_apps=" 413150" _bl_pids=(123) +step() { :; } bl_zram_scan() { :; } bl_game_focused() { [ "$focused" = 1 ]; } bl_cap_due() { [ "$cap_due" = 1 ]; } @@ -75,6 +77,32 @@ tick 30 0 0 0 0 self.assertEqual('', result.stderr) self.assertEqual('', result.stdout) + def test_a_new_game_restarts_the_compression_delay(self): + result = run_bash(self.monitor_harness() + ''' +tick 0 1 1 0 0 +_bl_apps=" 413150 1245620" +tick 15 1 1 0 0 +tick 20 1 1 0 0 +echo "starting:$_bl_packed" +tick 34 1 1 0 0 +tick 35 1 1 0 0 +''') + self.assertEqual(0, result.returncode, result.stderr) + self.assertEqual('', result.stderr) + self.assertEqual(['starting:-1', 'send:1:client'], result.stdout.splitlines()) + + def test_ram_cap_can_still_compress_an_unfocused_client(self): + result = run_bash(self.monitor_harness() + ''' +BL_ZRAM_CLIENT=0 BL_RAM_CAP_MB=1024 +bl_zram_usage() { _bl_rss=$((768 * 1024)); } +tick 0 1 0 1 1 +echo "cap:$_bl_packed:$_bl_since:$_bl_backoff" +tick 5 0 0 0 0 +''') + self.assertEqual(0, result.returncode, result.stderr) + self.assertEqual('', result.stderr) + self.assertEqual(['send:1:client', 'send:1:session', 'cap:0:-1:60', 'send:0:client'], result.stdout.splitlines()) + def test_game_exit_defers_restore_until_the_session_is_under_the_ram_cap(self): result = run_bash(self.monitor_harness() + ''' tick 0 1 1 0 0