关闭

linux 内存分析

1312人阅读 评论(0) 收藏 举报
分类:

内存分析:
条件:开移动侦测,车道校准,停车监控,智能算法,后拉uvc
执行cat /proc/meminfo:
MemTotal:          66204 kB
MemFree:           25356 kB   //当前剩余内存为24M
Buffers:            1788 kB   //该部分对于系统来说是占用的
Cached:             7380 kB   //该部分对于系统来说是占用的
Active:            22384 kB
Inactive:           1260 kB
Active(anon):      16072 kB
Inactive(anon):       48 kB
Active(file):       6312 kB
Inactive(file):     1212 kB
Unevictable:        1588 kB
LowTotal:          66204 kB
LowFree:           25356 kB
AnonPages:         16064 kB
Mapped:             7420 kB
Shmem:                56 kB
Slab:               4416 kB
SReclaimable:       1416 kB
SUnreclaim:         3000 kB
KernelStack:         808 kB
PageTables:          360 kB
CommitLimit:       33100 kB
Committed_AS:      25560 kB
VmallocTotal:     892928 kB
VmallocUsed:       45068 kB
VmallocChunk:     610664 kB

执行root@android:/ # ./busybox free 得到结果如下:
root@android:/ # ./busybox free -m                                            
             total         used         free       shared      buffers
Mem:            64           39           24            0            1
-/+ buffers:                 38           26
Swap:            0            0         0

从以上结果可知当前系统已使用内存为:约为39M  剩余内存为 24M

3,接下来执行统计所有进程消耗的内存:
  PID      Vss      Rss      Pss      Uss  cmdline
   59   82712K   31828K   31617K   31508K  /system/bin/mediaserver   //内存消耗大户,潜在优化对象
   58    3700K    3100K    2889K    2780K  /system/bin/newcdr
  347     408K     408K     303K     284K  procrank
   56     416K     416K     290K     264K  /system/bin/vold
   65     348K     348K     256K     240K  /system/bin/sh
   52     332K     332K     251K     208K  /init
   61     196K     196K     192K     192K  /sbin/adbd
   60     236K     236K     133K     112K  /system/bin/debuggerd
   51     188K     188K     115K      80K  /sbin/ueventd
   55     196K     196K     110K      96K  /system/bin/servicemanager
    1     180K     180K      99K      56K  /init
                          ------   ------  ------
                          36259K   35820K  TOTAL
       总共消耗:34.98M
      
那么问题来了:系统总的内存USED为39M ,进程消耗内存为:34.98M 中间有4M的差值?

我们在看cat/meminfo/这项里的Slab、PageTables这两项,首先slab是内核为了高性能每个需要重复使用的对象都会有个池,这个slab池会cache大量常用的对象,所以会消耗大量的内存
slab:4416 kB
命令查看:
echo `cat /proc/slabinfo |awk 'BEGIN{sum=0;}{sum=sum+$3*$4;}END{print sum/1024/1024}'` MB
PageTables:是系统boot的时候就会根据内存大小算出来分配出去的,18内核是1.56%左右,32内核由于cgroup的原因会在2.3%
命令查看:
echo `grep PageTables /proc/meminfo | awk '{print $2}'` KB

总结:内存的去向主要有3个:1. 进程消耗。 2. slab消耗 3.pagetable消耗


SDV 内存分析(物理内存128M) 测试条件 xxxdroid 内存项    
启动应用未录像                1   linux系统内核保留 约6.8M  
2 ION 内存 80M  
3 mediaserver 多媒体 3.97M(4060K)  
5 logger 0.375M (384K)  
6 TCP/SOCKET 74K  
7 Buffers 12K  
8 sdv 应用 6.05 M (6188K)  
9 Cached 4.63M(4744k)  
10 init 184K  
11 ueventd 188K  
12 servicemanager 320K  
13 vold 824K  
14 debuggerd 388K  
15 adbd 176K  
16 standbyservice 1604K  
17 sh 820K   
18 Slab 5412K  
19 PageTables: 336K  
20 MemFree 约18.7M (19068K)  


