首页 > 代码库 > Android 低内存导致monkey killed分析指南

Android 低内存导致monkey killed分析指南

现象描述:
monkey --pkg-blacklist-file storage/sdcard0/blacklist.txt  --ignore-security-exc       
eptions --monitor-native-crashes -s 800 -v -v -v  --throttle 1427 180000 >sdcard       
/Monkey.log                                                                            
shes -s 800 -v -v -v  --throttle 1427 180000 >sdcard/Monkey.log               <        
Killed                                                                                 


首先在kernel log中搜索关键字monkey,并根据monkey退出的log行向上查看如下:
<4>[ 2646.721739] (0)[474:AudioOut_2]AWD 8192AWD 8192======low memory killer=====
<4>[ 2646.781825] (1)[17854:sh]Free memory other_free: -1147, other_file:3990 pages
<4>[ 2646.781878] (1)[17854:sh]Candidate 1 (init), adj -941, rss 69, rswap 109, to kill
<4>[ 2646.781933] (1)[17854:sh]Candidate 87 (ueventd), adj -941, rss 56, rswap 64, to kill
。。。。。。
<4>[ 2646.784770] (1)[17854:sh]Candidate 17859 (roviders.global), adj -941, rss 1452, rswap 2652, to kill
<4>[ 2646.784825] (1)[17854:sh]Killing ‘commands.monkey‘ (7641), adj 0,
<4>[ 2646.784839] (1)[17854:sh]   to free 8504kB on behalf of ‘sh‘ (17854) because
<4>[ 2646.784852] (1)[17854:sh]   cache 15960kB is below limit 23552kB for oom_score_adj 0
<4>[ 2646.784867] (1)[17854:sh]   Free memory is -4588kB above reserved [gfp(0xd0)]
<4>[ 2646.784903] (1)[17854:sh]low memory info:
<4>[ 2646.784983] (1)[17854:sh]Normal free:3964kB min:2784kB low:7980kB high:8676kB active_anon:18352kB inactive_anon:18364kB active_file:6936kB inactive_file:6888kB unevictable:27196kB isolated(anon):0kB isolated(file):68kB present:485448kB mlocked:25284kB dirty:0kB writeback:40kB mapped:20816kB shmem:11948kB slab_reclaimable:18212kB slab_unreclaimable:52360kB kernel_stack:4120kB pagetables:5292kB unstable:0kB bounce:0kB writeback_tmp:0kB pages_scanned:252 all_unreclaimable? no
<4>[ 2646.785058] (1)[17854:sh]Normal: 991*4kB 0*8kB 0*16kB 0*32kB 0*64kB 0*128kB 0*256kB 0*512kB 0*1024kB 0*2048kB 0*4096kB = 3964kB
<4>[ 2646.785334] (1)[17854:sh]LowMemoryOn
<7>[ 2646.785381]-(1)[17854:sh][17854:sh] sig 9 to [7641:commands.monkey]
<7>[ 2646.786094] (0)[7641:commands.monkey][7641:commands.monkey] exit
分析结果:从上面log已经可以很清楚的看到当前monkey被killed原因是由于低内存导致。monkey退出
前low memory killer已经开始频繁杀内存了。且此时可以在log中搜索commands.monkey的adj值为0(值越小表示优先级最高,adj的值可以为负数,如
init进程的oom_adj为-16

Android 低内存导致monkey killed分析指南