Low memory 处理建议

文摘 MediaTek 2020-03-24 阅读:10896

1.优化系统进程内存占用

参考

Quick Start > Advanced System Debug & Tuning Method > Memory > memory usage分析

排查内存占比高进程并优化

2.减少reserved memory

2-1获取reserved memory 讯息: 

  • <=Android P , 参考FAQ21499 reserve_memory 用量
  • >=Android Q, 请提e-service 申请 "memory-layout-parser"  工具

也可从lk log  搜mblock_reserve-R   (但可能有缺漏)

Line 1920: [1604] mblock_reserve-R[3].start: 0x46000000, sz: 0x400000 map:0 name:lk_addr_mb
Line 1921: [1605] mblock_reserve-R[4].start: 0x46900000, sz: 0x8000000 map:0 name:scratch_addr_mb
Line 1922: [1606] mblock_reserve-R[5].start: 0x44000000, sz: 0x80000 map:1 name:dtb_kernel_addr_mb
Line 1923: [1607] mblock_reserve-R[6].start: 0x40008000, sz: 0x3200000 map:0 name:kernel_addr_mb
Line 1924: [1608] mblock_reserve-R[7].start: 0x45000000, sz: 0x1000000 map:0 name:ramdisk_addr_mb
Line 1925: [1609] mblock_reserve-R[8].start: 0x77370000, sz: 0xc90000 map:0 name:framebuffer
Line 1926: [1610] mblock_reserve-R[9].start: 0x7fa00000, sz: 0x400000 map:0 name:logo_db_addr_pa
Line 1927: [1611] mblock_reserve-R[10].start: 0x77360000, sz: 0x10000 map:0 name:SPM-reserved
Line 1928: [1612] mblock_reserve-R[11].start: 0x77350000, sz: 0x10000 map:0 name:MCUPM-reserved
Line 1929: [1613] mblock_reserve-R[12].start: 0x72000000, sz: 0x4000000 map:0 name:ccci

或是lk 代码搜 

mblock_reserve 或 mblock_reserve_ext

ex:

logo_db_addr_pa = (void *)(u32)mblock_reserve_ext(&g_boot_arg->mblock_info,
LK_LOGO_MAX_SIZE, PAGE_SIZE, 0x80000000, 0, "logo_db_addr_pa");

或.dts 搜 reserved-memory

ex:


        reserve-memory-scp_share {
            compatible = "mediatek,reserve-memory-scp_share";
            no-map;
            size = <0 0x01400000>; /*20 MB share mem size */
            alignment = <0 0x1000000>;
            alloc-ranges = <0 0x40000000 0 0x50000000>; /*0x4000_0000~0x8FFF_FFFF*/
        };
        consys-reserve-memory {
            compatible = "mediatek,consys-reserve-memory";
            no-map;
            size = <0 0x200000>;
            alignment = <0 0x200000>;
            alloc-ranges = <0 0x40000000 0 0x80000000>;

3.限制后台

3-1修改/frameworks/base/services/core/java/com/android/server/am/ActivityManagerConstants.java or  ProcessList.java

  public int MAX_CACHED_PROCESSES = DEFAULT_MAX_CACHED_PROCESSES;

  private static final int DEFAULT_MAX_CACHED_PROCESSES = 32;// 改为DEFAULT_MAX_CACHED_PROCESSES = 8 or 16 or ...

3-2修改/frameworks/base/services/core/java/com/android/server/am/ProcessList.java中

  long getCachedRestoreThresholdKb() {

    return mCachedRestoreLevel; //将mCachedRestoreLevel 改为 mCachedRestoreLevel/2

  }

4.调整lmk参数

4-1. <=kernel-4.9 non-ago project  or kernel-4.14 (ro.lmk.use_minfree_levels=1)

minfree table后三项阀值 ,分别增大1.x倍 1.x倍,1.x倍  (ex: 1.2 , 1.5 ,...倍)

minfree table 参考

Quick Start > Advanced System Debug & Tuning Method > Memory > lmkd & lmk

4-2. Ago project , or kernel-4.14 (ro.lmk.use_minfree_levels=0)

调整lmkd 参数

ro.lmk.medium 调小(mediaum pressure kill adj 减小, 更多进程可杀)

ro.lmk.downgrade_pressure 调大(更容易进到mediaum pressure状态)

ro.lmk.upgrade_pressure 调大(更容易进到critical pressure状态)

5.swap szie & swappiness

5-1.调大swap size, 使系统逻辑内存延伸加大

/device/mediatek/mt6xxx/
/device/mediatek/vendor/common/
fstab.enableswap
fstab.enableswap_gmo
fstab.enableswap_ago

/dev/block/zram0 none swap defaults zramsize=xx%     把值或百分比调大

可从/proc/zraminfo确认是否生效

5-2.调大swappiness, 使系统充分利用swap 分区

/proc/sys/vm/swappiness 

/dev/memcg/memory.swappiness

/dev/memcg/apps/memory.swappiness

/dev/memcg/system/memory.swappiness

6.Duraspeed enable (or  做好后台管理)

duraspeed 可主动管理后台进程与内存, 避免进入内存恶劣情况  

see also

FAQ22375 DuraSpeed3.0 Quick Start
FAQ21505 duraspeed 配置及判断是否正常使用
FAQ19932 快霸(DuraSpeed)功能介绍
FAQ21557 如何添加Duraspeed whitelist

0条评论

© 2024 芯缘异码. Powered by Typecho