본문 바로가기

Programming/Android

Android low memory killer disable 하기

  • Low memory killer was added as a kernel extension to the Android. The main source code is located at "/drivers/staging/android/lowmemorykiller.c". One of the interesting things to observe is the directory "staging" where the source code resides. Google added some of the kernel extensions such as wakelocks, lowmemkiller, logger, binder etc. which were never added to the mainline kernel branch. There is an interesting story associated with it, that Google did all the development behind closed doors and presented these extensions to the open source community. And, since the Linux open source community never accepted these changes, that is why the source code is under "staging" directory! You can read more on this here.

    OOM Killer
    Anyhow, Android's lowmemkiller is sort of an extension to the Linux's OOM (out-of-memory) killer. Before I explain about it, let me briefly talk about OOM killer and how to disable it. OOM killer is used to kill one or more processes in order to free up memory for the system. It basically calculates the "badness" by accumulating points for each process and the process then with the highest points is KILLED by sending a SIGTERM/SIGKILL signal to it. Two ways to disable it are as follows:
    - To disable it for a particular process, set value of the VM parameter "/proc/{pid}/oom_adj" to "-17". This will prevent this process from getting selected by OOM killer under low memory conditions.
    - To disable it system-wide, we need to modify two of the VM parameters. Set "overcommit_memory" to "2" and "overcommit_ratio" to "100". These are located in "/proc/sys/vm". You can either echo above values directly at the run-time (echo 2 > overcommit_memory) or add it to the sysctl.conf to make changes permanent (echo "vm.overcommit_memory=2" >> sysctl.conf).

    Lowmemory Killer
    Android mainly uses "lowmemory killer" to kill processes under low memory conditions. One might question, why do we need this at all. Can't we just SWAP out pages to the disk like any other OS. And the answer is NO, as there is no swap space on Android, although one can enable it if you have the source (perks of using an open-source system!). Android lowmem killer kills processes according to the priorities. "/init.rc" defines priority values & minimum free memory size for each priority. "ActivityManagerService" updates priority values for the processes in the memory. For ex - Foreground applications (one running on the main UI thread) is assigned the highest priority, so that it does not get killed. And priorities are further assigned so on to visible, hidden/empty applications. One way to disable (rather tune it) is by changing the "minfree" parameter in "init.rc". This will still not completely disable it. Again, set oom_adj to -17 to disable it for a process (Remember, its build on top of OOM killer). To disable it completely, you can make changes to the source code by commenting out the statement that sends SIGKILL to the selected process (lowmemorykiller.c).

    Note - Making above changes may render you phone unusable. Use caution while trying above options. Best way is to try runtime option (i.e. directly echoing to the files).


'Programming > Android' 카테고리의 다른 글

What is onPreExecute, doInBackground, onPostExecute  (0) 2016.11.02
adb unauthorized issue  (0) 2016.07.21
com.android.internal ...  (0) 2016.03.16
registerReceiver  (0) 2016.03.16
Android.mk file 의 define Hierarchy  (0) 2016.01.12