How to configure Android's *internal* taskkiller

Search This thread

an0therus3r

Senior Member
Oct 19, 2009
487
23
I used this settings:

echo "1536,3072,4096,21000,23000,25000" > /sys/module/lowmemorykiller/parameters/minfree

But after a while (2 days) i noticed that at least 1 program andFTP was giving me a FC on start.

Trying different settings now.
 

Tikerz

Senior Member
Nov 5, 2005
2,839
654
Mesa, AZ
Those who have disabled Compcache, do you still show a swap file when you type:

Code:
# free

?

I commented out all the lines for Compcache and rebooted, but I'm still showing I have a swap file of 48976KB. I remember before I enabled on Compcache it always showed 0KB in that row.
 

Tikerz

Senior Member
Nov 5, 2005
2,839
654
Mesa, AZ
I used this settings:

echo "1536,3072,4096,21000,23000,25000" > /sys/module/lowmemorykiller/parameters/minfree

But after a while (2 days) i noticed that at least 1 program andFTP was giving me a FC on start.

Trying different settings now.

Are you using this with Compcache enabled or disabled?

Edit: What I'm finding is with Compcache enabled the swap file is not being used because the internal task killer doesn't allow the memory to dip below the threshold to actually use the compcache swap file. Other than claiming that space back by disabling compcache, I'm curious to know if it would be beneficial to configure the internal task killer thresholds or compcache (swappiness setting) to actually use the compcache swap on occasion?
 
Last edited:

androcheck

Senior Member
Dec 7, 2009
236
413
john.zweng.at
Hi everyone,

This seems to work quite well for me too, so I've created a very simple app to help testing, it's in the market place called 'MinFreeManager' or you can search for my nic 'oldskool73' to find it also.
...

Hi oldskool73!

Thanks for the work! :)

Unfortunately I also cannot find it in the market. Is it possible that you declared the app using SDK level 1.6 or higher?
If so, would it be possible to redeploy it using sdk 1.5? Otherwise it will not be found by users of 1.5 ROMs in the market.
 

oldskool73

Member
Jan 27, 2010
42
4
Don't want to hijack this thread, so anyone having trouble finding MinFreeManager in the store or wanting to give feedback etc should hop over to my blog post about it where you can find the APK for download and leave comments....

(sorry, just joined to can't leave external links yet...)
www dustypixels com/blog/2010/01/30/android-app-minfreemanager/

Yeah, it is 1.6+ I'm afraid, it was just created on a whim in one night and I started building it for 2.1 because that's what I'm on, didn't give it much thought. I later tried stepping down the SDK's but it wouldn't build on 1.5, not sure why yet. As you can see on the pic on my blog post, it was 6.30am by then so I just put it up as is. Sorry about that for anyone on 1.5, will take another look when I get a chance.
 
  • Like
Reactions: sowen222

nemesys504

Senior Member
Oct 13, 2006
268
10
New York, NY
Don't want to hijack this thread, so anyone having trouble finding MinFreeManager in the store or wanting to give feedback etc should hop over to my blog post about it where you can find the APK for download and leave comments....

(sorry, just joined to can't leave external links yet...)
www dustypixels com/blog/2010/01/30/android-app-minfreemanager/

Yeah, it is 1.6+ I'm afraid, it was just created on a whim in one night and I started building it for 2.1 because that's what I'm on, didn't give it much thought. I later tried stepping down the SDK's but it wouldn't build on 1.5, not sure why yet. As you can see on the pic on my blog post, it was 6.30am by then so I just put it up as is. Sorry about that for anyone on 1.5, will take another look when I get a chance.

Just wanna say great work and it sucks it doesnt work for 1.5 right now but I was thinking if you could add a default option to your app where it inserts the default values 1536,2048,4096,5120,5632,6144 back to the minfree.
 

Unconn

Senior Member
Dec 3, 2009
396
109
Raleigh
Truely is a nice discovery, i have 10240, 12800,15360 for the last 3 that is 40 50 and 60 Megabytes respectively.

Do you have compcahe enabled?
Yes compcache enabled. I am trying your settings as mine did not seem to be quite aggressive enough (close though). I had to reboot the phone last night and really did notice the difference without these settings. It really is faster with a little more memory free.

I don't see a init.d directory in the etc folder. I'm applying a new ROM, will post update after.

Still no init.d directory
Mine was under:
/system/init.d

HTH
 

askwhy

Senior Member
Jun 26, 2009
220
0
i have 10240, 12800,15360 for the last 3 that is 40 50 and 60 Megabytes respectively.


These values are working out very well for me.

I had trouble with the higher ones in a situation such as minimizing CoPilot Live, which is a real memory-hog, and would always need re-loading after switching to any other application. With your values as stated above, I have been able to switch away from CoPilot to other applications, and then back, without forcing a reload.

...and to androcheck --

Thank you. Thank you! You have, with this excellent work and thread, advanced the goals of the entire android community. I am impressed, having learned a lot this morning, and am extremely grateful as my phone is now simply flying. Cheers!
 

aziz831

Senior Member
Sep 20, 2009
99
4
@Xfight: Glad to see, I could help you. :)
Regarding compcache: I disabled it (for testing) on MCR by commenting out the line
Code:
/system/xbin/insmod /system/lib/modules/ramzswap.ko disksize_kb=XXXXX
in "/system/init.d/ramzswap.sh"

Or just temporarily (until next restart):
Code:
# swapoff /dev/block/ramzswap0

Can someone please point me in the direction of disabling Compcache?

I think thats how you disable compcache
 

aziz831

Senior Member
Sep 20, 2009
99
4
Hi everyone,

This seems to work quite well for me too, so I've created a very simple app to help testing, it's in the market place called 'MinFreeManager' or you can search for my nic 'oldskool73' to find it also.

It simply reads from and writes to /sys/module/lowmemorykiller/parameters/minfree, and auto converts pages to mb to make it a little easier to use.

If there's any interest and we can work out a reliable solution I'll add some way of storing the values after a reboot also.

Hope someone finds it useful :)

