Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm doing Memory management analysis for my Java web application,

Before starting my tomcat the free memory was around 595 MB, Once I started the server the free memory goes to 151 MB. When I took the Heap dump, the objects were occupying 262 MB.

So will tomcat alone take remaining 181 MB?

Another question is, I ran Load Test with 500 Users. The free memory goes to 8MB, When I took heap dump here, It was around 265MB. So free space 151 MB is reduced to 8MB, What could be reason

share|improve this question
    
What else is running on that machine? –  Massimo Feb 28 '12 at 11:16
    
No other processes, This is dedicated to my application –  Selvakumar P Feb 28 '12 at 11:34
1  
where do you get your values for "free memory"? i suggest reading through linuxatemyram.com –  Niko S P Feb 28 '12 at 12:16
    
I took it using top command –  Selvakumar P Feb 28 '12 at 13:05
add comment

3 Answers 3

up vote 1 down vote accepted

Firstly, read and understand http://www.linuxatemyram.com/ for why "free" memory numbers are much lower than you might think.

Secondly, Java allocates its entire heap upfront from the operating system, although it doesn't touch or dirty the pages until they're actually used. This gives you top output like:

 PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND         
9521 pjc       17   0 1288m 524m  25m S  0.0 13.3  58:31.92 java

That's me running Eclipse; the VIRT column shows that Java probably has a 1024Mb maximum heap size; on top of that are libraries and memory allocated for storing the compiled Java. However only 524Mb of that is currently in RAM.

Your heap dump is the best guide to how much memory your application is using - provided that's after it's done a garbage collection.

share|improve this answer
add comment

The operating system is smart, not stupid. It understands that free memory is wasted memory, no better than memory that isn't in the system at all. It's not like if your 4GB machine uses only 3GB today, you can use 5GB tomorrow.

So it keeps stuff that it might be able to use in RAM. If it later is able to use it, that's a performance win. Amazingly, if it later isn't able to use it, it's still a performance win because if it had made it free, it would just have to make it in use again. (That would require two operations, whereas switching it directly from one use to another is just one operation.)

Modern operating systems only make a small amount of memory free and only when they have no choice.

share|improve this answer
add comment

Use psi-probe to actually see what goes on in the JVM. Or VisualVM, but psi-probe is more accessible.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.