aspose file tools*
The moose likes Linux / UNIX and the fly likes java memory usage on linux Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "java memory usage on linux" Watch "java memory usage on linux" New topic

java memory usage on linux

Santosh Manjrekar

Joined: Aug 10, 2004
Posts: 2
I have a socket server running on sun solaris which accepts requests and sends back response.It runs fine on solaris and have no performance memory issue. When I run same program on 64 bit linux ,I noticed that this program consumes lot of memory. Even when i start this program on linux and there is no requests,program consumes lot of memory. The java process memory footprint is around 811MB (using pmap command or top -p).
I use jre1.5.0_11 and memory parameters set to -Xms32m -Xmx512m

When I looked at my pmap output, I see lots of annon processes consuming memory I tried to use -XX:InitialCodeCacheSize=# and -XX:ReservedCodeCacheSize=# parameters but it didn't help.

Any help or suggestions are appreciated

Here is the pmap output

0000000040000000 56K r-x-- /bb/util/jre1.5.0_11/bin/java
000000004010d000 12K rw--- /bb/util/jre1.5.0_11/bin/java
0000000040110000 268K rwx-- [ anon ]
0000000040153000 4K ----- [ anon ]
0000000040154000 1024K rwx-- [ anon ]
0000000040254000 4K ----- [ anon ]
0000000040255000 1024K rwx-- [ anon ]
0000000040355000 4K ----- [ anon ]
0000000040356000 1024K rwx-- [ anon ]
0000000040456000 4K ----- [ anon ]
0000000040457000 1024K rwx-- [ anon ]
0000000040557000 4K ----- [ anon ]
0000000040558000 1024K rwx-- [ anon ]
0000000040658000 4K ----- [ anon ]
0000000040659000 1024K rwx-- [ anon ]
0000000040759000 4K ----- [ anon ]
000000004075a000 1024K rwx-- [ anon ]
000000004085a000 4K ----- [ anon ]
000000004085b000 1024K rwx-- [ anon ]
000000004095b000 4K ----- [ anon ]
000000004095c000 1024K rwx-- [ anon ]
0000000040a5c000 12K ----- [ anon ]
0000000040a5f000 1016K rwx-- [ anon ]
0000000040b5d000 12K ----- [ anon ]
0000000040b60000 1016K rwx-- [ anon ]
0000000040c5e000 12K ----- [ anon ]
0000000040c61000 1016K rwx-- [ anon ]
0000000040d5f000 12K ----- [ anon ]
0000000040d62000 1016K rwx-- [ anon ]
0000000040e60000 12K ----- [ anon ]
0000000040e63000 1016K rwx-- [ anon ]
0000000040f61000 12K ----- [ anon ]
0000000040f64000 1016K rwx-- [ anon ]
0000000041062000 12K ----- [ anon ]
0000000041065000 1016K rwx-- [ anon ]
0000000041163000 4K ----- [ anon ]
0000000041164000 1024K rwx-- [ anon ]
0000000041264000 12K ----- [ anon ]
0000000041267000 1016K rwx-- [ anon ]
0000000041365000 12K ----- [ anon ]
0000000041368000 1016K rwx-- [ anon ]
0000000041466000 12K ----- [ anon ]
0000000041469000 1016K rwx-- [ anon ]
0000002a95556000 4K rw--- [ anon ]
0000002a95566000 12K rw--- [ anon ]
0000002a95569000 6992K r-x-- /bb/util/jre1.5.0_11/lib/amd64/server/
0000002a95c3d000 1024K ----- /bb/util/jre1.5.0_11/lib/amd64/server/
0000002a95d3d000 1516K rw--- /bb/util/jre1.5.0_11/lib/amd64/server/
0000002a95eb8000 188K rw--- [ anon ]
0000002a95ee7000 4K r---- [ anon ]
0000002a95ee8000 4K rw--- [ anon ]
0000002a95ee9000 36K r-x-- /bb/util/jre1.5.0_11/lib/amd64/native_threads/
0000002a95ef2000 1020K ----- /bb/util/jre1.5.0_11/lib/amd64/native_threads/
0000002a95ff1000 16K rw--- /bb/util/jre1.5.0_11/lib/amd64/native_threads/
0000002a95ff5000 32K rw-s- /tmp/hsperfdata_op/19421
0000002a96004000 40K r-x-- /lib64/
0000002a9600e000 1024K ----- /lib64/
0000002a9610e000 4K r---- /lib64/
0000002a9610f000 4K rw--- /lib64/
0000002a96110000 52K r-x-- /bb/util/jre1.5.0_11/lib/amd64/
0000002a9611d000 1020K ----- /bb/util/jre1.5.0_11/lib/amd64/
0000002a9621c000 12K rw--- /bb/util/jre1.5.0_11/lib/amd64/
0000002a9621f000 148K r-x-- /bb/util/jre1.5.0_11/lib/amd64/
0000002a96244000 1020K ----- /bb/util/jre1.5.0_11/lib/amd64/
0000002a96343000 24K rw--- /bb/util/jre1.5.0_11/lib/amd64/
0000002a96349000 60K r-x-- /bb/util/jre1.5.0_11/lib/amd64/
0000002a96358000 1028K ----- /bb/util/jre1.5.0_11/lib/amd64/
0000002a96459000 16K rw--- /bb/util/jre1.5.0_11/lib/amd64/
0000002a9645d000 34920K r--s- /bb/util/jre1.5.0_11/lib/rt.jar
0000002a98677000 420K rw--- [ anon ]
0000002a986e0000 476K r--s- /bb/util/jre1.5.0_11/lib/jsse.jar
0000002a98757000 84K r--s- /bb/util/jre1.5.0_11/lib/jce.jar
0000002a9876c000 8520K r--s- /bb/util/jre1.5.0_11/lib/charsets.jar
0000002a98fbe000 2496K rwx-- [ anon ]
0000002a9922e000 46656K rwx-- [ anon ]
0000002a9bfbe000 40K rwx-- [ anon ]
0000002a9bfc8000 728K rwx-- [ anon ]
0000002a9c080000 21248K rwx-- [ anon ]
0000002a9d540000 64768K rwx-- [ anon ]
0000002aa1480000 21888K rwx-- [ anon ]
0000002aa29e0000 327680K rwx-- [ anon ]
0000002ab69e0000 10880K rwx-- [ anon ]
0000002ab7480000 163840K rwx-- [ anon ]
0000002ac1480000 44K rwx-- [ anon ]
0000002ac148b000 124K rwx-- [ anon ]
0000002ac14aa000 44K rwx-- [ anon ]
0000002ac14b5000 636K rwx-- [ anon ]
0000002ac1554000 24K rwx-- [ anon ]
0000002ac155a000 320K rwx-- [ anon ]
0000002ac15aa000 48K rwx-- [ anon ]
0000002ac15b6000 640K rwx-- [ anon ]
0000002ac1656000 44K rwx-- [ anon ]
0000002ac1661000 124K rwx-- [ anon ]
0000002ac1680000 1184K rw--- [ anon ]
0000002ac17a8000 47392K r---- /usr/lib/locale/locale-archive
0000002ac45f0000 1024K rw--- [ anon ]
0000002ac46f0000 156K r--s- /bb/util/jre1.5.0_11/lib/ext/sunjce_provider.jar
0000002ac4717000 784K r--s- /bb/util/jre1.5.0_11/lib/ext/localedata.jar
0000002ac47db000 8K r--s- /bb/util/jre1.5.0_11/lib/ext/dnsns.jar
0000002ac47dd000 4112K r--s- /bb/mtge/cdi/cmbs/runscript/web/runtime2/cmbs.jar
0000002ac4be1000 348K r--s- /bb/mtge/cdi/cmbs/runscript/web/runtime2/log4j-1.2.9.jar
0000002ac4c38000 1024K rw--- [ anon ]
0000002ac4e00000 1024K rw--- [ anon ]
0000002ac4f00000 76K r-x-- /bb/util/jre1.5.0_11/lib/amd64/
0000002ac4f13000 1028K ----- /bb/util/jre1.5.0_11/lib/amd64/
0000002ac5014000 12K rw--- /bb/util/jre1.5.0_11/lib/amd64/
0000002ac5100000 1020K rw--- [ anon ]
0000002ac51ff000 4K ----- [ anon ]
00000030e8400000 84K r-x-- /lib64/
00000030e8514000 4K r---- /lib64/
00000030e8515000 4K rw--- /lib64/
00000030e8600000 1200K r-x-- /lib64/tls/
00000030e872c000 1024K ----- /lib64/tls/
00000030e882c000 12K r---- /lib64/tls/
00000030e882f000 8K rw--- /lib64/tls/
00000030e8831000 16K rw--- [ anon ]
00000030e8900000 532K r-x-- /lib64/tls/
00000030e8985000 1020K ----- /lib64/tls/
00000030e8a84000 4K r---- /lib64/tls/
00000030e8a85000 4K rw--- /lib64/tls/
00000030e8b00000 8K r-x-- /lib64/
00000030e8b02000 1020K ----- /lib64/
00000030e8c01000 4K r---- /lib64/
00000030e8c02000 4K rw--- /lib64/
00000030e8f00000 64K r-x-- /lib64/tls/
00000030e8f10000 1020K ----- /lib64/tls/
00000030e900f000 4K r---- /lib64/tls/
00000030e9816000 8K rw--- [ anon ]
0000007fbfe00000 12K ----- [ anon ]
0000007fbfe03000 2036K rwx-- [ stack ]
ffffffffff600000 4K r-x-- [ anon ]
total 811312K
Peter Johnson

