文章目录

  • 一、oom_adj 值对应的进程优先级
  • 二、oom_adj 值动态改变
    • 1、正常运行时的 oom_adj 值
    • 2、按下 Home 键后的 oom_adj 值
    • 3、按下回退键后的 oom_adj 值
  • 二、进程保活优化方向

一、oom_adj 值对应的进程优先级


oom_adj 值对应的进程优先级 : 优先级从上到下越来越高 , 最下面的优先级最高 , 最上面的优先级最低 ;

  • UNKNOWN_ADJ = 16 : 缓存进程 ;
  • CACHED_APP_MAX_ADJ = 15 : 不可见进程的 oom_adj 最大值 ;
  • CACHED_APP_MIN_ADJ = 9 : 不可见进程的 oom_adj 最小值 ;
  • SERVICE_B_ADJ = 8 : 在 B 列表中的 Service 服务 , 这些服务比较老 , 再次使用的可能性较小 ;
  • PREVIOUS_APP_ADJ = 7 : 上一个应用程序进程 , 即上一次按下返回键退出的应用 , 缓存应用中的第一个应用 ;
  • HOME_APP_ADJ = 6 : Home 应用所在的进程 , 不能杀 ;
  • SERVICE_ADJ = 5 : 服务进程 ;
  • HEAVY_WEIGHT_APP_ADJ = 4 : 后台的重量级继承 , 启动时在 system/rootdir/init.rc 配置中设置 ;

  • BACKUP_APP_ADJ = 3 : 进入后台的进程 , 按下 Menu 键可查看 , 备份进程 , 可唤醒 ;
  • PERCEPTIBLE_APP_ADJ = 2 : 可感知进程 , 如后台播放音乐 , 铃声 , 震动 , 闪光灯 等除视觉外的其它可感知效果 ;
  • VISIBLE_APP_ADJ = 1 : 可见进程 ;
  • FOREGROUND_APP_ADJ = 0 : 前台进程 ;

  • PERSISTENT_SERVICE_ADJ = -11 : 系统或持久化进程绑定的进程 ;
  • PERSISTENT_PROC_ADJ = -12 : 系统持久化进程 , 如电话进程 ;
  • SYSTEM_ADJ = -16 : 系统进程 ;
  • NATIVE_ADJ = -17 : 本地进程 , 不受系统控制 ;

打印出来的值是上述值 , 不是常量中定义的值 ;

这些 ADJ 值都在 frameworks/base/services/core/java/com/android/server/am/ProcessList.java 源码中以常量形式记录 :

