Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Huge Memory allocated outside of Java Heap

I have a java program running as server. Java version is Java6u35. OS is CentOS 6.

The heap config is -Xmx3g -Xms3g. After days of run, it allocated over 8G memory and actually used over 6G memory.

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                        
26955 deploy    15   0 8347m 6.0g  10m S 30.9 25.5   3730:12 java 

The extra memory is surely ouside-heap memory. Using pmap, I got the following content. The unit is k. Whole output has beyond the limit of stackoverflow question body limitation, so I removed some small ones. Starting with size 1016k. (There are over 300 lines has similar content address 1,016 rwx-- [anon]):

addres             size(kB) 
0000000063ba3000    1,016   rwx--   [anon]   (over 300 similar lines omitted)
00002aaaaaac3000    1,020   -----   /usr/java/jdk1.6.0_35/jre/lib/amd64/libverify.so
00002aaaaabee000    1,020   -----   /usr/java/jdk1.6.0_35/jre/lib/amd64/libjava.so
00002aaaaad2c000    1,020   -----   /usr/java/jdk1.6.0_35/jre/lib/amd64/libjdwp.so
00002aaaaae38000    1,020   -----   /usr/java/jdk1.6.0_35/jre/lib/amd64/libnpt.so
00002aaab76b1000    1,020   -----   /usr/java/jdk1.6.0_35/jre/lib/amd64/libdt_socket.so
00002aaab77b8000    1,020   -----   /usr/java/jdk1.6.0_35/jre/lib/amd64/libmanagement.so
00002aaab842b000    1,020   -----   /usr/java/jdk1.6.0_35/jre/lib/amd64/libnio.so
00002aaab8748000    1,020   -----   /usr/java/jdk1.6.0_35/jre/lib/amd64/libjaas_unix.so
00002aab87519000    1,020   -----   /usr/java/jdk1.6.0_35/jre/lib/amd64/librmi.so
00000000411ec000    1,024   rwx--   [anon]
00000000412ed000    1,024   rwx--   [anon]
0000000041ad8000    1,024   rwx--   [anon]
0000000041bd9000    1,024   rwx--   [anon]
0000000041cda000    1,024   rwx--   [anon]
0000000041ddb000    1,024   rwx--   [anon]
0000000041edc000    1,024   rwx--   [anon]
0000000041fdd000    1,024   rwx--   [anon]
00000000420de000    1,024   rwx--   [anon]
00000000421df000    1,024   rwx--   [anon]
4.22E+02    1,024   rwx--   [anon]
00000000423e1000    1,024   rwx--   [anon]
00000000428e6000    1,024   rwx--   [anon]
00002b66d5a07000    1,024   -----   /usr/java/jdk1.6.0_35/jre/lib/amd64/server/libjvm.so
00002aaab78cc000    1,028   -----   /usr/java/jdk1.6.0_35/jre/lib/amd64/libnet.so
00002b66d4fe5000    1,028   -----   /usr/java/jdk1.6.0_35/jre/lib/amd64/jli/libjli.so
00002aaaae72f000    1,032   -----   /usr/java/jdk1.6.0_35/jre/lib/amd64/libzip.so
00002aab83efd000    1,036   -----   [anon]
00002aabbfefd000    1,036   -----   [anon]
00000038b5600000    1,340   r-x--   /lib64/libc-2.5.so
00002aaacfe95000    1,452   -----   [anon]
00002aaab74e3000    1,628   r-xs-   /usr/java/jdk1.6.0_35/jre/lib/rt.jar
00002b66d5b07000    1,752   rwx--   /usr/java/jdk1.6.0_35/jre/lib/amd64/server/libjvm.so
00000038b574f000    2,044   -----   /lib64/libc-2.5.so
00000038b5e16000    2,044   -----   /lib64/libpthread-2.5.so
00000038b6a82000    2,044   -----   /lib64/libm-2.5.so
00000038b9a15000    2,044   -----   /lib64/libnsl-2.5.so
00002aaaae520000    2,044   -----   /lib64/libnss_files-2.5.so
00002aaab8223000    2,044   -----   /lib64/libnss_dns-2.5.so
00000038b5a02000    2,048   -----   /lib64/libdl-2.5.so
00000038b7207000    2,048   -----   /lib64/librt-2.5.so
00000038b8211000    2,048   -----   /lib64/libresolv-2.5.so
00002aaab8546000    2,048   -----   /SERVER/lib/native/libhadoop.so
00002aaab79d0000    3,076   rwx--   [anon]
00002aabd3b22000    4,984   -----   [anon]
00002aaab18f5000    6,400   rwx--   [anon]
00002aaaae834000    7,940   rwx--   [anon]
ffffffffff600000    8,192   -----   [anon]
00002b66d50eb000    9,328   r-x--   /usr/java/jdk1.6.0_35/jre/lib/amd64/server/libjvm.so
00002aaac8000000    18,180  rwx--   [anon]
00002aabcc000000    28,724  rwx--   [anon]
00002aabcdc0d000    36,812  -----   [anon]
00002aaaaeff5000    41,216  rwx--   [anon]
00002aaac91c1000    47,356  -----   [anon]
00002aab84000000    54,368  rwx--   [anon]
00002aaaaaf38000    55,120  r-x--   /usr/lib/locale/locale-archive
00002aaab884c000    56,784  rwx--   [anon]
00002aabd0000000    60,552  rwx--   [anon]
00002aaacc000000    64,084  rwx--   [anon]
00002aab80000000    64,500  rwx--   [anon]
00002aabbc000000    64,500  rwx--   [anon]
00002aab14000000    64,576  rwx--   [anon]
00002aab64000000    64,584  rwx--   [anon]
00002aab90000000    64,668  rwx--   [anon]
00002aabac000000    64,684  rwx--   [anon]
00002aab88000000    64,692  rwx--   [anon]
00002aabc4000000    64,716  rwx--   [anon]
00002aab18000000    64,836  rwx--   [anon]
00002aab48000000    64,868  rwx--   [anon]
00002aabc0000000    64,896  rwx--   [anon]
00002aabb4000000    64,936  rwx--   [anon]
00002aabb8000000    64,948  rwx--   [anon]
00002aab94000000    64,976  rwx--   [anon]
00002aab1c000000    65,008  rwx--   [anon]
00002aabb0000000    65,020  rwx--   [anon]
00002aaaf8000000    65,032  rwx--   [anon]
00002aaabc000000    65,152  rwx--   [anon]
00002aab98000000    65,184  rwx--   [anon]
00002aaba0000000    65,320  rwx--   [anon]
00002aab8c000000    65,360  rwx--   [anon]
00002aaac0000000    65,388  rwx--   [anon]
00002aaba8000000    65,440  rwx--   [anon]
00002aaba4000000    65,472  rwx--   [anon]
00002aaac4000000    65,508  rwx--   [anon]
00002aab9c000000    65,508  rwx--   [anon]
00002aaab1f35000    87,736  rwx--   [anon]
000000004a74f000    104,592 rwx--   [anon]
00002aaafc000000    392,432 rwx--   [anon]
00002aab4c000000    392,480 rwx--   [anon]
00002aab68000000    392,908 rwx--   [anon]
00002aab20000000    654,464 rwx--   [anon]
00002aaad0000000    655,072 rwx--   [anon]
738000000   3,276,800   rwx--   [anon]
total   8,551,872       

