Java堆外内存排查

1 查看内存占用

# pid
pmap -x pid | sort -n -k3

# memory
---------------- ------- ------- ------- 
00000007c1324000 1028976       0       0 -----   [ anon ]
00007f09d9a0a000      12       0       0 -----   [ anon ]
00007f09da212000      12       0       0 -----   [ anon ]
00007f09da313000      12       0       0 -----   [ anon ]
......
00007f0e2a000000  163840  163840  163840 rw---   [ anon ]
00007f0bf9eec000  361552  189408  189408 rw---   [ anon ]
0000000540000000 10485760 10460516 10460516 rw---   [ anon ]
total kB         34980624 13873904 13862028

可以发现,从0000000540000000开始的内存,是堆空间

2 dump内存

#!/bin/bash
grep rw-p /proc/$1/maps | sed -n 's/^\([0-9a-f]*\)-\([0-9a-f]*\) .*$/ /p' | while read start stop; do gdb --batch --pid $1 -ex "dump memory $1-$start-$stop.dump 0x$start 0x$stop"; done

dump一部分内存

gdb --batch --pid $pid -ex "dump memory a.dump 0x7f2bceda1000 0x7f2bcef2b000

3 查看内存内容

view xxxx.dump

 

Leave a Reply

Your email address will not be published. Required fields are marked *