/*** Activity manager code dealing with processes.*/
public final class ProcessList {// The B list of SERVICE_ADJ -- these are the old and decrepit// services that aren't as shiny and interesting as the ones in the A list.static final int SERVICE_B_ADJ = 800;// This is the process of the previous application that the user was in.// This process is kept above other things, because it is very common to// switch back to the previous app.  This is important both for recent// task switch (toggling between the two top recent apps) as well as normal// UI flow such as clicking on a URI in the e-mail app to view in the browser,// and then pressing back to return to e-mail.static final int PREVIOUS_APP_ADJ = 700;// This is a process holding the home application -- we want to try// avoiding killing it, even if it would normally be in the background,// because the user interacts with it so much.static final int HOME_APP_ADJ = 600;// This is a process holding an application service -- killing it will not// have much of an impact as far as the user is concerned.static final int SERVICE_ADJ = 500;// This is a process with a heavy-weight application.  It is in the// background, but we want to try to avoid killing it.  Value set in// system/rootdir/init.rc on startup.static final int HEAVY_WEIGHT_APP_ADJ = 400;// Adjustment used in certain places where we don't know it yet.// (Generally this is something that is going to be cached, but we// don't know the exact value in the cached range to assign yet.)static final int UNKNOWN_ADJ = 1001;// This is a process only hosting activities that are not visible,// so it can be killed without any disruption.static final int CACHED_APP_MAX_ADJ = 906;static final int CACHED_APP_MIN_ADJ = 900;// This is a process currently hosting a backup operation.  Killing it// is not entirely fatal but is generally a bad idea.static final int BACKUP_APP_ADJ = 300;// This is a process currently hosting a backup operation.  Killing it// is not entirely fatal but is generally a bad idea.static final int BACKUP_APP_ADJ = 300;// This is a process only hosting components that are perceptible to the// user, and we really want to avoid killing them, but they are not// immediately visible. An example is background music playback.static final int PERCEPTIBLE_APP_ADJ = 200;// This is a process only hosting activities that are visible to the// user, so we'd prefer they don't disappear.static final int VISIBLE_APP_ADJ = 100;// This is the process running the current foreground app.  We'd really// rather not kill it!static final int FOREGROUND_APP_ADJ = 0;// This is a process that the system or a persistent process has bound to,// and indicated it is important.static final int PERSISTENT_SERVICE_ADJ = -700;// This is a system persistent process, such as telephony.  Definitely// don't want to kill it, but doing so is not completely fatal.static final int PERSISTENT_PROC_ADJ = -800;// The system process runs at the default adjustment.static final int SYSTEM_ADJ = -900;// Special code for native processes that are not being managed by the system (so// don't have an oom adj assigned by the system).static final int NATIVE_ADJ = -1000;// Memory pages are 4K.static final int PAGE_SIZE = 4*1024;}

参考源码 : frameworks/base/services/core/java/com/android/server/am/ProcessList.java

二、oom_adj 值动态改变


1、正常运行时的 oom_adj 值

一个程序的 oom_adj 值是不断动态改变的 , 当程序处于前台时 , 该前台进程的 oom_adj 的值为 0 ,

运行程序 ,

在 Android Studio 中 , 可以看到该运行的程序的进程号 PID 为 308563085630856 ,

进入 adb shell 命令行 , su 获取 root 权限 , 使用如下命令 , 查询指定 PID 的 oom_adj 值 ;

cat /proc/30856/oom_adj

2、按下 Home 键后的 oom_adj 值

点击 Home 键 , 程序退出 , 显示 Home 程序 ,

此时查询该 PID 为 308563085630856 的 oom_adj 值为 121212 , 不可见进程范围是 999 ~ 151515 , 此时的状态是不可见状态 ;

3、按下回退键后的 oom_adj 值

如果是按下回退键退出界面 , 此时查询该 PID 为 308563085630856 的 oom_adj 值为 161616 , 此时进程的状态是缓存进程 , 随时都可能被杀掉 ;

二、进程保活优化方向


优先级越高 , oom_adj 值越小 , 越不能被杀死 ;

如果想要使得进程尽可能长的保留在内存中 , 那么就要减小 oom_adj 的值 ;

在 oom_adj 值相同时 , 内存占用量越大的进程 , 被杀的几率就越高 , 因此这里还要尽可能降低进程占用尽可能少的内存 ;

总结一下就是 ① 降低 oom_adj 值 , ② 减小内存占用 ;

【Android 进程保活】oom_adj 值 ( oom_adj 值对应的进程优先级 | oom_adj 值动态改变 | 进程保活优化方向 )相关推荐

  1. Linux--进程和计划任务管理 理论干货+实操(程序,进程,线程之间关系的详解,静态与动态查看进程方式,控制进程的 方式,一次性任务与周期性任务的设置)

    文章目录 前言 一:程序,进程,线程之间的关系 1.1:进程概述 1.2:应用程序,进程和线程的关系 1.2.1:程序和进程的关系 1.2.2:进程和线程的关系 二:查看进程 2.1:静态查看 ps命 ...

  2. 【Android 逆向】Android 进程注入工具开发 ( 远程调用 | x86 架构的返回值获取 | arm 架构远程调用 )