测试条件: SDV 物理内存大小: 128M byte,通过
调试方法:在commandline中 memblock=debug
     
memory layout 内存范围 大小 byte  
kernel _stext代码段、data段   [0x000000400081c0-0x000000405efe57] 5.905M(0x5e7c98)  
kernel initrd 段   [0x00000041000000-0x00000041037fe0] 224K  
页表内存   [0x00000040004000-0x00000040007fff] 16K  
android RAM_CONSOLE   [ 41f20800-41f307ff] 64K  
sys_config.fex  [0x00000041f00000-0x00000041f20000] 128K  
STANDBY_MEM_SIZE  [0x00000041f20000-0x00000041f20800] 2K  
alloc_base_nid   20.1K(0x5060)  
中断向量   4K  
bootmem bitmap   56KB  
pmd表内存   8736byte  
fixmap   896 kB  
ION   80M  
       


cat proc/meminfo 

top 

cat proc/slabinfo



 echo f > /proc/sysrq-trigger 


130|root@camdroid:/ #
130|root@camdroid:/ #  echo f > /proc/sysrq-trigger 
[   37.890423] SysRq : Manual OOM execution
[   37.895297] kworker/0:0 invoked oom-killer: gfp_mask=0xd0, order=0, oom_adj=0, oom_score_adj=0
[   37.905132] Backtrace:
[   37.908097] [<c0013410>] (dump_backtrace+0x0/0x110) from [<c03158f8>] (dump_stack+0x18/0x1c)
[   37.917666]  r6:00000000 r5:000000d0 r4:c0e82080 r3:c0460740
[   37.924466] [<c03158e0>] (dump_stack+0x0/0x1c) from [<c0070e64>] (dump_header.isra.15+0x54/0x124)
[   37.934503] [VFE_WARN] Nobody is waiting on this video buffer,buf = 0xc0cd8640
[   37.942730] [<c0070e10>] (dump_header.isra.15+0x0/0x124) from [<c007103c>] (oom_kill_process.part.18.constprop.19+0x44/0x1e4)
[   37.955475]  r6:00000000 r5:000000d0 r4:c0e82080
[   37.961009] [<c0070ff8>] (oom_kill_process.part.18.constprop.19+0x0/0x1e4) from [<c00715d0>] (out_of_memory+0x2c4/0x33c)
[   37.973267] [VFE_WARN] Nobody is waiting on this video buffer,buf = 0xc0cd86c0
[   37.981499] [<c007130c>] (out_of_memory+0x0/0x33c) from [<c01831d0>] (moom_callback+0x2c/0x38)
[   37.991261] [<c01831a4>] (moom_callback+0x0/0x38) from [<c004245c>] (process_one_work+0x1e0/0x338)
[   38.001308] [VFE_WARN]Only two buffer left for csi
[   38.006823] [<c004227c>] (process_one_work+0x0/0x338) from [<c004323c>] (worker_thread+0x1c0/0x2c8)
[   38.017071] [<c004307c>] (worker_thread+0x0/0x2c8) from [<c0046aec>] (kthread+0x94/0xa0)
[   38.026164] [<c0046a58>] (kthread+0x0/0xa0) from [<c0031df0>] (do_exit+0x0/0x660)
[   38.034655] [VFE]capture video mode!
[   38.043738]  r6:c0031df0 r5:c0046a58 r4:c1821ed0
[   38.049255] Mem-info:
[   38.051880] Normal per-cpu:
[   38.055071] CPU    0: hi:   18, btch:   3 usd:  17
[   38.060591] active_anon:1073 inactive_anon:8 isolated_anon:0
[   38.060597]  active_file:244 inactive_file:1349 isolated_file:0
[   38.060602]  unevictable:0 dirty:0 writeback:0 unstable:0
[   38.060607]  free:3051 slab_reclaimable:292 slab_unreclaimable:837
[   38.060613]  mapped:1115 shmem:11 pagetables:69 bounce:0
[   38.060618]  free_cma:0
[   38.095613] [VFE]capture video first frame done!
[   38.100914] [VFE_WARN]Only two buffer left for csi
[   38.106358] Normal free:12204kB min:1016kB low:1268kB high:1524kB active_anon:4292kB inactive_anon:32kB active_file:976kB inactive_file:5396kB unevictable:0kB isolated(anon):0kB isolated(file):0kB present:65024kB mlocked:0kB dirty:0kB writeback:0kB mapped:4460kB shmem:44kB slab_reclaimable:1168kB slab_unreclaimable:3348kB kernel_stack:816kB pagetables:276kB unstable:0kB bounce:0kB free_cma:0kB writeback_tmp:0kB pages_scanned:0 all_unreclaimable? no
[   38.150896] [VFE]capture video mode!
[   38.154961] lowmem_reserve[]: 0 0
[   38.159029] Normal: 19*4kB (U) 104*8kB (UEM)
[   38.164266] [VFE]capture video first frame done!
[   38.169770] [VFE_WARN]Only two buffer left for csi
[   38.175193] 124*16kB (UEM) 63*32kB (UEM) 34*64kB (UEM) 8*128kB (M) 0*256kB 0*512kB 0*1024kB 0*2048kB 1*4096kB (R) = 12204kB
[   38.189138] 1604 total pagecache pages
[   38.194127] 16384 pages of RAM
[   38.197625] [VFE]capture video mode!
[   38.201720] 3206 free pages
[   38.205003] 8675 reserved pages
[   38.208577] 1129 slab pages
[   38.211782] 2319 pages shared
[   38.215166] 0 pages swap cached
[   38.218831] [ pid ]   uid  tgid total_vm      rss cpu oom_adj oom_score_adj name
[   38.227173] [   54]     0    54       87       47   0       0             0 ueventd
[   38.235858] [VFE]capture video first frame done!
[   38.241073] [VFE_WARN]Only two buffer left for csi
[   38.246591] [   55]     0    55       98       60   0       0             0 init
[   38.254907] [   58]  1000    58      222       80   0       0             0 servicemanager
[   38.264279] [   59]     0    59      946      184   0       0             0 vold
[   38.272685] [VFE]capture video mode!
[   38.276760] [   60]     0    60     9902     1004   0       0             0 mediaserver
[   38.285840] [   62]     0    62     6111     1122   0       0             0 ccdr                            单位: 以页(4K)为单位, 1122 个页,即 (1122/256) M =  4.3828125 M
[   38.294246] [   63]     0    63      862       45   0       0             0 adbd
[   38.302554] [VFE]capture video first frame done!
[   38.307853] [VFE_WARN]Only two buffer left for csi
[   38.313281] [   64]     0    64      233       97   0       0             0 debuggerd
[   38.322169] [   65]     0    65     1075      401   0       0             0 standbyservice
[   38.331441] [VFE]capture video mode!
[   38.335605] [   69]     0    69      204      116   0       0             0 sh
[   38.348734] Out of memory: Kill process 62 (ccdr) score 117 or sacrifice child
[   38.356954] Killed process 62 (ccdr) total-vm:24444kB, anon-rss:1760kB, file-rss:2728kB
[   38.366026] [VFE]capture video first frame done!
[   38.371239] [VFE_WARN]Only two buffer left for csi
[   38.382458] init: waitpid returned pid 62, status = 00000009
[   38.388866] init: process 'ccdr', pid 62 exited
[   38.397783] [VFE]capture video mode!
root@camdroid:/ # [   38.407329] [VFE]vfe_close
[   38.410536] [h22_mipi Raw]CSI_SUBDEV_PWR_OFF!
[   38.415468] [VFE]mclk off
[   38.456069] [VFE]..........................vfe clk close!.......................
[   38.464462] [VFE]vfe_close end
[   44.693656] ****************Set_Rset_Cap=2***********
[   75.998831] charger->usb_valid = 0
[   76.002730] set usb vol-lim to 4000 mV, cur-lim to 0 mA


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:143934次
    • 积分:3381
    • 等级:
    • 排名:第10342名
    • 原创:182篇
    • 转载:157篇
    • 译文:0篇
    • 评论:10条
    最新评论