aspose file tools*
The moose likes Performance and the fly likes Understanding memory usage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Understanding memory usage" Watch "Understanding memory usage" New topic
Author

Understanding memory usage

Sk Bali
Greenhorn

Joined: Dec 26, 2009
Posts: 2
Running JBoss 5.1.0GA on 2.6.18-164.el5 with Sun JDK 1.6.0_16

Xms=Xmx=1536m
XX:newSize=XX:MaxNewSize=400m
XX:MaxPermSize=304m

I was expecting this to remain well within 2.5GB, however when I run top I see RES=4GB. I don't get any OutOfMemory errors and the VM does not show any leaks. The app is simple jsp, No EJBs, No db access.

cat /proc/<pid>/status shows
VmPeak: 5323840 kB
VmSize: 5194912 kB
VmLck: 0 kB
VmHWM: 4159884 kB
VmRSS: 4159884 kB
VmData: 5094360 kB
VmStk: 84 kB
VmExe: 36 kB
VmLib: 68980 kB
VmPTE: 9128 kB

Why is so much memory being help by the process?

Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5843
    
    7

Sk, welcome to Java Ranch.

I assume that you used an operating system utility to determine memory usage for the java process. Well, for a java process the memory usage is a combination of:

  • the java heap (which you set to 1.5G)
  • the permgen, which holds class-level info (add another 304MB)
  • the thread stack - each thread uses up from 512KB to 2MB of space depending on the OS, and an application server runs a large number of threads
  • the C/C++ data structures used by the JVM
  • the code for the JVM, including the executable itself and any libraries (.so, .dll) used by it


  • I probably forgot something. But when you add all that up, it could be 4GB.


    JBoss In Action
    Sk Bali
    Greenhorn

    Joined: Dec 26, 2009
    Posts: 2
    Peter Johnson wrote:Sk, welcome to Java Ranch.

    I assume that you used an operating system utility to determine memory usage for the java process. Well, for a java process the memory usage is a combination of:

  • the java heap (which you set to 1.5G)
  • the permgen, which holds class-level info (add another 304MB)
  • the thread stack - each thread uses up from 512KB to 2MB of space depending on the OS, and an application server runs a large number of threads
  • the C/C++ data structures used by the JVM
  • the code for the JVM, including the executable itself and any libraries (.so, .dll) used by it


  • I probably forgot something. But when you add all that up, it could be 4GB.


    Thanks Peter.

    So 1536m + 304m + 237 threads at -Xss256k is still less than 2 GB.
    That would mean that 2GB of memory is being used by the C/C++ data structures and code for JVM. That is more than even my full heap. I find that very strange.

    A similar process that I manage on Solaris 10 with similar settings and more threads does not go beyound 2.3 GB.

    Thanks for the quick response.

    Regards,
    Bali
    Peter Johnson
    author
    Bartender

    Joined: May 14, 2008
    Posts: 5843
        
        7

    This discussion might also help:
    http://www.coderanch.com/t/111262/Linux-UNIX/read-memory-usage-process-running

    Also, I think your question is more along the lines of "how does Linux calculate the amount of memory used by a process?" In which case this might help:
    http://virtualthreads.blogspot.com/2006/02/understanding-memory-usage-on-linux.html
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: Understanding memory usage