diff --git a/docs/development/low-memory.md b/docs/development/low-memory.md index 70916998fc..ba7d5b87fa 100644 --- a/docs/development/low-memory.md +++ b/docs/development/low-memory.md @@ -64,7 +64,7 @@ and the RAM cap are unaffected. The session request runs when real headroom falls below a quarter of RAM (bounded to 768–2560 MiB), or below one and a half times that with at least 1% `some` or `full avg10` memory stall. Real headroom subtracts positive growth in KGSL allocation, `Unevictable`, and -`Shmem` from `MemAvailable`; a rapid fall also qualifies near twice the headroom. The monitor +`Shmem` from `MemAvailable`; a rapid fall also qualifies below twice the headroom or two fifths of RAM, whichever is larger (a 15 GB Thor Max was killed with 5.3 GB still available while memory fell about 400 MB per tick). The monitor may first request page-out of idle Steam and hidden launchers, subject to the Performance setting and client reclaim limits. When both qualify, both requests are sent before waiting for either to complete, so a slow launcher acknowledgement does not delay the game request. Until the client diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session index 82772f80b0..8d169120b4 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session @@ -887,8 +887,10 @@ case $mode in _bl_fall=$((_bl_sample_available - _bl_available)) [ "$_saved_growth" -gt "$_bl_growth" ] && _bl_growth=$_saved_growth [ "$_saved_fall" -gt "$_bl_fall" ] && _bl_fall=$_saved_fall - _bl_sample_at=$SECONDS _bl_sample_available=$_bl_available _bl_sample_gpu=$_bl_gpu - _bl_sample_unevictable=$_bl_unevictable _bl_sample_shmem=$_bl_shmem + if [ $((SECONDS - _bl_sample_at)) -ge 5 ]; then + _bl_sample_at=$SECONDS _bl_sample_available=$_bl_available _bl_sample_gpu=$_bl_gpu + _bl_sample_unevictable=$_bl_unevictable _bl_sample_shmem=$_bl_shmem + fi fi _bl_real_available=$_bl_available [ "$_bl_real_available" -ge 0 ] && _bl_real_available=$((_bl_real_available - _bl_growth)) @@ -898,6 +900,8 @@ case $mode in _bl_tier_headroom=$((_bl_mem_total / 4)) [ "$_bl_tier_headroom" -ge $((768 * 1024)) ] || _bl_tier_headroom=$((768 * 1024)) [ "$_bl_tier_headroom" -le $((2560 * 1024)) ] || _bl_tier_headroom=$((2560 * 1024)) + _bl_fall_headroom=$((_bl_tier_headroom * 2)) + [ "$_bl_fall_headroom" -ge $((_bl_mem_total * 2 / 5)) ] || _bl_fall_headroom=$((_bl_mem_total * 2 / 5)) _bl_swap_reserve=$((_bl_swap_total / 5)) [ "$_bl_swap_reserve" -ge $((256 * 1024)) ] || _bl_swap_reserve=$((256 * 1024)) } @@ -967,7 +971,7 @@ case $mode in [ "$_bl_mem_total" -gt 0 ] && [ "$_bl_available" -ge 0 ] && { [ "$_bl_real_available" -lt "$_bl_tier_headroom" ] || { [ "$_bl_psi" -ge 100 ] && [ "$_bl_real_available" -lt $((_bl_tier_headroom * 3 / 2)) ]; } || - { [ "$_bl_fall" -ge $((256 * 1024)) ] && [ "$_bl_real_available" -lt $((_bl_tier_headroom * 2)) ]; }; } + { [ "$_bl_fall" -ge $((256 * 1024)) ] && [ "$_bl_real_available" -lt "$_bl_fall_headroom" ]; }; } } bl_session_pressure() { bl_memory_read @@ -1030,7 +1034,7 @@ case $mode in } bl_watch_nap() { local _i - if [ "$_bl_game" = 1 ] && [ "$_bl_available" -ge 0 ] && [ "$_bl_real_available" -lt $((_bl_tier_headroom * 2)) ]; then + if [ "$_bl_game" = 1 ] && [ "$_bl_available" -ge 0 ] && [ "$_bl_real_available" -lt "$_bl_fall_headroom" ]; then for _i in 1 2 3 4 5; do nap 1 bl_memory_read diff --git a/tools/tests/test_memory_pressure.py b/tools/tests/test_memory_pressure.py index 5dbb8d8d89..20b6b484ca 100644 --- a/tools/tests/test_memory_pressure.py +++ b/tools/tests/test_memory_pressure.py @@ -204,6 +204,27 @@ SECONDS=30; bl_session_pressure self.memory(total=16384, available=3072, psi='1.23') self.assertEqual(['send:1:session'], self.run_policy('bl_session_pressure')) + def test_a_fast_fall_on_a_large_device_reclaims_above_the_fixed_headroom(self): + self.memory(total=15255, available=6176) + falling = self.root / 'falling' + falling.write_text( + f'MemTotal: {15255 * 1024} kB\nMemAvailable: {5367 * 1024} kB\n' + f'SwapTotal: {8192 * 1024} kB\nSwapFree: {6144 * 1024} kB\n') + meminfo = self.root / 'meminfo' + self.assertEqual(['send:1:session'], self.run_policy( + f'cp {falling} {meminfo}\nSECONDS=5; bl_session_pressure')) + + def test_a_fall_split_across_one_second_polls_still_reclaims(self): + self.memory(total=15255, available=6300) + steps = [] + for second, available in ((5, 6100), (6, 6020), (7, 5940), (8, 5860), (9, 5780)): + sample = self.root / f'meminfo-{second}' + sample.write_text( + f'MemTotal: {15255 * 1024} kB\nMemAvailable: {available * 1024} kB\n' + f'SwapTotal: {8192 * 1024} kB\nSwapFree: {6144 * 1024} kB\n') + steps.append(f'cp {sample} {self.root / "meminfo"}; SECONDS={second}; bl_session_pressure') + self.assertEqual(['send:1:session'], self.run_policy('\n'.join(steps))) + def test_no_game_does_not_compress_the_session(self): self.assertEqual([], self.run_policy('_bl_game=0; bl_session_pressure'))