Joined: May 14, 2008
Posts: 5845

Please see this discussion:

JBoss In Action
Charles Lyons
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
When I run same program on 64 bit linux ,I noticed that this program consumes lot of memory. Even when i start this program on linux and there is no requests,program consumes lot of memory. The java process memory footprint is around 811MB (using pmap command or top -p).
Linux makes a large distinction between allocated memory and used memory. Newer kernels all support overcommit, so your programs can request an allocation summing to more RAM+Swap than is available in the system. That RAM is only actually accounted in the kernel as used once the program starts writing data to it. This sounds like madness, but in the case of Java especially is very useful... Java can allocate anywhere between 2 and 10 times more than it needs. As an example, the Caucho Resin Java EE server has two components: a watchdog manager and the server itself. On one of my systems, the latter has currently allocated 550MB and used ~212MB, while the former has currently allocated 170MB and used only ~32MB!

In general, you don't need to worry about allocated memory as it'll never be used by the application so you don't need to be concerned about memory shortage. The information reported by "free" and /proc/meminfo counts only used pages of memory. So one test is to stop your application (if you can, with minimal disruption to service) and note the difference before/after, then restart it and again notice the before/after difference. You may be surprised.

Secondly, when doing ps, use the format:and possibly change "comm" to "command" for fuller details. Note the numbers in the RSS column---this is closer to the used RAM (in kB) than VSIZE is. It's not perfect, but a good indication if the process isn't being swapped. The meanings are:
  • VSIZE = Virtual Image (kb): The total amount of virtual memory used by the task. It includes all code, data and shared libraries plus pages that have been swapped out. It also includes all allocated (but also unused) pages.
  • RES -- Resident size (kb): The non-swapped physical memory a task has used. This includes the amount of physical memory devoted to executable code, also known as the 'text resident set' size or TRS, and the amount of physical memory devoted to other than executable code, also known as the 'data resident set' size or DRS.
  • VIRT = RES + (Swapped) + (Allocated but unused).
  • Please do run the above "ps" and tell us what you get for VSIZE and RSS in each case... also if you can, stop/start and use "free" to determine how much memory the kernel has assigned to the application. Compare the two.
    [ October 29, 2008: Message edited by: Charles Lyons ]

    Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
    Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
    I agree. Here's the link:
    subject: java memory usage on linux