Saturday, 23 July 2016

Stopping UT from killing apps



I finally found a way to not have my apps killed all the time!

I am using a device with 2 GB of ram (Nexus 7 2013) and I experienced frequently that apps are killed. Quite often it gets so bad that it's impossible to have both dekko and the browser open at the same time. It always felt like it was an out of memory situation. Today I stumbled over this remark of ShadowEO on his github page to configure the lowmemorykiller. In my experience, I need two other tweaks in addition. So in total I did the following three things:
  1. Increase the swappiness
    Checking with

    Code:


    dstat --top-oom --top-mem --vmstat -s 30

    and

    Code:


    tail -f /var/log/syslog  | grep sigkill

    I see which app the out-of-memory killer (oom) considers for killing and I see when that app is being killed. Also, I see that even though there is swap space available, it isn't being used. In order to make the system actually use the available swap space I increased the swappiness from 0 to 70:

    Code:


    cat /proc/sys/vm/swappiness
    0
    echo 70 | sudo tee /proc/sys/vm/swappiness



  2. Increase swapspace
    Now the swap is being used, but it doesn't seem to make a whole lot of a difference with the killing, so I increase the size of the swapspace.
    Out of the box, if I remember it correctly, I only had 32 MB of swap:

    Code:


    swapon -s

    The swap file being /userdata/SWAP.img. I increased it to 2 GB following these tips:

    Code:


    sudo swapoff /userdata/SWAP.img
    sudo rm /userdata/SWAP.img
    sudo fallocate -l 2g /userdata/SWAP.img
    sudo chmod 0600 /userdata/SWAP.img
    sudo swapon /userdata/SWAP.img



  3. Configure the lowmemorykiller
    Now a little more of the swap is being used, but it still doesn't stop the killing. Seems on Android there is something called lowmemorykiller, which on my Nexus 7 had this original configuration:

    Code:


    cat /sys/module/lowmemorykiller/parameters/minfree
    1536,2048,4096,16384


    Where 16384 pages (4k each) corresponds to 16384*4/1024 = 64 MB. So, seems that once the free memory drops below 64MB, the killing starts. Inspired by ShadowEO's tip, I set it:

    Code:


    echo "1536,2048,4096,5120,10240,15360" | sudo tee /sys/module/lowmemorykiller/parameters/minfree

    which corresponds to 20 instead of 64 MB. (I also set the last two levels to 40 and 60 MB - don't know whether that is needed.)


With all three things in place, I can now have the browser, dekko, podbird, filemanager, unav, uradio playing music, terminal and gedit and libreoffice writer running from libertine all open at the same time. I'm almost running out of apps that I care to run in addition :)

At times there was some stuttering, but of course nobody forces you to have so many apps open at the same time. However, now you can choose what you want to close to relieve the memory pressure :) Swappiness and lowmemorykiller I need to repeat after every reboot. Need to find a solution to persist this.

I'd be curious to hear whether/how this works for other people!



No comments:

Post a Comment