I found your app in the market and I am currently using villian2.0.1 ROM can you tell me what values i should set and in which box.

Thanks, If this app works out it will make my life a 100 times easier because i dont know ANYTHING about linux and i tried following the steps in this thread and I am completely lost
 

aziz831

Senior Member
Sep 20, 2009
99
4
!!!

I found your app in the market and I am currently using villian2.0.1 ROM can you tell me what values i should set and in which box.

Thanks, If this app works out it will make my life a 100 times easier because i dont know ANYTHING about linux and i tried following the steps in this thread and I am completely lost

SUCCESS!!! the app works

I used the values specified by androcheck in his first post, i used the very aggressive values of (in megabites): 6, 12, 16, 82, 90, 97

Now my HERO is lightning fast running villian2.0.1

Thanks androcheck and oldskool73
 
  • Like
Reactions: glenb77

oldskool73

Member
Jan 27, 2010
42
4
Update

Hi all,

I've just pushed a 'MinFreeManager' update to the Marketplace, it's jumped to v.1.5 because it now runs on Android 1.5 too! :cool:

I've added some basic presets selectable from the menu (including 'stock' in case you mess something up) and the ability to store your own favourite custom settings. (Remember to 'apply' the values after you select them from the menu).

Have fun :)
 

nemesys504

Senior Member
Oct 13, 2006
268
10
New York, NY
hi all,

i've just pushed a 'minfreemanager' update to the marketplace, it's jumped to v.1.5 because it now runs on android 1.5 too! :cool:

I've added some basic presets selectable from the menu (including 'stock' in case you mess something up) and the ability to store your own favourite custom settings. (remember to 'apply' the values after you select them from the menu).

Have fun :)

Thank you :D
 