Using this tool to check the direct memory usage https://gist.github.com/rednaxelafx/1593521:

JVM version is 20.10-b01
NIO direct memory: (in bytes)
  reserved size = 228.038025 MB (239115200 bytes)
  max size      = 2867.250000 MB (3006529536 bytes)

So the Direct Memory isn't too big. The 3,276,800 is java heap. But can't find who required hundreds of MB memory.

This server program uses hadoop client, hbase client to write data to hadoop and hbase. The java Heap it self works fine.

Any clue is appreciated.

like image 413
DeepNightTwo Avatar asked Sep 11 '13 06:09

DeepNightTwo


1 Answers

Figured out a solution but the reason is still in black box. After adding -XX:MaxDirectMemorySize=1024m, it works.

Seems like java GC for Memory Outside Heap (MOH) is not as smart as heap gc.

The guessed reason is, java gc for MOH is triggered when the MOH usage is reached some level, maybe 50%. So before that, it will only mark the memory as freed but not free it actually. Even the system has very little memory.

By default, the XX:MaxDirectMemorySize is big and even usage is 50%, system will down.

So after add this limitation, the threshold is easy to reach and MOH is freed in time.

So 1024m works for my application. It is big enough for application to run and not too big to make the system crash.

like image 147
DeepNightTwo Avatar answered Oct 01 '22 22:10

DeepNightTwo