Android P LMKD分析二
关于mp_event_common接受的内存压力事件,是从内核而来,简单说下。
先来看下官方的介绍:
Historically, Android used in-kernel lowmemorykiller driver to handle memory pressure situations by killing non-essential processes. This mechanism is rigid and depends on hard-coded values. In addition, starting with kernel 4.12, the lowmemorykiller driver is excluded from the upstream kernel.
The userspace lmkd process implements the same functionality but with already existing kernel mechanisms to detect and estimate memory pressure. It uses vmpressure events generated by the kernel to get notifications about memory pressure levels. It also can use memory cgroup features to limit memory resources allocated to each process based on its importance.
这里还说了老的内核minfree的缺点,就是太死板,我去,那7.0还用着呢, 9.0依然可以用,除非内核不支持了。
介绍也说了用已经存在的内核机制就是kernel vmpressure探测评估内存压力,然后lmkd去获取这个状态,也就是代码看到的event相关代码。
vmpressure以前也大概分析过,可以看这里:vmpressure分析。
vmpressure本身就定义了low, medium, critical三类内存压力状态,所以能看到在lmkd 初始化时init了这三种状态,至于怎么和kernel交互,已经偏用户态了,主要是epoll。
if (use_inkernel_interface) { |
init_mp_common
里注册 by EPOLL_CTL_ADD:
epev.events = EPOLLIN; |
另外就是策略的选择,看了下骁龙625 P kernel4. 9还是用的in kernel。
至于用户态属性怎么配置,机制大概都明白了,我想还是根据遇到的问题以及性能测试为主,rt?
版权声明:本站所有文章均采用 CC BY-NC-SA 4.0 CN 许可协议。转载请注明原文链接!