Top Liked Posts

  • There are no posts matching your filters.
  • 86
    Hi!

    Note:
    Sorry this posting got very long. But it will tell you how to configure Android's internal taskkiller which may help getting your hero really speedy again.. :) Without using any taskkiller.



    Here the long story:
    I just was curious if already someone tried to play around with Android's internal low-memory task killer.

    We all know that Android uses a different way of handling processes. Instead of killing every process after its Activity ended, processes are kept until the system needs more memory. These processes usually should not harm the overall performance and should give speed improvements if you start an Activity again. That's the idea.

    But when does Android kill a process? And which process? As far as I understood android keeps a LRU (last recently used) list and starts killing the oldest unneeded process. This way it is much smarter than any of the taskkillers we see in the Market.

    Just for curiosity I started to investigate how this mechanism works. Please correct me if you think that I got something wrong:


    What I found out:
    ActivityManagerService.java tracks the "importance" of processes (is foreground, is running a service, ..) and reflects this importance by setting the "oom_adj" value of the process.

    (For info: "oom_adj" is a value of every process under Linux which gives the kernel a hint, which process it can kill in an oom [out of memory] situation. You can see this value on every Linux 2.6 system in the proc directory: /proc/[PID]/oom_adj ). The higher this value is set, the more likely this process gets selected by the kernel's oom killer.)

    It seems that on Android the current forefround application gets an oom_adj value of 0 and as soon it's not visible anymore it gets some higher value. I assume the concrete value is dependent by the processes' place in the LRU list.


    The out-of-memory killer in the standard Linux kernel only runs in one situation: when the available memory is critical low. However in the Android Linux kernel there is implemented a more fine-grained handling of low memory situations.

    I found the kernel source file "lowmemorykiller.c" (located in the kernel source tree under "drivers/misc/"; or look here for GIT source tree: http://tinyurl.com/lowmemkiller).


    This module seems to be more configurable than the kernel's standard out-of-memory killer as you can define more than one memory limit, when it should get active and you can tell it which oom_adj values it may kill.

    In other words:
    You can say "if free memory goes below XXXX then kill some process with oom_adj greater then YYY; if free memory goes even more below than ZZZ then start to kill some processes with oom_adj greater than XYXY. and so on.."

    So it's possible to define multiple memory criterias and matching processes which can be killed in these situations. Android seems to group running processes into 6 different categories (comments taken out of "ActivityManagerServer.java"):
    Code:
    FOREGROUND_APP:
        // This is the process running the current foreground app.  We'd really
        // rather not kill it! Value set in system/rootdir/init.rc on startup.
    
    VISIBLE_APP:
        // This is a process only hosting activities that are visible to the
        // user, so we'd prefer they don't disappear. Value set in
        // system/rootdir/init.rc on startup.
    
    SECONDARY_SERVER:
        // This is a process holding a secondary server -- killing it will not
        // have much of an impact as far as the user is concerned. Value set in
        // system/rootdir/init.rc on startup.
    
    HIDDEN_APP:
        // This is a process only hosting activities that are not visible,
        // so it can be killed without any disruption. Value set in
        // system/rootdir/init.rc on startup.
    
    CONTENT_PROVIDER:
        // This is a process with a content provider that does not have any clients
        // attached to it.  If it did have any clients, its adjustment would be the
        // one for the highest-priority of those processes.
    
    EMPTY_APP:
        // This is a process without anything currently running in it.  Definitely
        // the first to go! Value set in system/rootdir/init.rc on startup.
        // This value is initalized in the constructor, careful when refering to
        // this static variable externally.
    These 6 categories are reflected by 6 memory limits which are configured for the lowmemorykiller in the kernel.

    Fortunately, it is possible to configure the lowmemorykiller at runtime! :)
    (But only if you are root). The configuration is set in the file: "/sys/module/lowmemorykiller/parameters/minfree"

    So if you want to see the current settings, you can do:

    Code:
    # cat /sys/module/lowmemorykiller/parameters/minfree
    This should produce output like this (or similiar):
    Code:
    1536,2048,4096,5120,5632,6144

    These values are the 6 memory limits on which Anedroid starts to kill processes of one of the 6 categories above. Be careful, the units of these values are pages!! 1 page = 4 kilobyte.

    So the example above says that Anddroid starts killing EMPTY_APP processes if available memory goes below 24MB (=6144*4/1024). And it starts to kill unused CONTENT_PROVIDERs if available memory goes below 22MB (=5632*4/1024).


    So if you want to try if your Hero goes faster when fewer processes are running you can try to adjust these settings. For example if you practically do not want any empty processes you can set the corresponding value very high. For example, you can set the values like this:

    Code:
    # echo "1536,2048,4096,5120,15360,23040" > /sys/module/lowmemorykiller/parameters/minfree

    This example will tell Android to kill unused Content providers if less then 60MB is available and kill empty processes if available memory goes below 90MB.

    All other processes will stay untouched! Do you see the advantage compared to process killers?


    One word about durabilty:
    If you change the settings like this, they are NOT PERMANENT. They will be gone after the next restart of your phone. So you can try to play around a little bit. Please share your results if you find some improvements! :)

    To make this settings survive also reboots you need to somehow set this at startup. I am running Modaco's custom rom and added the command to the startup script /system/init.d/ramzswap.sh, but there may be other ways to do this.

    Currently I also disabled compcache on my Hero and set the lowmemkiller very aggressive, as it seems to me that this makes my hero very responsive.

    So these are my (current) settings:
    Code:
    echo "1536,3072,4096,21000,23000,25000" > /sys/module/lowmemorykiller/parameters/minfree
    (and compcache disabled)

    But play around.. I am glad about any feedback. :)
    Please also give feedback if I am wrong or missed something!

    Thx! :rolleyes:
    4

    This is a Hero thread and quite a few months old. Also FYI - taskillers are a fallacy. Increasing the amount of free ram will only serve to reduce the number of apps you can run simultaneously it will NOT speed up your phone.
    These settings could apply to all Android builds, as Android has a built-in task killer for memory management. And no, its not a fallacy (I mean the built-in Android task killer is not a fallacy). It does speed up the phone. The *free* RAM is not unused. Rather it's used by Linux to cache the file system, which does speed things up.

    You can see the real usage by doing:

    # cat /proc/meminfo
    MemTotal: 311340 kB
    MemFree: 3656 kB
    Buffers: 580 kB
    Cached: 92136 kB
    SwapCached: 0 kB
    Active: 194460 kB
    Inactive: 49624 kB
    Active(anon): 154344 kB
    Inactive(anon): 768 kB
    Active(file): 40116 kB
    Inactive(file): 48856 kB
    Unevictable: 2788 kB
    Mlocked: 0 kB
    SwapTotal: 0 kB
    SwapFree: 0 kB
    Dirty: 20 kB
    Writeback: 0 kB
    AnonPages: 154176 kB
    Mapped: 81012 kB
    Shmem: 956 kB
    Slab: 11380 kB
    SReclaimable: 2788 kB
    SUnreclaim: 8592 kB
    KernelStack: 3224 kB
    PageTables: 11800 kB
    NFS_Unstable: 0 kB
    Bounce: 0 kB
    WritebackTmp: 0 kB
    CommitLimit: 155668 kB
    Committed_AS: 6467652 kB
    VmallocTotal: 319488 kB
    VmallocUsed: 93716 kB
    VmallocChunk: 176132 kB

    In this case my Task Manager is reporting almost 100MB free but as you can see, 92MB of that is being used by the OS as cache, and the actual unused RAM is only about 4MB. Linux kernels use most of the "free" RAM for file system caching.
    2
    The difference of this method compared to task killers like "Automatic Task Killer" is that there is no separate application involved.

    There is no widget or taskkiller process which needs to be run.

    Instead you configure the Android kernel itself how to handle processes. While taskkillers need to be run regularly (automatically or by hand) to check memory and kill processes, the way I described this gets done complete automatically by the Android kernel, immediately when available memory goes under the configured limits.

    There is also no need for ignore-lists or something like this, as the Android kernel knows which applications it can kill and which not. Furthermore you can configure much more fine-grained when to kill which processes and the kernel is using the internal "last recently used" list and kills the least needed processes first.

    External task killer only can kill processes "blindly", they cannot see which processes are "empty" (not hosting an Activity) or which have been in the background for the longest time, and so on..


    When people tell you that taskkillers are evil, they mean that taskkillers interfere with Androids process management in a way this was never intended. The way I described you still let Android handling processes itself, but you just tell it to be more restrictive. :)

    So this is far less invasive into the Android system and (should :)) have less side-effects..

    But I'm still learning. I am a programmer who wants to understand things. And fortunately here we have the source to do so.. :cool:
    2
    These values can be directly edited in your initrc
    *APP_ADJ, *APP_MIN_ADJ, *ADJ, *PROVIDER_MEM, *SERVER_MEM and *APP_MEM
    2
    Seems a good time to remind everyone about my MinFreeManager again, an alternative to ratsons AMM.

    You can grab it from the marketplace too, it allows you to change the minfree values and nothing else, it simply makes the changes and quits so no running services or extra fluff (after all it's supposed to be freeing memory, not using it) & just takes up a few kb storage space, and is completely free so no ads :)

    Just an alternative...

    chart

    MinFreeManager 1.6