[Miscellaneous Android Development] stevemp:
Task Killer

The Android kernel has a built in task killer, but I think the people who make our tablets compromise between speed and multitasking. Free memory seems to stay around 50 to 60 megabytes. If you only use a few apps (like me) then be aggressive in killing background processes to speed up system.

ActivityManagerService.java tracks the processes running and gives them a priority to be killed.

Out of Memory adjustment, oom_adj sets the priority of apps.

Comments from ActivityManagerService.java

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.

App starts with a oom_adj value of 0, then moves up in priority to be killed when you switch to another app.

Lowmemorykiller sets the memory level at which apps are killed, 1 page=4 kilobyte.

There are 6 slots available for oom_adj and lowmemorykiller and they work together.

write /sys/module/lowmemorykiller/parameters/adj 0,1,2,7,14,15

write /sys/module/lowmemorykiller/parameters/minfree 1536,2048,4096,5120,5632,6144

0>1536, 1>2048, 2>4096, 7>5120, 14>5632, 15>6144.

What does this mean for us? We can use higher numbers to get more free memory. I like to have between 90 and 100 megabytes free so when starting a new app memory is already available, no waiting on kernel to kill off app to free memory. 0, 1, 2 should not be changed but last three can be increased.

Example> write /sys/module/lowmemorykiller/parameters/minfree 1536,2048,4096,21000,23000,25000

The running (FOREGROUND_APP_ADJ) app always has oom_adj of 0 and I keep home (HOME_APP_ADJ) at 1 to reduce lag when returning to home screen. Try different to see which settings work for your needs.

In Darwin build.prop you find dalvik.vm.heapsize=32m which is the reason it kept crashing on me. I read pdf files on my tablet and 32m is too small. PMP3084BA has 64m and DarmoS gingerbread has 96m values, seems to make system a little slower but more stable.

Hope this helps in modifying your roms, like I said at the beginning, compromise between speed and multitasking. :)

stevemp