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

Android-V lmkd 中的那些属性值

源码基于:Android V

相关博文:

Android lmkd 机制详解(一)

Android lmkd 机制详解(二)

Android lmkd 机制从R到T

1. 汇总

属性名说明默认值

ro.lmk.debug

启动 lmkd 的debug 模式,会打印一些调试信息

false

ro.lmk.use_psi

启动 PSI monitor,否则使用memcg 的方式,详细可以查看 init_monitors() 函数

true

ro.lmk.use_new_strategy

启动mp_event_psi 处理策略,否则使用 mp_event_common 常规策略

默认值依赖:low_ram_device || !use_minfree_levels

ro.lmk.use_minfree_levels

使用水位等级,详细查看 ProcessList.java

否则,使用指定的等级,使用 ro.lmk.low、medium、critical 指定的水位adj

false

ro.config.low_ram

低 ram 设备,用以确定是否使用 psi 策略,详细见 ro.lmk.use_new_strategy

false

ro.config.per_app_memcg

日志记录是否精确到每个进程的memcg

默认值为 ro.config.low_ram

ro.lmk.low

mp_event_common() 函数中使用,依赖于memcg 统计且值在cgroup v1 中生效。

三个prop 用以标记在三个等级下的被查杀的最小 adj。

1001

ro.lmk.medium

800

ro.lmk.critical

0

ro.lmk.critical_upgrade

允许提升pressure level 等级,mp_event_common() 函数中使用

false

ro.lmk.upgrade_pressure

提升压力等级的阈值,依赖 ro.lmk.critical_upgrade 使能

如果mem_pressure < upgrade_pressure,则调用 upgrade_level() 提示压力等级

100

ro.lmk.downgrade_pressure

降低压力等级的阈值,当mem_pressure 低于该值,会考虑降低压力等级

100

ro.lmk.kill_heaviest_task

kill 符合条件的最繁重的task(最好决定) VS kill 符合条件的任何task(最快决定)

false

ro.lmk.kill_timeout_ms

查杀进程后等待进程释放资源的 timeout,如果超过时间没有释放资源,系统将强制结束该进程。

100

ro.lmk.pressure_after_kill_min_score

当 cycle_after_kill && wmark < WMARK_LOW 时,指定min_score_adj

查杀回收无法满足进程对内存的消耗时,会进入连续查杀,此时指定最小 adj

0

ro.lmk.delay_monitors_until_boot

推迟 init_monitors,直到 boot completed

false

属性名说明 默认值
高性能低性能

ro.lmk.psi_partial_stall_ms

PSI stall ms,medium 等级

70

200

ro.lmk.psi_complete_stall_ms

PSI stall ms,critical 等级

700

ro.lmk.stall_limit_critical

严重失速限定值,当 FULL_10 大于该值,标记严重失速,min_score_adj 将指定到0

100

ro.lmk.swap_free_low_percentage

swap 分区可用内存占swap total 的百分比,用以判断swap 分区是否处于 low

10

ro.lmk.swap_util_max

swap 内存的利用率,用以确定是否有可回收的内存,如果达到该阈值,则表示因无法swap引起的内存压力

100

ro.lmk.swap_compression_ratio

用以 ZRAM 的压缩比,通常根据 easy_available 计算出 swap free 内存空间

1

ro.lmk.thrashing_limit

某段时间内 workingset refault (Kernel5.9之后特指 file)在 file lru 中的百分比阈值

100

30

ro.lmk.thrashing_limit_decay

为了尽快停止抖动,thrashing_limit 会进行衰减,该值为每次衰减的比例

10

50

ro.lmk.thrashing_limit_critical

严重抖动的阈值,默认值为 ro.lmk.thrashing_limit * 3,

ro.lmk.filecache_min_kb

上一轮查杀是因为抖动,这一轮查杀若无其他原因,则会确认系统 file lru 是否过低

0

ro.lmk.direct_reclaim_threshold_ms

直接内存回收的耗时阈值,如果超过该阈值,则表示设备因为直接内存回收卡住了,0 表示不使能该检查

0

ro.lmk.lowmem_min_oom_score

LOW_MEM 原因查杀时,指定的 min_score_adj 最终与 PERCEPTIBLE_APP_ADJ + 1 比较,取最大值

PREVIOUS_APP_ADJ + 1

2. ro.lmk.swap_free_low_percentage

这用以标记 swap free 的水位线,当swap free 小于该线时,则表示处于 low 状态:

    if (swap_free_low_percentage) {swap_low_threshold = mi.field.total_swap * swap_free_low_percentage / 100;swap_is_low = get_free_swap(&mi) < swap_low_threshold;} else {swap_low_threshold = 0;}

2.1 变量 swap_is_low

从上面代码可知,swap_is_low 是 get_free_swap() 小于 swap_low_threshold。

static inline int64_t get_free_swap(union meminfo *mi) {if (swap_compression_ratio)return std::min(mi->field.free_swap, mi->field.easy_available * swap_compression_ratio);return mi->field.free_swap;
}

get_free_swap() 的返回值为 meminfo 中的 free_swap 以及 easy_available * swap_compression_ratio 之间的最小值。

这里设计到三个数值:

  • free_swap
  • easy_available
  • swap_compression_ratio

第一个 free_swap 不必多说,先来看下 swap_compression_ration。这里 zram 的压缩率,在V 之前直接是 3,即默认认为压缩比是 1:3,而在 V 中使用了prop 动态控制,默认值为 1。

