Hi, 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.
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 / AmazonAmazon UK )