Exact state of committed memory in java
Asked Answered
D

2

14

Im curious what the exact meaning of "committed" memory is when the value is queried from the MemoryUsage class. That class explains it as "committed represents the amount of memory (in bytes) that is guaranteed to be available for use by the Java virtual machine." Does this mean that the memory is in use by the jvm process and NOT available to other processes until it is released by the java process, or does it mean that the java process will be successful if it tries to allocate up to that amount of memory? I realize this might be implementation specific but i am only interested in hotspot.

Decolorize answered 15/10, 2008 at 22:59 Comment(0)
S
24

The committed size is the actually allocated memory, the used size is the size used for storing actual data (when used ~= committed it's time for major GC and possibly growing the heap). The Max size is the hard limit to which the heap can grow - if it's not enough the JVM throws OutOfMemoryError.

If a memory is committed then it definitely can be used. Also, the only occasion when JVM would not be able to commit more memory (on a modern OS) is if the hardware is out of virtual memory.

All these sizes only tell you the size of the heap region. The JVM has other memory regions as well (thread stacks, JIT cache, etc.) The heap region is usually largest, this roughly corresponds to the process footprint.

Two notes:

  • if the committed size does not fit in the physical memory, parts of it will be swapped to the page file. This leads to big slowdown during GC and in such cases you will improve the app performance by reducing the heap size.
  • some operating systems allow double booking of memory - you can allocate as much as you want as long as you don't try to use it (forgot which OS it was - somebody fill me in)
Sufferable answered 15/10, 2008 at 22:59 Comment(2)
At least Linux can do this double-booking; it's called "overcommit". opsmonkey.blogspot.com/2007/01/linux-memory-overcommit.htmlWiredraw
"The committed size is the actually allocated memory, the used size is the size used for storing actual data (when used ~= committed it's time for major GC and possibly growing the heap). The Max size is the hard limit to which the heap can grow - if it's not enough the JVM throws OutOfMemoryError." for me this means that sometime (it depens on max value of heap, -Xmx) you will get OutOfMemoryError?Suppurate
F
2

"Does this mean that the memory is in use by the jvm process and NOT available to other processes" would be the correct one. So its less then (or equal to) the amount of memory the OS sees as taken by the JVM process.

http://java.sun.com/j2se/1.5.0/docs/guide/management/jconsole.html (sorry no anchors to link to).

Funda answered 15/10, 2008 at 23:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.