Android Low Memory Killer

1,993 views
Skip to first unread message

Raja Pavan

unread,
Nov 23, 2010, 7:45:20 AM11/23/10
to Android Linux Kernel Development
We are trying to test Android LowMemoryKiller Driver using a sample
test application.

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

MINFREE module parameter is set from the application.

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

The test application is pasted at the end of this mail. (lowmemTest.c)

Expected Behavior: We have set the oom_adj of the lowmemTest.c to 13.
It is expected to get killed when the free memory in the system (as
seen from the putput of free() command is 5120*4*1024 = 20MB .

We are printing the free memoy of the system by invoking free() inside
the lowmemoryTest.c

Observed Behavior:
(1) But the process is not being killed at the 20MB free memory.
(2) This process is getting killed at the free memory close to the
min_free_kbytes (/proc/sys/vm/min_free_kbytes)

Need Support on these Isssues (Any Patch to kernel)

(1) Is there any patch to the linux 2.6.30 kernel (MM or some other
subsystem) for getting the desired behavior from lowmemorykiller
driver.
(2) We have taken the lowmemory killer for this kernel from android
git, will this work?
(3) Is there any test application available to test the
lowmemorykiller, provided by Google?
(4) Can some provide us clue about improved debugging of this driver?

Please extend help ASAP.

Thanks
Raja



Dianne Hackborn

unread,
Nov 23, 2010, 12:19:09 PM11/23/10
to android...@googlegroups.com
Have you run your tests on the stock platform (even just the emulator) to see if you are getting the behavior you expect there?  There are a *lot* of potential gotchas if trying to test this behavior: running at the right oom_adj, fuzziness in the definition of "free memory", etc.  I would suggest validating your test first on a known working build before using it to draw conclusions about the  behavior of your own build.




--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

Raja Pavan

unread,
Nov 23, 2010, 11:48:49 PM11/23/10
to Android Linux Kernel Development

Please let me know if there is some test appliaction available in
android repository. (CTS or some where)

I am pasting the code of sample test application below.

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <unistd.h>

int main()
{
int size,i=0;
int **ptr = NULL;
int pid[6];
pid_t my_pid = (pid_t) 0;
char cmdStr[40];
memset(cmdStr, 0, 40);
unsigned long adbd_pid = 0;

ptr = (int **)malloc(2000000*sizeof(int *));//Pointer to hold 2M
Another pointer
int free_levels[6] = {1536,2048,4096,5120,5632,6144}; //

//Overwriting the default lowmemorykiller module parameters
system("cat /sys/module/lowmemorykiller/parameters/minfree");
system("echo 1536,2048,4096,5120,5632,6144 >/sys/module/
lowmemorykiller/parameters/minfree");
system("cat /sys/module/lowmemorykiller/parameters/minfree");
system("cat /proc/sys/vm/min_free_kbytes");

my_pid = getpid();

sprintf(cmdStr, "echo 13 > /proc/%d/oom_adj", my_pid);
system(cmdStr);

while(i++ < 240) //240 MB Memory
{
size = 256*1024*sizeof(int); //1MB
ptr[i] = (int *)malloc(size);

int *write=ptr[i];
if(ptr[i]!=NULL)
{
size = size/sizeof(int);
//printf("Success in malloc");
while(size--)
*write++=size;
system("/usr/bin/free");
}
else
{
printf("malloc error %d ",ptr[i]);
}
}
}



On Nov 23, 5:45 pm, Raja Pavan <rajain...@gmail.com> wrote:
> We are trying to test Android LowMemoryKiller Driver using a sample
> test application.
>
> /sys/module/lowmemorykiller/parameters/adj 0,1,2,7,14,15
>
> MINFREE module parameter is set from the application.
>
> echo 1536,2048,4096,5120,5632,6144 >/sys/module/lowmemorykiller/
> parameters/minfree
>
> The test application is pasted at the end of this mail. (lowmemTest.c)
>
> Expected Behavior: We have set the oom_adj of the lowmemTest.c to 13.
> It is expected to get killed when the freememoryin the system (as
> seen from the putput of free() command is 5120*4*1024 = 20MB .
>
> We are printing the free memoy of the system by invoking free() inside
> the lowmemoryTest.c
>
> Observed Behavior:
> (1) But the process is not being killed at the 20MB freememory.
> (2) This process is getting killed at the freememoryclose to the
> min_free_kbytes (/proc/sys/vm/min_free_kbytes)
>
> Need Support on these Isssues (Any Patch to kernel)
>
> (1) Is there any patch to the linux 2.6.30 kernel (MM or some other
> subsystem) for getting the desired behavior from lowmemorykiller
> driver.
> (2) We have taken the lowmemorykillerfor this kernel from android

Raja Pavan

unread,
Nov 25, 2010, 12:49:21 AM11/25/10
to Android Linux Kernel Development
Hi Dianne

I did run the test application (shared with you) on emulator.

It was killed.

It has been observed that the adb shell is also killed (as it is not
available anymore)

But How do I know whether the process is crashing at the watermark
level?

Thanks
Raja
> > unsubscribe: android-kerne...@googlegroups.com<android-kernel%2Bunsubscribe@go­oglegroups.com>
> > website:http://groups.google.com/group/android-kernel
>
> --
> Dianne Hackborn
> Android framework engineer
> hack...@android.com
>
> Note: please don't send private questions to me, as I don't have time to
> provide private support, and so won't reply to such e-mails.  All such
> questions should be posted on public forums, where I and others can see and
> answer them.- Hide quoted text -
>
> - Show quoted text -

Dianne Hackborn

unread,
Nov 25, 2010, 1:17:14 AM11/25/10
to android...@googlegroups.com
There are no guarantees about things being killed at an exact level.  In fact what the current "memory level" is, is quite fuzzy if not just outright not knowable.

Is there a problem you are trying to address?




--
Dianne Hackborn
Android framework engineer

Raja Pavan

unread,
Nov 25, 2010, 1:37:02 AM11/25/10
to Android Linux Kernel Development
Is there any test methodology available from android, for testing LMK
driver?

Dianne Hackborn

unread,
Nov 25, 2010, 3:56:20 AM11/25/10
to android...@googlegroups.com
Unfortunately there are no unit test cases; at the end of the day, this is often a part of tuning the platform and seeing that it is behaving appropriately in use.

That said, I would really like to have some CTS tests for this.  These are tricky to do since the guarantees are so loose, but I think some basic stuff can be done.  For example a test could:

1. Start an activity in process A.
2. Start a service in process B.
3. Start another activity in process C.

Now process A is a background process, B is a service, and C is foreground.  If C starts using memory, A should be killed before B which is killed before C.  It is tricky however to put this together so it works as a unit test with dependable behavior.




--
Dianne Hackborn
Android framework engineer

ksam

unread,
Jan 29, 2014, 9:00:56 AM1/29/14
to android...@googlegroups.com
Hi All,

I am trying to understand working of low memory killer. Can you please suggest from where lowmem_shrink function is getting called. And in which part of source code the the threshold values will be compared or how the OS comes to know to start the low memory killer. And in which source code the file /sys/module/lowmemorykiller/parameters/minfree and adj files will be created.
Show sum light on this, it will be vary helpful.

Thanking You,
ksam
Reply all
Reply to author
Forward
0 new messages