再来看下 easy_available

mi->field.easy_available = mi->field.nr_free_pages + mi->field.inactive_file;

 swap 虽然还有很多,但实际可用的需要根据实际剩余的物理内存来判定,即系统留给 zram 压缩的可用物理空间。

从官方解释来看:

lmkd: measure free swap as available and easily reclaimable memory In the case of ZRAM,
SwapFree does not represent the actual free swap amount because swap space is taken from
the free memory or reclaimed. Therefore use free memory and easily reclaimable memory as an 
approximation of how much free swap system can use. Use SwapFree as a measure of how much
swap space the system will consider using. Min of those two measurements is used to decide
how much usable swap the system still has.

因此,swap_is_low 不仅仅要看 free_swap,还需要考虑实际剩余物理内存以及压缩比。

3. ro.lmk.swap_util_max

是查杀策略中的一种,用以判断 swap 的利用率:

    } else if (wmark < WMARK_HIGH && swap_util_max < 100 &&(swap_util = calc_swap_utilization(&mi)) > swap_util_max) {/** Too much anon memory is swapped out but swap is not low.* Non-swappable allocations created memory pressure.*/kill_reason = LOW_MEM_AND_SWAP_UTIL;
static int calc_swap_utilization(union meminfo *mi) {int64_t swap_used = mi->field.total_swap - get_free_swap(mi);int64_t total_swappable = mi->field.active_anon + mi->field.inactive_anon +mi->field.shmem + swap_used;return total_swappable > 0 ? (swap_used * 100) / total_swappable : 0;
}

系统匿名页越大,表示可以swap 的内存越大,最后比值就会越小。

即,该阈值用以确认系统中可回收的内存,默认值为100时,实际上会停止该检查。

4. ro.lmk.thrashing_limit

在某段时间内,系统会出现 workingset refault,从Kernel 5.9 开始特指文件页的workingset refault:

thrashing = (workingset_refault_file - init_ws_refault) * 100 / (base_file_lru + 1);

抖动就是在某段时间内 workingset_refault_file 在file lru 中的百分比。

每次 mp_event_psi() 的触发都会检查抖动值,且在进入查杀后会对 thrashing_limit 进行衰减,更加严格控制抖动值,以此加快停止抖动。

5. ro.lmk.thrashing_limit_decay

thrashing_limit 的衰减比例,通常衰减10%,在 low ram 设备中衰减50%。

将 thrashing_limit 值进行衰减,用以在 1s 连续查杀释放内存,以此尽快停止抖动:

        int pages_freed = find_and_kill_process(min_score_adj, &ki, &mi, &wi, &curr_tm, &psi_data);if (pages_freed > 0) {killing = true;max_thrashing = 0;if (cut_thrashing_limit) {/** Cut thrasing limit by thrashing_limit_decay_pct percentage of the current* thrashing limit until the system stops thrashing.*/thrashing_limit = (thrashing_limit * (100 - thrashing_limit_decay_pct)) / 100;}}

注意 thrashing_limit 会在 THRASHING_RESET_INTERVAL_MS(1000) 时间后恢复到 thrashing_limit_pct,也就是恢复到 ro.lmk.thrashing_limit 设定的阈值:

    since_thrashing_reset_ms = get_time_diff_ms(&thrashing_reset_tm, &curr_tm);if (since_thrashing_reset_ms > THRASHING_RESET_INTERVAL_MS) {...thrashing_limit = thrashing_limit_pct;}

http://www.lryc.cn/news/523519.html

相关文章:

  • PageHelper快速使用
  • 图像处理基础(3):均值滤波器及其变种
  • 力扣刷题心得_JAVA
  • 音乐播放器实现:前端HTML,CSS,JavaScript综合大项目
  • Unity编辑器缩放设置
  • ChatGPT大模型极简应用开发-CH1-初识 GPT-4 和 ChatGPT
  • Golang学习笔记_27——单例模式
  • хорошо哈拉少wordpress俄语主题
  • [数据结构与算法]js实现二叉树
  • MySQL程序之:连接到服务器的命令选项
  • python3GUI--仿崩坏三二次元登录页面(附下载地址) By:PyQt5
  • 阿里云 Serverless 助力盟主直播:高并发下的稳定性和成本优化
  • Unity 学习指南与资料分享
  • Android SystemUI——CarSystemBar视图解析(十一)
  • .NET周刊【1月第1期 2025-01-05】
  • 初识go语言之指针用法
  • 用户中心项目教程(二)---umi3的使用出现的错误
  • Android设备:Linux远程gdb调试
  • (十四)WebGL纹理坐标初识
  • 【机器学习】制造业转型:机器学习如何推动工业 4.0 的深度发展
  • Nginx安装配置Mac使用Nginx访问前端打包项目
  • 国自然面上项目|基于组合机器学习算法的病理性近视眼底多模态影像资料自动化定量分析研究|基金申请·25-01-18
  • 03_UI自适应
  • Python在DevOps中的应用:自动化CI/CD管道的实现
  • API接口技术推动电商数据处理的自动化
  • Nginx反向代理架构介绍
  • .Net Core微服务入门系列(一)——项目搭建
  • WPF 实现可视化操作数据库的程序全解析
  • python mysql库的三个库mysqlclient mysql-connector-python pymysql如何选择,他们之间的区别
  • 如何将数据库字符集改为中文,让今后所有的数据库都支持中文