LowMemoryKiller in Android
来源:互联网 发布:ghost系统还原软件 编辑:程序博客网 时间:2024/05/17 04:16
Android uses lowmemorykiller driver to kill selected process and free the memory, when some kind of low memory thresholds is met. Two files are generated in /sys file system for system tuning.
1. /sys/module/lowmemorykiller/parameters/adj
This file includes the oomadj array. If the corresponding minfree data is met, one of the process which oomadj are larger than this number will be killed.
About oomadj, the factor is introduced by OOMkiller module in the kernel. It is a property of the process. The range is from -17 to +15, the higher the score, more likely the associated process is to be killed by oom-killer. Lowmemorykiller use this score as well.
http://www.chineselinuxuniversity.net/articles/19534.shtml
2. /sys/module/lowmemorykiller/parameters/minfree
This file includes the threshold numbers for minfree memory size. The unit is page.
Example in Android
The default setting is in system/core/rootdir/init.rc.
# Write value must be consistent with the above properties.
write /sys/module/lowmemorykiller/parameters/adj 0,1,2,7,14,15
write /proc/sys/vm/overcommit_memory 1
write /sys/module/lowmemorykiller/parameters/minfree 1536,2048,4096,5120,5632,6144
# Set init its forked children's oom_adj.
write /proc/1/oom_adj -16
This means if the free memory is smaller than 1536*4K=6MB, one of the processes which adj is larger than 0 will be killed. If the free memory is smaller than 2048*4K=8MB, the process adj larger than 1 will be killed. And so on.
On the other hand, Android put the processes into 6 classes.
# Define the oom_adj values for the classes of processes that can be
# killed by the kernel. These are used in ActivityManagerService.
setprop ro.FOREGROUND_APP_ADJ 0
setprop ro.VISIBLE_APP_ADJ 1
setprop ro.SECONDARY_SERVER_ADJ 2
setprop ro.HIDDEN_APP_MIN_ADJ 7
setprop ro.CONTENT_PROVIDER_ADJ 14
setprop ro.EMPTY_APP_ADJ 15
Say, the FOREGROUND application has the highest priority, the least likely to be killed. The CONTENT_PROVIDER and EMPTY_APP will be killed at first. Confusion here is we know the activity is the one people can see from UI. It actually means the process has foreground activity will have the highest priority, and the process which hosts the activity visible to user has the second priority.
Actually it defines two more priorities as below, in frameworks/base/services/java/com/android/server/am/ActivityManagerService.java
// This is a process running a core server, such as telephony. Definitely
// don't want to kill it, but doing so is not completely fatal.
static final int CORE_SERVER_ADJ = -12;
// The system process runs at the default adjustment.
static final int SYSTEM_ADJ = -16;
In the ActivityManagerService, it starts some core service in a process and assigns it to SYSTEM_ADJ score.
ActivityManagerService.java did some other works as well. For example, it tracks which activity is running in background and foreground, and so it has use-count reference for the process. The java file is 11508 lines, like a monster.
To customize for some short-of-memory devices, we could change the threshold value accordingly. For example:
write /sys/module/lowmemorykiller/parameters/minfree 1536, 4096, 4096, 5120,5632,6144
This makes the driver kill the processes as early as possible. So the new application could get more memory.
These need some tunings and adjustment on hardware. I will try next week
原文地址: http://swcai.blogspot.com/2009/02/lowmemorykiller-in-android.html
- LowMemoryKiller in Android
- Android分析之LowMemoryKiller
- Android分析之LowMemoryKiller
- Android分析之LowMemoryKiller
- Android分析之LowMemoryKiller
- android lowmemorykiller机制简介
- Android lowmemorykiller 原理分析
- Android 7.0 LowMemoryKiller 初识
- android lowmemorykiller笔记
- Android 的lowmemorykiller机制
- Android lowmemorykiller分析
- lowmemorykiller
- Android学习之lowmemorykiller driver
- Android内存管理机制之LowMemoryKiller
- Android 6.0的lowmemorykiller机制
- Android的lowmemorykiller演变分析
- Android 6.0的lowmemorykiller机制
- Android——内存管理-lowmemorykiller 机制
- 换角度思考:http://acm.hdu.edu.cn/showproblem.php?pid=3602
- 二维背包:http://acm.hdu.edu.cn/showproblem.php?pid=3303
- HDU3549 最大流入门
- Jdom开发指南(XML读写操作及XPath语法分析)
- Android进程 Handler Message Looper
- LowMemoryKiller in Android
- Andriod通话处理流程
- quicklisp发布
- Android 图形系统剖析
- Linux查看文件或文件夹大小的实用命令
- C++ Gui Programming With Qt 4 一到十章汉化的是哪个版本??
- 努力,奋斗!
- php异常处理函数
- BlackBerry App World limited time offer: registration and submission fees are waived.