当前位置: 首页 > java >正文

Android Native 之 lmkd进程分析

lwkd进程属于native层启动的一个守护进程,他的作用贯穿android世界的始终。他的另外一个大家都属于的名字lowmemorykiller。

根据readme的介绍lmkd是用来对android系统内存检查的守护进程,它通过终止不重要的进程来达到系统稳定运行的状态。在Linux Kernel 4.12之前是这项任务是放在了kernel进行管理,在Linux Kernel 4.12之后移到了native层中,因为在kernel进程管理中直接干掉某个应用进程太过暴力。

后面介绍了我们可以通过一些属性的值来控制lmkd进程的效果,如下:

  • ro.config.low_ram: choose between low-memory vs high-performance device. Default = false.

  • ro.lmk.use_minfree_levels: use free memory and file cache thresholds for making decisions when to kill. This mode works the same way kernel lowmemorykiller driver used to work. Default = false

  • ro.lmk.low: min oom_adj score for processes eligible to be killed at low vmpressure level. Default = 1001 (disabled)

  • ro.lmk.medium: min oom_adj score for processes eligible to be killed at medium vmpressure level. Default = 800 (non-essential processes)

  • ro.lmk.critical: min oom_adj score for processes eligible to be killed at critical vmpressure level. Default = 0 (all processes)

  • ro.lmk.critical_upgrade: enables upgrade to critical level. Default = false

  • ro.lmk.upgrade_pressure: max mem_pressure at which level will be upgraded because system is swapping too much. Default = 100 (disabled)

  • ro.lmk.downgrade_pressure: min mem_pressure at which vmpressure event will be ignored because enough free memory is still available. Default = 100 (disabled)

  • ro.lmk.kill_heaviest_task: kill heaviest eligible task (best decision) vs. any eligible task (fast decision). Default = false

  • ro.lmk.kill_timeout_ms: duration in ms after a kill when no additional kill will be done. Default = 0 (disabled)

  • ro.lmk.debug: enable lmkd debug logs, Default = false

  • ro.lmk.swap_free_low_percentage: level of free swap as a percentage of the total swap space used as a threshold to consider the system as swap space starved. Default for low-RAM devices = 10, for high-end devices = 20

  • ro.lmk.thrashing_limit: number of workingset refaults as a percentage of the file-backed pagecache size used as a threshold to consider system thrashing its pagecache. Default for low-RAM devices = 30, for high-end devices = 100

  • ro.lmk.thrashing_limit_decay: thrashing threshold decay expressed as a percentage of the original threshold used to lower the threshold when system does not recover even after a kill. Default for low-RAM devices = 50, for high-end devices = 10

  • ro.lmk.psi_partial_stall_ms: partial PSI stall threshold in milliseconds for triggering low memory notification. Default for low-RAM devices = 200, for high-end devices = 70

  • ro.lmk.psi_complete_stall_ms: complete PSI stall threshold in milliseconds for triggering critical memory notification. Default = 700

lmkd will set the following Android properties according to current system configurations:

  • sys.lmk.minfree_levels: minfree:oom_adj_score pairs, delimited by comma

  • sys.lmk.reportkills: whether or not it supports reporting process kills to clients. Test app should check this property before testing low memory kill notification. Default will be unset.

一、LMKD源码分析

1、LMKD进程的启动

1.1 三种启动方式

同其他native进程一致,他的启动还是通过init rc机制来启动。如下代码

总结如下:

  • 标记为core类的服务会在init.rcon early-initon init阶段被启动,未显式设置disabled属性时,core类服务会随init进程初始化自动启动。PS:在core进行启动是为了防止核心服务没有启动导致系统异常
  • 监听sys.boot_completed开机属性然后传递--reinit参数进行完整启动。PS:从后文可以了解到reinit会去读取一系列相关属性,即这是完整启动
  • 最后监听属性变更,传递--reinit参数,应该是做成不需要重启系统就能够动态生效这些参数的效果

1.2 主函数三部曲

2、

http://www.xdnf.cn/news/12974.html

相关文章:

  • 嵌入式学习之系统编程(九)OSI模型、TCP/IP模型、UDP协议网络相关编程(6.3)
  • NLP-数据集
  • wifi改ip地址有什么用?wifi改ip地址怎么改
  • LeetCode - 3. 无重复字符的最长子串
  • 无源一阶低通电路噪声如何计算
  • 音乐“穿梭机”AudioRelay,让你的音频“无缝对接”
  • push [特殊字符] present
  • 深入解析 Qwen3 基础模型:架构设计与技术创新
  • 第2课 SiC MOSFET与 Si IGBT 静态特性对比
  • 从0开始学习R语言--Day20--Wilcoxon秩和检验
  • 组件库实战-基建思路
  • Docker拉取MySQL后数据库连接失败的解决方案
  • P3 QT项目----记事本(3.8)
  • Qt的学习(二)
  • 用神经网络读懂你的“心情”:揭秘情绪识别系统背后的AI魔法
  • HDMI 显示器热插拔对应显示应用启停测试
  • 高分辨率图像合成归一化流扩展
  • 02.运算符
  • 使用Spring Cloud Stream 模拟生产者消费者group destination的介绍(整合rabbitMQ)
  • c++默认类模板参数
  • K8S中的PV、PVC和StorageClass
  • 【C++】std::bind和std::placeholders
  • c# 局部函数 定义、功能与示例
  • 「Java基本语法」变量的使用
  • redis--黑马点评--Redisson快速入门
  • 自动化过程中,如何定位一闪而过的toast?
  • 【11408学习记录】考研数学攻坚:行列式本质、性质与计算全突破
  • Xen Server服务器释放磁盘空间
  • 什么是CRM客户管理系统?怎样的企业需要用CRM客户管理系统?
  • SQL 注入:JDO与Hibernate