最近遇到一个Lost RAM占用内存达到1.5GB的问题,所以先统计一下Lost RAM的计算方法:
根据计算公式:
long lostRAM = memInfo.getTotalSizeKb() - (totalPss - totalSwapPss)
- memInfo.getFreeSizeKb() - memInfo.getCachedSizeKb()
- memInfo.getKernelUsedSizeKb() - memInfo.getZramTotalSizeKb();
解读:
Lost RAM=total memory(减掉kernel reserve部分)-(process total pss - swap占用空间总和(除去native process所占用swap空间))-dumpsys meminfo(free+cached kernel+kernel+ZRAM used见下文)
即:Lost ram=883248-(193417+476988-74453)-(64008+81368+100892+59368)=-18340
Total RAM: 883,248K (status normal)
Free RAM: 338,793K ( 193,417K cached pss + 81,368K cached kernel + 64,008K free)
Used RAM: 577,880K ( 476,988K used pss + 100,892K kernel)
Lost RAM: -18,340K
ZRAM: 59,368K physical used for 179,388K in swap ( 661,184K total swap)
Tuning: 128 (large 256), oom 184,320K, restore limit 61,440K (low-ram)