查slub内存泄漏的一种方法
-
测试环境:
board: SC335
sensor imx307
APP: 整合mixer
flash:nor
network: 连在公司网络 -
注意项目:
-
所有测试项目,需要手动改mi_demo.sh,在mi_venc.ko之后加上max_width=1920 max_height=1088.
-
mixer命令他后加上-x (表示启用priv pool)。
-
注意frame mode DIVP和real mode DIVP 互斥,即-V 3和-V 4或者5不能同时,-c和-V4或者5不能同时。
-
测试步骤:
-
执行命令:
/customer/mixer -n 1 -r 2 -v 1 -V 1 -L 3 -o -d 512 -
动态开关MD/OD:ie 1 352 288;ie 0 352 288 1s切一次可以使用附件test_md_od.py脚本, secureCRT=>Script=>Run load脚本;依次选择"7"(切MD/OD)->10000(loop次数)->2(2s一次)。
查问题的准备¶
-
SLUB_DEBUG [=y], SLUB_DEBUG_ON [=y]
在kernel中打开这两个SLUB config,重新编译与烧写uImage.xz。 -
Beyond Compare
用于对比内存泄漏前后的debug信息。 -
arm-linux-gnueabihf-gdb
结合backtrace的信息定位代码。
如何判断是内存泄漏问题¶
平台开始压测内存泄漏问题的时候执行以下脚本循环打印内存信息
#!/bin/bash
while true
do
echo "####################################################################"
echo "cat meminfo..."
cat /proc/meminfo
sleep 1s
echo "####################################################################"
echo "cat slabinfo..."
cat /proc/slabinfo
sleep 1s
echo "###################"
echo 3 > /proc/sys/vm/drop_caches
free
sleep 5s
done
复现到问题后,可以看到OOM。
venc0_P0_MAIN invoked oom-killer: gfp_mask=0x26040c0(GFP_KERNEL|__GFP_COMP|__GFP_NOTRACK), nodemask=0, order=2, oom_score_adj=0
CPU: 0 PID: 648 Comm: venc0_P0_MAIN Tainted: P O 4.9.84 #3
Hardware name: SStar Soc (Flattened Device Tree)
[<c0011521>] (unwind_backtrace) from [<c000fcc7>] (show_stack+0xb/0xc)
[<c000fcc7>] (show_stack) from [<c008148d>] (dump_header.constprop.3+0x45/0x11c)
[<c008148d>] (dump_header.constprop.3) from [<c005f6a1>] (oom_kill_process+0x6d/0x300)
[<c005f6a1>] (oom_kill_process) from [<c005fc37>] (out_of_memory+0x21f/0x264)
[<c005fc37>] (out_of_memory) from [<c00620a3>] (__alloc_pages_nodemask+0x5cb/0x630)
[<c00620a3>] (__alloc_pages_nodemask) from [<c007d1c5>] (new_slab+0x85/0x260)
[<c007d1c5>] (new_slab) from [<c007deaf>] (___slab_alloc.constprop.12+0x18b/0x21c)
[<c007deaf>] (___slab_alloc.constprop.12) from [<c007e015>] (kmem_cache_alloc+0x51/0xa4)
[<c007e015>] (kmem_cache_alloc) from [<bfb2542b>] (mi_sys_ringpool_AppendTailContentTailRecord+0x176/0x2cc [mi_sys])
[<bfb2542b>] (mi_sys_ringpool_AppendTailContentTailRecord [mi_sys]) from [<bfb03b37>] (mi_sys_RingPool_AppendTailContentTailRecord+0x6/0x8 [mi_sys])
[<bfb03b37>] (mi_sys_RingPool_AppendTailContentTailRecord [mi_sys]) from [<bfc2b969>] (_MI_VENC_ProcShowOutInfo+0x2bc/0x448 [mi_venc])
[<bfc2b969>] (_MI_VENC_ProcShowOutInfo [mi_venc]) from [<bfc32327>] (_MI_VENC_DequeueInputTask+0xb2e/0xf64 [mi_venc])
[<bfc32327>] (_MI_VENC_DequeueInputTask [mi_venc]) from [<bfb0fccb>] (MI_SYS_IMPL_DequeueInputOutputTasks+0x822/0x13dc [mi_sys])
[<bfb0fccb>] (MI_SYS_IMPL_DequeueInputOutputTasks [mi_sys]) from [<bfb1575b>] (mi_sys_internal_main_worker_thread+0xa0e/0x1a00 [mi_sys])
[<bfb1575b>] (mi_sys_internal_main_worker_thread [mi_sys]) from [<c0029da5>] (kthread+0x99/0xa8)
[<c0029da5>] (kthread) from [<c000d441>] (ret_from_fork+0x11/0x30)
从抓取的日志搜free命令的"Mem:"字段,可以看到如下结果(为了方便分析,日志有做冗余删除)。 可以看到free那一列显示的可用内存总体上在不断减少,基本可以认为是内存泄漏 。
total used free shared buffers
Mem: 44792 40148 4644 12 272
Mem: 44792 41036 3756 12 792
Mem: 44792 40996 3796 12 636
Mem: 44792 41112 3680 12 356
Mem: 44792 41460 3332 12 440
Mem: 44792 41084 3708 12 608
Mem: 44792 41100 3692 12 536
Mem: 44792 41196 3596 12 748
Mem: 44792 41064 3728 12 360
Mem: 44792 41380 3412 12 516
Mem: 44792 41468 3324 12 728
Mem: 44792 41980 2812 12 1072
Mem: 44792 41424 3368 12 632
Mem: 44792 40992 3800 12 248
Mem: 44792 42176 2616 12 932
Mem: 44792 42092 2700 12 924
Mem: 44792 42576 2216 12 920
Mem: 44792 41988 2804 12 636
Mem: 44792 42132 2660 12 568
Mem: 44792 41856 2936 12 704
Mem: 44792 41408 3384 12 332
Mem: 44792 42008 2784 12 664
Mem: 44792 42196 2596 12 760
Mem: 44792 42008 2784 12 472
Mem: 44792 42536 2256 12 772
Mem: 44792 43064 1728 12 748
Mem: 44792 43788 1004 12 1184
定位内存泄漏的模块¶
测试刚开始的内存信息打印:
MemTotal: 44792 kB
MemFree: 7904 kB
MemAvailable: 19716 kB
Buffers: 2396 kB
Cached: 10744 kB
SwapCached: 0 kB
Active: 5972 kB
Inactive: 8804 kB
Active(anon): 1648 kB
Inactive(anon): 0 kB
Active(file): 4324 kB
Inactive(file): 8804 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 0 kB
Writeback: 0 kB
AnonPages: 1668 kB
Mapped: 4412 kB
Shmem: 12 kB
Slab: 14508 kB
SReclaimable: 1884 kB
SUnreclaim: 12624 kB
KernelStack: 544 kB
PageTables: 164 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 22396 kB
Committed_AS: 53880 kB
VmallocTotal: 991232 kB
VmallocUsed: 0 kB
VmallocChunk: 0 kB
CmaTotal: 2048 kB
CmaFree: 1740 kB
##############################################################################################
slabinfo - version: 2.1
- # name <active_objs> <num_objs> <objsize> <objperslab> <pagesperslab>
- tunables <limit> <batchcount> <sharedfactor> : slabdata <active_slabs> <num_slabs> <sharedavail>
mi_vpe_taskinfo 4 4 16384 2 8 : tunables 0 0 0 : slabdata 2 2 0
cmdq_pool 3 18 224 18 1 : tunables 0 0 0 : slabdata 1 1 0
mi_sys_bufhandle_cachep 23 24 16384 2 8 : tunables 0 0 0 : slabdata 12 12 0
mi_sys_ringpool_record_cachep 0 2 16384 2 8 : tunables 0 0 0 : slabdata 1 1 0
g_mi_sysmem_sgtable_info_cachep 0 0 16384 2 8 : tunables 0 0 0 : slabdata 0 0 0
mi_sys_cust_allocation_cachep 2 2 16384 2 8 : tunables 0 0 0 : slabdata 1 1 0
g_mi_sys_chunk_cachep 27 28 16384 2 8 : tunables 0 0 0 : slabdata 14 14 0
mi_sys_mma_allocation_cachep 26 26 16384 2 8 : tunables 0 0 0 : slabdata 13 13 0
mi_sys_internal_inputtaskinfo_cachep 4 8 16384 2 8 : tunables 0 0 0 : slabdata 4 4 0
mi_sys_internal_inputtaskinfo_cachep 3 4 16384 2 8 : tunables 0 0 0 : slabdata 2 2 0
mi_sys_bufref_cachep 8 8 16384 2 8 : tunables 0 0 0 : slabdata 4 4 0
sd_ext_cdb 2 18 216 18 1 : tunables 0 0 0 : slabdata 1 1 0
ntfs_big_inode_cache 0 0 896 9 2 : tunables 0 0 0 : slabdata 0 0 0
ntfs_inode_cache 0 0 432 9 1 : tunables 0 0 0 : slabdata 0 0 0
ntfs_name_cache 0 0 768 10 2 : tunables 0 0 0 : slabdata 0 0 0
ntfs_attr_ctx_cache 0 0 256 16 1 : tunables 0 0 0 : slabdata 0 0 0
ntfs_index_ctx_cache 0 0 320 12 1 : tunables 0 0 0 : slabdata 0 0 0
fat_inode_cache 0 0 672 12 2 : tunables 0 0 0 : slabdata 0 0 0
fat_cache 0 0 200 20 1 : tunables 0 0 0 : slabdata 0 0 0
nfs_direct_cache 0 0 384 10 1 : tunables 0 0 0 : slabdata 0 0 0
nfs_commit_data 4 11 704 11 2 : tunables 0 0 0 : slabdata 1 1 0
nfs_write_data 32 38 832 19 4 : tunables 0 0 0 : slabdata 2 2 0
nfs_read_data 0 0 832 19 4 : tunables 0 0 0 : slabdata 0 0 0
nfs_inode_cache 1 19 832 19 4 : tunables 0 0 0 : slabdata 1 1 0
nfs_page 0 0 320 12 1 : tunables 0 0 0 : slabdata 0 0 0
rpc_inode_cache 0 0 704 11 2 : tunables 0 0 0 : slabdata 0 0 0
rpc_buffers 8 14 2304 14 8 : tunables 0 0 0 : slabdata 1 1 0
rpc_tasks 8 10 384 10 1 : tunables 0 0 0 : slabdata 1 1 0
cifs_small_rq 30 33 704 11 2 : tunables 0 0 0 : slabdata 3 3 0
cifs_request 4 4 16768 1 8 : tunables 0 0 0 : slabdata 4 4 0
cifs_mpx_ids 3 12 320 12 1 : tunables 0 0 0 : slabdata 1 1 0
cifs_inode_cache 0 0 672 12 2 : tunables 0 0 0 : slabdata 0 0 0
scsi_data_buffer 0 0 200 20 1 : tunables 0 0 0 : slabdata 0 0 0
ubi_wl_entry_slab 865 880 200 20 1 : tunables 0 0 0 : slabdata 44 44 0
ubifs_inode_slab 52 69 688 23 4 : tunables 0 0 0 : slabdata 3 3 0
sgpool-128 2 14 2304 14 8 : tunables 0 0 0 : slabdata 1 1 0
sgpool-64 2 12 1280 12 4 : tunables 0 0 0 : slabdata 1 1 0
sgpool-32 2 10 768 10 2 : tunables 0 0 0 : slabdata 1 1 0
sgpool-16 2 8 512 8 1 : tunables 0 0 0 : slabdata 1 1 0
sgpool-8 2 10 384 10 1 : tunables 0 0 0 : slabdata 1 1 0
mqueue_inode_cache 1 19 832 19 4 : tunables 0 0 0 : slabdata 1 1 0
jffs2_inode_cache 0 0 208 19 1 : tunables 0 0 0 : slabdata 0 0 0
jffs2_node_frag 0 0 208 19 1 : tunables 0 0 0 : slabdata 0 0 0
jffs2_refblock 0 0 432 9 1 : tunables 0 0 0 : slabdata 0 0 0
jffs2_tmp_dnode 0 0 216 18 1 : tunables 0 0 0 : slabdata 0 0 0
jffs2_raw_inode 0 0 320 12 1 : tunables 0 0 0 : slabdata 0 0 0
jffs2_raw_dirent 0 0 320 12 1 : tunables 0 0 0 : slabdata 0 0 0
jffs2_full_dnode 0 0 200 20 1 : tunables 0 0 0 : slabdata 0 0 0
jffs2_i 0 0 624 13 2 : tunables 0 0 0 : slabdata 0 0 0
squashfs_inode_cache 84 88 704 11 2 : tunables 0 0 0 : slabdata 8 8 0
kioctx 0 0 512 8 1 : tunables 0 0 0 : slabdata 0 0 0
aio_kiocb 0 0 320 12 1 : tunables 0 0 0 : slabdata 0 0 0
dnotify_mark 0 0 248 16 1 : tunables 0 0 0 : slabdata 0 0 0
dnotify_struct 0 0 200 20 1 : tunables 0 0 0 : slabdata 0 0 0
dio 0 0 536 15 2 : tunables 0 0 0 : slabdata 0 0 0
fasync_cache 0 0 224 18 1 : tunables 0 0 0 : slabdata 0 0 0
pid_namespace 0 0 288 14 1 : tunables 0 0 0 : slabdata 0 0 0
posix_timers_cache 0 0 352 11 1 : tunables 0 0 0 : slabdata 0 0 0
UNIX 0 8 960 8 2 : tunables 0 0 0 : slabdata 1 1 0
ip4-frags 0 0 320 12 1 : tunables 0 0 0 : slabdata 0 0 0
UDP-Lite 0 0 960 8 2 : tunables 0 0 0 : slabdata 0 0 0
tcp_bind_bucket 3 16 256 16 1 : tunables 0 0 0 : slabdata 1 1 0
inet_peer_cache 1 10 384 10 1 : tunables 0 0 0 : slabdata 1 1 0
ip_fib_trie 4 18 216 18 1 : tunables 0 0 0 : slabdata 1 1 0
ip_fib_alias 5 18 216 18 1 : tunables 0 0 0 : slabdata 1 1 0
ip_dst_cache 6 10 384 10 1 : tunables 0 0 0 : slabdata 1 1 0
PING 0 0 896 9 2 : tunables 0 0 0 : slabdata 0 0 0
RAW 2 8 960 8 2 : tunables 0 0 0 : slabdata 1 1 0
UDP 1 8 960 8 2 : tunables 0 0 0 : slabdata 1 1 0
tw_sock_TCP 0 12 328 12 1 : tunables 0 0 0 : slabdata 1 1 0
request_sock_TCP 0 21 376 21 2 : tunables 0 0 0 : slabdata 1 1 0
TCP 4 9 1792 9 4 : tunables 0 0 0 : slabdata 1 1 0
eventpoll_pwq 0 0 216 18 1 : tunables 0 0 0 : slabdata 0 0 0
eventpoll_epi 0 0 320 12 1 : tunables 0 0 0 : slabdata 0 0 0
inotify_inode_mark 0 0 248 16 1 : tunables 0 0 0 : slabdata 0 0 0
request_queue 10 12 1304 12 4 : tunables 0 0 0 : slabdata 1 1 0
blkdev_requests 40 50 392 10 1 : tunables 0 0 0 : slabdata 5 5 0
blkdev_ioc 2 16 256 16 1 : tunables 0 0 0 : slabdata 1 1 0
bio-0 22 50 384 10 1 : tunables 0 0 0 : slabdata 5 5 0
biovec-256 22 27 3328 9 8 : tunables 0 0 0 : slabdata 3 3 0
biovec-128 0 0 1792 9 4 : tunables 0 0 0 : slabdata 0 0 0
biovec-64 0 0 1024 8 2 : tunables 0 0 0 : slabdata 0 0 0
biovec-16 0 0 448 9 1 : tunables 0 0 0 : slabdata 0 0 0
uid_cache 0 0 320 12 1 : tunables 0 0 0 : slabdata 0 0 0
sock_inode_cache 14 22 704 11 2 : tunables 0 0 0 : slabdata 2 2 0
skbuff_fclone_cache 2 12 640 12 2 : tunables 0 0 0 : slabdata 1 1 0
skbuff_head_cache 256 261 448 9 1 : tunables 0 0 0 : slabdata 29 29 0
configfs_dir_cache 0 0 232 17 1 : tunables 0 0 0 : slabdata 0 0 0
file_lock_cache 0 0 320 12 1 : tunables 0 0 0 : slabdata 0 0 0
file_lock_ctx 0 0 224 18 1 : tunables 0 0 0 : slabdata 0 0 0
net_namespace 0 0 960 8 2 : tunables 0 0 0 : slabdata 0 0 0
shmem_inode_cache 185 200 632 25 4 : tunables 0 0 0 : slabdata 8 8 0
pool_workqueue 3 10 768 10 2 : tunables 0 0 0 : slabdata 1 1 0
proc_inode_cache 31 39 592 13 2 : tunables 0 0 0 : slabdata 3 3 0
sigqueue 0 12 328 12 1 : tunables 0 0 0 : slabdata 1 1 0
bdev_cache 2 19 832 19 4 : tunables 0 0 0 : slabdata 1 1 0
kernfs_node_cache 10398 10410 264 15 1 : tunables 0 0 0 : slabdata 694 694 0
mnt_cache 25 32 512 8 1 : tunables 0 0 0 : slabdata 4 4 0
filp 105 117 448 9 1 : tunables 0 0 0 : slabdata 13 13 0
inode_cache 1458 1470 560 14 2 : tunables 0 0 0 : slabdata 105 105 0
dentry 1858 1860 336 12 1 : tunables 0 0 0 : slabdata 155 155 0
names_cache 0 14 4352 7 8 : tunables 0 0 0 : slabdata 2 2 0
buffer_head 599 612 232 17 1 : tunables 0 0 0 : slabdata 36 36 0
nsproxy 1 19 208 19 1 : tunables 0 0 0 : slabdata 1 1 0
vm_area_struct 302 315 272 15 1 : tunables 0 0 0 : slabdata 21 21 0
mm_struct 7 22 704 11 2 : tunables 0 0 0 : slabdata 2 2 0
fs_cache 7 24 320 12 1 : tunables 0 0 0 : slabdata 2 2 0
files_cache 7 16 512 8 1 : tunables 0 0 0 : slabdata 2 2 0
signal_cache 63 76 832 19 4 : tunables 0 0 0 : slabdata 4 4 0
sighand_cache 62 70 1600 10 4 : tunables 0 0 0 : slabdata 7 7 0
task_struct 69 77 1408 11 4 : tunables 0 0 0 : slabdata 7 7 0
cred_jar 73 80 384 10 1 : tunables 0 0 0 : slabdata 8 8 0
anon_vma_chain 174 198 216 18 1 : tunables 0 0 0 : slabdata 11 11 0
anon_vma 114 119 232 17 1 : tunables 0 0 0 : slabdata 7 7 0
pid 68 72 320 12 1 : tunables 0 0 0 : slabdata 6 6 0
radix_tree_node 327 336 280 14 1 : tunables 0 0 0 : slabdata 24 24 0
idr_layer_cache 142 143 1248 13 4 : tunables 0 0 0 : slabdata 11 11 0
kmalloc-8192 4 6 8448 3 8 : tunables 0 0 0 : slabdata 2 2 0
kmalloc-4096 158 161 4352 7 8 : tunables 0 0 0 : slabdata 23 23 0
kmalloc-2048 330 336 2304 14 8 : tunables 0 0 0 : slabdata 24 24 0
kmalloc-1024 148 156 1280 12 4 : tunables 0 0 0 : slabdata 13 13 0
kmalloc-512 365 370 768 10 2 : tunables 0 0 0 : slabdata 37 37 0
kmalloc-256 382 384 512 8 1 : tunables 0 0 0 : slabdata 48 48 0
kmalloc-192 79 90 448 9 1 : tunables 0 0 0 : slabdata 10 10 0
kmalloc-128 1046 1060 384 10 1 : tunables 0 0 0 : slabdata 106 106 0
kmalloc-64 10491 10500 320 12 1 : tunables 0 0 0 : slabdata 875 875 0
kmem_cache_node 128 132 320 12 1 : tunables 0 0 0 : slabdata 11 11 0
kmem_cache 128 130 384 10 1 : tunables 0 0 0 : slabdata 13 13 0
###################
total used free shared buffers
Mem: 44792 36904 7888 12 2396
-/+ buffers: 34508 10284
Swap: 0 0 0
复现到内存泄漏时内存信息打印:
MemTotal: 44792 kB
MemFree: 2036 kB
MemAvailable: 2848 kB
Buffers: 788 kB
Cached: 1904 kB
SwapCached: 0 kB
Active: 4640 kB
Inactive: 1172 kB
Active(anon): 3132 kB
Inactive(anon): 0 kB
Active(file): 1508 kB
Inactive(file): 1172 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 0 kB
Writeback: 0 kB
AnonPages: 3124 kB
Mapped: 1120 kB
Shmem: 12 kB
Slab: 29252 kB
SReclaimable: 784 kB
SUnreclaim: 28468 kB
KernelStack: 560 kB
PageTables: 196 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 22396 kB
Committed_AS: 86780 kB
VmallocTotal: 991232 kB
VmallocUsed: 0 kB
VmallocChunk: 0 kB
CmaTotal: 2048 kB
CmaFree: 0 kB
##############################################################################################
slabinfo - version: 2.1
- # name <active_objs> <num_objs> <objsize> <objperslab> <pagesperslab>
- tunables <limit> <batchcount> <sharedfactor> : slabdata <active_slabs> <num_slabs> <sharedavail>
mi_shadow_devinfo_cacheheap 0 2 16384 2 8 : tunables 0 0 0 : slabdata 1 1 0
divp_chnres_cache 1 8 512 8 1 : tunables 0 0 0 : slabdata 1 1 0
mi_vpe_taskinfo 4 4 16384 2 8 : tunables 0 0 0 : slabdata 2 2 0
cmdq_pool 3 18 224 18 1 : tunables 0 0 0 : slabdata 1 1 0
mi_sys_bufhandle_cachep 327 330 16384 2 8 : tunables 0 0 0 : slabdata 173 173 0
mi_sys_ringpool_record_cachep 0 12 16384 2 8 : tunables 0 0 0 : slabdata 6 6 0
g_mi_sysmem_sgtable_info_cachep 0 0 16384 2 8 : tunables 0 0 0 : slabdata 0 0 0
mi_sys_cust_allocation_cachep 2 4 16384 2 8 : tunables 0 0 0 : slabdata 2 2 0
g_mi_sys_chunk_cachep 334 338 16384 2 8 : tunables 0 0 0 : slabdata 193 193 0
mi_sys_mma_allocation_cachep 330 337 16384 2 8 : tunables 0 0 0 : slabdata 188 188 0
mi_sys_internal_inputtaskinfo_cachep 4 8 16384 2 8 : tunables 0 0 0 : slabdata 4 4 0
mi_sys_internal_inputtaskinfo_cachep 3 8 16384 2 8 : tunables 0 0 0 : slabdata 4 4 0
mi_sys_bufref_cachep 8 13 16384 2 8 : tunables 0 0 0 : slabdata 7 7 0
sd_ext_cdb 2 18 216 18 1 : tunables 0 0 0 : slabdata 1 1 0
ntfs_big_inode_cache 0 0 896 9 2 : tunables 0 0 0 : slabdata 0 0 0
ntfs_inode_cache 0 0 432 9 1 : tunables 0 0 0 : slabdata 0 0 0
ntfs_name_cache 0 0 768 10 2 : tunables 0 0 0 : slabdata 0 0 0
ntfs_attr_ctx_cache 0 0 256 16 1 : tunables 0 0 0 : slabdata 0 0 0
ntfs_index_ctx_cache 0 0 320 12 1 : tunables 0 0 0 : slabdata 0 0 0
fat_inode_cache 0 0 672 12 2 : tunables 0 0 0 : slabdata 0 0 0
fat_cache 0 0 200 20 1 : tunables 0 0 0 : slabdata 0 0 0
nfs_direct_cache 0 0 384 10 1 : tunables 0 0 0 : slabdata 0 0 0
nfs_commit_data 4 11 704 11 2 : tunables 0 0 0 : slabdata 1 1 0
nfs_write_data 32 38 832 19 4 : tunables 0 0 0 : slabdata 2 2 0
nfs_read_data 0 0 832 19 4 : tunables 0 0 0 : slabdata 0 0 0
nfs_inode_cache 1 19 832 19 4 : tunables 0 0 0 : slabdata 1 1 0
nfs_page 0 0 320 12 1 : tunables 0 0 0 : slabdata 0 0 0
rpc_inode_cache 0 0 704 11 2 : tunables 0 0 0 : slabdata 0 0 0
rpc_buffers 8 14 2304 14 8 : tunables 0 0 0 : slabdata 1 1 0
rpc_tasks 8 10 384 10 1 : tunables 0 0 0 : slabdata 1 1 0
cifs_small_rq 30 33 704 11 2 : tunables 0 0 0 : slabdata 3 3 0
cifs_request 4 4 16768 1 8 : tunables 0 0 0 : slabdata 4 4 0
cifs_mpx_ids 3 12 320 12 1 : tunables 0 0 0 : slabdata 1 1 0
cifs_inode_cache 0 0 672 12 2 : tunables 0 0 0 : slabdata 0 0 0
scsi_data_buffer 0 0 200 20 1 : tunables 0 0 0 : slabdata 0 0 0
ubi_wl_entry_slab 865 880 200 20 1 : tunables 0 0 0 : slabdata 44 44 0
ubifs_inode_slab 4 69 688 23 4 : tunables 0 0 0 : slabdata 3 3 0
sgpool-128 2 14 2304 14 8 : tunables 0 0 0 : slabdata 1 1 0
sgpool-64 2 12 1280 12 4 : tunables 0 0 0 : slabdata 1 1 0
sgpool-32 2 10 768 10 2 : tunables 0 0 0 : slabdata 1 1 0
sgpool-16 2 8 512 8 1 : tunables 0 0 0 : slabdata 1 1 0
sgpool-8 2 10 384 10 1 : tunables 0 0 0 : slabdata 1 1 0
mqueue_inode_cache 1 19 832 19 4 : tunables 0 0 0 : slabdata 1 1 0
jffs2_inode_cache 0 0 208 19 1 : tunables 0 0 0 : slabdata 0 0 0
jffs2_node_frag 0 0 208 19 1 : tunables 0 0 0 : slabdata 0 0 0
jffs2_refblock 0 0 432 9 1 : tunables 0 0 0 : slabdata 0 0 0
jffs2_tmp_dnode 0 0 216 18 1 : tunables 0 0 0 : slabdata 0 0 0
jffs2_raw_inode 0 0 320 12 1 : tunables 0 0 0 : slabdata 0 0 0
jffs2_raw_dirent 0 0 320 12 1 : tunables 0 0 0 : slabdata 0 0 0
jffs2_full_dnode 0 0 200 20 1 : tunables 0 0 0 : slabdata 0 0 0
jffs2_i 0 0 624 13 2 : tunables 0 0 0 : slabdata 0 0 0
squashfs_inode_cache 52 88 704 11 2 : tunables 0 0 0 : slabdata 8 8 0
kioctx 0 0 512 8 1 : tunables 0 0 0 : slabdata 0 0 0
aio_kiocb 0 0 320 12 1 : tunables 0 0 0 : slabdata 0 0 0
dnotify_mark 0 0 248 16 1 : tunables 0 0 0 : slabdata 0 0 0
dnotify_struct 0 0 200 20 1 : tunables 0 0 0 : slabdata 0 0 0
dio 0 0 536 15 2 : tunables 0 0 0 : slabdata 0 0 0
fasync_cache 0 0 224 18 1 : tunables 0 0 0 : slabdata 0 0 0
pid_namespace 0 0 288 14 1 : tunables 0 0 0 : slabdata 0 0 0
posix_timers_cache 0 0 352 11 1 : tunables 0 0 0 : slabdata 0 0 0
UNIX 0 8 960 8 2 : tunables 0 0 0 : slabdata 1 1 0
ip4-frags 0 0 320 12 1 : tunables 0 0 0 : slabdata 0 0 0
UDP-Lite 0 0 960 8 2 : tunables 0 0 0 : slabdata 0 0 0
tcp_bind_bucket 3 16 256 16 1 : tunables 0 0 0 : slabdata 1 1 0
inet_peer_cache 1 10 384 10 1 : tunables 0 0 0 : slabdata 1 1 0
ip_fib_trie 4 18 216 18 1 : tunables 0 0 0 : slabdata 1 1 0
ip_fib_alias 5 18 216 18 1 : tunables 0 0 0 : slabdata 1 1 0
ip_dst_cache 4 20 384 10 1 : tunables 0 0 0 : slabdata 2 2 0
PING 0 0 896 9 2 : tunables 0 0 0 : slabdata 0 0 0
RAW 2 8 960 8 2 : tunables 0 0 0 : slabdata 1 1 0
UDP 1 8 960 8 2 : tunables 0 0 0 : slabdata 1 1 0
tw_sock_TCP 0 12 328 12 1 : tunables 0 0 0 : slabdata 1 1 0
request_sock_TCP 0 21 376 21 2 : tunables 0 0 0 : slabdata 1 1 0
TCP 4 9 1792 9 4 : tunables 0 0 0 : slabdata 1 1 0
eventpoll_pwq 0 0 216 18 1 : tunables 0 0 0 : slabdata 0 0 0
eventpoll_epi 0 0 320 12 1 : tunables 0 0 0 : slabdata 0 0 0
inotify_inode_mark 0 0 248 16 1 : tunables 0 0 0 : slabdata 0 0 0
request_queue 10 12 1304 12 4 : tunables 0 0 0 : slabdata 1 1 0
blkdev_requests 41 50 392 10 1 : tunables 0 0 0 : slabdata 5 5 0
blkdev_ioc 11 16 256 16 1 : tunables 0 0 0 : slabdata 1 1 0
bio-0 33 60 384 10 1 : tunables 0 0 0 : slabdata 6 6 0
biovec-256 22 27 3328 9 8 : tunables 0 0 0 : slabdata 3 3 0
biovec-128 0 0 1792 9 4 : tunables 0 0 0 : slabdata 0 0 0
biovec-64 0 0 1024 8 2 : tunables 0 0 0 : slabdata 0 0 0
biovec-16 0 0 448 9 1 : tunables 0 0 0 : slabdata 0 0 0
uid_cache 0 0 320 12 1 : tunables 0 0 0 : slabdata 0 0 0
sock_inode_cache 14 22 704 11 2 : tunables 0 0 0 : slabdata 2 2 0
skbuff_fclone_cache 0 12 640 12 2 : tunables 0 0 0 : slabdata 1 1 0
skbuff_head_cache 256 261 448 9 1 : tunables 0 0 0 : slabdata 29 29 0
configfs_dir_cache 0 0 232 17 1 : tunables 0 0 0 : slabdata 0 0 0
file_lock_cache 0 0 320 12 1 : tunables 0 0 0 : slabdata 0 0 0
file_lock_ctx 0 0 224 18 1 : tunables 0 0 0 : slabdata 0 0 0
net_namespace 0 0 960 8 2 : tunables 0 0 0 : slabdata 0 0 0
shmem_inode_cache 487 500 632 25 4 : tunables 0 0 0 : slabdata 20 20 0
pool_workqueue 3 10 768 10 2 : tunables 0 0 0 : slabdata 1 1 0
proc_inode_cache 4 52 592 13 2 : tunables 0 0 0 : slabdata 4 4 0
sigqueue 0 12 328 12 1 : tunables 0 0 0 : slabdata 1 1 0
bdev_cache 2 19 832 19 4 : tunables 0 0 0 : slabdata 1 1 0
kernfs_node_cache 10458 10470 264 15 1 : tunables 0 0 0 : slabdata 698 698 0
mnt_cache 25 32 512 8 1 : tunables 0 0 0 : slabdata 4 4 0
filp 387 405 448 9 1 : tunables 0 0 0 : slabdata 45 45 0
inode_cache 183 266 560 14 2 : tunables 0 0 0 : slabdata 19 19 0
dentry 743 1008 336 12 1 : tunables 0 0 0 : slabdata 84 84 0
names_cache 0 14 4352 7 8 : tunables 0 0 0 : slabdata 2 2 0
buffer_head 178 187 232 17 1 : tunables 0 0 0 : slabdata 11 11 0
nsproxy 1 19 208 19 1 : tunables 0 0 0 : slabdata 1 1 0
vm_area_struct 616 630 272 15 1 : tunables 0 0 0 : slabdata 42 42 0
mm_struct 7 22 704 11 2 : tunables 0 0 0 : slabdata 2 2 0
fs_cache 7 24 320 12 1 : tunables 0 0 0 : slabdata 2 2 0
files_cache 7 16 512 8 1 : tunables 0 0 0 : slabdata 2 2 0
signal_cache 64 76 832 19 4 : tunables 0 0 0 : slabdata 4 4 0
sighand_cache 64 70 1600 10 4 : tunables 0 0 0 : slabdata 7 7 0
task_struct 70 88 1408 11 4 : tunables 0 0 0 : slabdata 8 8 0
cred_jar 72 80 384 10 1 : tunables 0 0 0 : slabdata 8 8 0
anon_vma_chain 180 216 216 18 1 : tunables 0 0 0 : slabdata 12 12 0
anon_vma 120 136 232 17 1 : tunables 0 0 0 : slabdata 8 8 0
pid 70 84 320 12 1 : tunables 0 0 0 : slabdata 7 7 0
radix_tree_node 136 196 280 14 1 : tunables 0 0 0 : slabdata 14 14 0
idr_layer_cache 142 156 1248 13 4 : tunables 0 0 0 : slabdata 12 12 0
kmalloc-8192 4 9 8448 3 8 : tunables 0 0 0 : slabdata 3 3 0
kmalloc-4096 158 161 4352 7 8 : tunables 0 0 0 : slabdata 23 23 0
kmalloc-2048 334 350 2304 14 8 : tunables 0 0 0 : slabdata 25 25 0
kmalloc-1024 171 180 1280 12 4 : tunables 0 0 0 : slabdata 15 15 0
kmalloc-512 361 375 768 10 2 : tunables 0 0 0 : slabdata 38 38 0
kmalloc-256 145 216 512 8 1 : tunables 0 0 0 : slabdata 27 27 0
kmalloc-192 81 108 448 9 1 : tunables 0 0 0 : slabdata 12 12 0
kmalloc-128 1009 1060 384 10 1 : tunables 0 0 0 : slabdata 106 106 0
kmalloc-64 11103 11112 320 12 1 : tunables 0 0 0 : slabdata 926 926 0
kmem_cache_node 130 132 320 12 1 : tunables 0 0 0 : slabdata 11 11 0
kmem_cache 130 130 384 10 1 : tunables 0 0 0 : slabdata 13 13 0
###################
total used free shared buffers
Mem: 44792 43788 1004 12 1184
-/+ buffers: 42604 2188
Swap: 0 0 0
1.比较测试开始时和复现到内存泄漏时的/proc/meminfo信息
可以看到MemFree和MemAvailable从(7904, 19716)减少到(2036, 2848), 而Slab、SReclaimable和SUnreclaim从(14508, 1884, 12624)增加到(29252, 784, 28468),由此可以**基本确定是Slab内存泄漏**。
因此我们需要关注/proc/slabinfo信息的变化。
2.比较测试开始时和复现到内存泄漏时的/proc/slabinfo信息
可以看到mi_sys_bufhandle_cachep、g_mi_sys_chunk_cachep和mi_sys_mma_allocation_cachep大小是原来的10倍,增加的内存最多,可以确定主要是这里引起了内存泄漏。
而每个mi_sys_bufhandle_cachep、g_mi_sys_chunk_cachep和mi_sys_mma_allocation_cachep会在mma内存里面有对应的内存块,所以可以**确定是mma的内存泄漏**。
因此我们需要关注/proc/mi_modules/mi_sys_mma/mma_heap_name0信息的变化。
3. 比较测试开始时和复现到内存泄漏时的/proc/mi_modules/mi_sys_mma/mma_heap_name0信息
这一步由于之前没有打印mma_heap_name0的信息,需要再次复现问题,这次是专门打印mma_heap_name0的信息。
在开始复现问题的时候可以执行以下脚本做打印:
#!/bin/bash
while true
do
echo "################################################################"
cat /proc/mi_modules/mi_sys_mma/mma_heap_name0
sleep 5s
done
复现到问题后,我们对比测试刚开始时和问题出现时的mma_heap_name0信息,如下:
可用看到内存泄漏时会多出很多用户空间申请名为app-mmaAlloc的mma内存,在开关MD/OD时没有及时释放。
从这里可用猜想到,事实上不需要做压测也可用看到内存泄漏,只需要开关MD/OD一次,再看mma_heap_name0的信息就可用知道会有app-mmaAlloc内存没释放。
为了查看是在用户空间哪个地方call了MI_SYS_MMA_Alloc去要mma内存,可用在MI_SYS_MMA_Alloc接口里面加backtrace打印。
操作打开MD就可用看到申请mma内存的backtrace:
Obtained 10 stack frames.
/lib/libmi_sys.so(print_trace+0x1b) [0xb6e285b0]
/lib/libmi_sys.so(MI_SYS_MMA_Alloc+0x19) [0xb6e2863a]
/lib/libMD_LINUX.so [0xb6c05794]
/lib/libMD_LINUX.so [0xb6c2f084]
/lib/libMD_LINUX.so [0xb6c003b4]
/lib/libMD_LINUX.so(MI_MD_Init+0x104) [0xb6c035a8]
/lib/libmi_vdf.so [0xb6e058ce]
/lib/libmi_vdf.so(MI_VDF_CreateChn+0x5e1) [0xb6e0b3e2]
/customer/mixer(_Z17mid_md_VDF_Configi+0x33) [0x82ff8]
/customer/mixer(_Z14mid_md_Initiali+0x25) [0x8316e]
Obtained 10 stack frames.
/lib/libmi_sys.so(print_trace+0x1b) [0xb6e285b0]
/lib/libmi_sys.so(MI_SYS_MMA_Alloc+0x19) [0xb6e2863a]
/lib/libMD_LINUX.so [0xb6c05794]
/lib/libMD_LINUX.so [0xb6c2ea68]
/lib/libMD_LINUX.so [0xb6c00408]
/lib/libMD_LINUX.so(MI_MD_Init+0x104) [0xb6c035a8]
/lib/libmi_vdf.so [0xb6e058ce]
/lib/libmi_vdf.so(MI_VDF_CreateChn+0x5e1) [0xb6e0b3e2]
/customer/mixer(_Z17mid_md_VDF_Configi+0x33) [0x82ff8]
/customer/mixer(_Z14mid_md_Initiali+0x25) [0x8316e]
Obtained 10 stack frames.
/lib/libmi_sys.so(print_trace+0x1b) [0xb6e285b0]
/lib/libmi_sys.so(MI_SYS_MMA_Alloc+0x19) [0xb6e2863a]
/lib/libMD_LINUX.so [0xb6c05794]
/lib/libMD_LINUX.so [0xb6c2ea68]
/lib/libMD_LINUX.so [0xb6c0043c]
/lib/libMD_LINUX.so(MI_MD_Init+0x104) [0xb6c035a8]
/lib/libmi_vdf.so [0xb6e058ce]
/lib/libmi_vdf.so(MI_VDF_CreateChn+0x5e1) [0xb6e0b3e2]
/customer/mixer(_Z17mid_md_VDF_Configi+0x33) [0x82ff8]
/customer/mixer(_Z14mid_md_Initiali+0x25) [0x8316e]
Obtained 10 stack frames.
/lib/libmi_sys.so(print_trace+0x1b) [0xb6e285b0]
/lib/libmi_sys.so(MI_SYS_MMA_Alloc+0x19) [0xb6e2863a]
/lib/libMD_LINUX.so [0xb6c05794]
/lib/libMD_LINUX.so [0xb6c2ea68]
/lib/libMD_LINUX.so [0xb6c004d8]
/lib/libMD_LINUX.so(MI_MD_Init+0x104) [0xb6c035a8]
/lib/libmi_vdf.so [0xb6e058ce]
/lib/libmi_vdf.so(MI_VDF_CreateChn+0x5e1) [0xb6e0b3e2]
/customer/mixer(_Z17mid_md_VDF_Configi+0x33) [0x82ff8]
/customer/mixer(_Z14mid_md_Initiali+0x25) [0x8316e]
Obtained 10 stack frames.
/lib/libmi_sys.so(print_trace+0x1b) [0xb6e285b0]
/lib/libmi_sys.so(MI_SYS_MMA_Alloc+0x19) [0xb6e2863a]
/lib/libMD_LINUX.so [0xb6c05794]
/lib/libMD_LINUX.so [0xb6c2ea68]
/lib/libMD_LINUX.so [0xb6c0050c]
/lib/libMD_LINUX.so(MI_MD_Init+0x104) [0xb6c035a8]
/lib/libmi_vdf.so [0xb6e058ce]
/lib/libmi_vdf.so(MI_VDF_CreateChn+0x5e1) [0xb6e0b3e2]
/customer/mixer(_Z17mid_md_VDF_Configi+0x33) [0x82ff8]
/customer/mixer(_Z14mid_md_Initiali+0x25) [0x8316e]
Obtained 10 stack frames.
/lib/libmi_sys.so(print_trace+0x1b) [0xb6e285b0]
/lib/libmi_sys.so(MI_SYS_MMA_Alloc+0x19) [0xb6e2863a]
/lib/libMD_LINUX.so [0xb6c05794]
/lib/libMD_LINUX.so [0xb6c2ea68]
/lib/libMD_LINUX.so [0xb6c00540]
/lib/libMD_LINUX.so(MI_MD_Init+0x104) [0xb6c035a8]
/lib/libmi_vdf.so [0xb6e058ce]
/lib/libmi_vdf.so(MI_VDF_CreateChn+0x5e1) [0xb6e0b3e2]
/customer/mixer(_Z17mid_md_VDF_Configi+0x33) [0x82ff8]
/customer/mixer(_Z14mid_md_Initiali+0x25) [0x8316e]
[mid_md_Bind_DIVP_To_VDF 118] exec function pass
[DBG]:mid_md_Task[225]: enter md task loop, md model is 1
Obtained 7 stack frames.
/lib/libmi_sys.so(print_trace+0x1b) [0xb6e285b0]
/lib/libmi_sys.so(MI_SYS_MMA_Alloc+0x19) [0xb6e2863a]
/lib/libMD_LINUX.so [0xb6c05794]
/lib/libMD_LINUX.so [0xb6c2e698]
/lib/libMD_LINUX.so [0xb6c01000]
/lib/libmi_vdf.so [0xb6e06aae]
/lib/libmi_vdf.so(vdf_CalcRst_task+0x144b) [0xb6e09a94]
Obtained 7 stack frames.
/lib/libmi_sys.so(print_trace+0x1b) [0xb6e285b0]
/lib/libmi_sys.so(MI_SYS_MMA_Alloc+0x19) [0xb6e2863a]
/lib/libMD_LINUX.so [0xb6c05794]
/lib/libMD_LINUX.so [0xb6c2ea68]
/lib/libMD_LINUX.so [0xb6c01050]
/lib/libmi_vdf.so [0xb6e06aae]
/lib/libmi_vdf.so(vdf_CalcRst_task+0x144b) [0xb6e09a94]
4.用arm-linux-gnueabihf-gdb定位申请mma内存的地方
这里定位backtrace其中一个地方