    文章目录 前言 一.x86 架构的返回值获取 二.ARM 架构远程调用 前言 在之前的博客 [Android 逆向]Android 进程注入工具开发 ( 注入代码分析 | 获取 远程 目标进程 中的 ...

  3. 【Android】你可能还不知道的elevation、以及Z值等

    Android你可能还不知道的elevation以及Z值等 elevation以及Z值是什么 有什么用处呢 影响View的阴影 影响View相互阻挡顺序 还有CardView [Android]你可能 ...

  4. 【Android 逆向】Android 进程注入工具开发 ( 总结 | 源码编译 | 逆向环境搭建使用 | 使用进程注入工具进行逆向操作 ) ★★★

    文章目录 一.Android 进程注入工具开发系列博客 二.Android 进程注入工具 源码下载编译 三.逆向环境搭建 四.使用注入工具进行逆向操作 1.获取远程进程号 2.注入工具准备 3.注入动 ...

  5. 【Android】系统架构功能+init、zygote、system server、app等进程间关系分析

    文章目录 架构功能 Loader层 Linux内核层 硬件抽象层 (HAL) Android Runtime & 系统库 Framework层 App层 Syscall && ...

  6. 搭建Redis服务器: 设置变量school,值为tarena 查看变量school的值

    1.1 问题 具体要求如下: 在主机 192.168.4.51 上安装并启用 redis 服务 设置变量school,值为tarena 查看变量school的值 1.2 步骤 实现此案例需要按照如下步 ...

  7. linux中time命令详解、脚本监控记录系统硬盘io值、定位linux系统中await值过高占用的盘、定位占用硬盘IO高的程序、iotop命令说明、lsof使用说明【可定位端口所占用程序等】

    文章目录 文章说明 linux中的time命令 说明&常规用法 bash中使用time,将运行记录追加到文件中,-f后的参数说明 高阶用法 time 命令详细输出指标介绍 ime taken ...

  8. sql-case when 条件1 then 取值1 when 条件2 then 取值2 else 取值3 end

    遇到 XXX情况 就 XXX 遇不到就 XXX 结束 case when -- then -- else -- end 例如一个3条件取值的字段: case when 条件1 then 取值1 whe ...

  9. R语言dplyr包的mutate函数将列添加到dataframe中或者修改现有的数据列:使用na_if()函数将0值替换为NA值、负收入替换为NA值

    R语言dplyr包的mutate函数将列添加到dataframe中或者修改现有的数据列:使用na_if()函数将0值替换为NA值.负收入替换为NA值 目录

最新文章

  1. 梯度下降算法的正确步骤是什么?
  2. Java并发编程原理与实战一:聊聊并发
  3. 对于细节的一些处理和领悟
  4. 数据结构考完,想了很多。
  5. node服务成长之路
  6. numpy数组中冒号[:,:,0]与[...,0]的区别
  7. 你必须搞清楚的String,StringBuilder,StringBuffer
  8. Flume安装(单节点)
  9. oracle字段属性设置下拉列表,下拉列表 select-option ; select-optgroup-option
  10. java类作为多层级的数据实体_API json多层数据实体类封装(利用泛型技术)
  11. 详解 HTTPS 移动端对称加密套件优
  12. 客户端(浏览器端)数据存储技术概览
  13. 【Au】如何消去视频音频中的人声,提取伴奏
  14. Java ArrayList集合案例(上课笔记)
  15. 哈工大软件构造lab3总结
  16. 植入式广告热的冷思考
  17. 谈优秀游戏程序员工作的三大基本要求
  18. Expected a string but was BEGIN_OBJECT at line 1 column 2 path $
  19. 图形类的实现(java)
  20. DataBinder.Eval用法

热门文章

  1. 多线程并发:每个开发人员都应了解的内容
  2. 林正刚本地化中摸索前进 称中国未来无可比拟
  3. 如何設定 VS2008 讓 HTML 在格式化排版時不要破壞版面
  4. .net 学习 报错 Invalid temp directory in chart handler configuration [c:\TempImageFiles\]
  5. 【数据结构】 线性表的顺序表
  6. linux命令之find和locate
  7. 手机访问PC网站自动跳转到手机网站代码
  8. 使用.net调用java的Web Services
  9. 用Greasemonkey脚本收藏网站会员信息到本地
  10. COM First Teck.