JDK Memory Allocation
I set -xmx1024M but "top" shows something different.
There is more to java than the object heap.
the native binary image of "java" and any dlls it loads
the native "c" heap
stack memory for threads
jvm specific areas that are not part of the object heap (e.g. the permenant generation for Sun's hotspot)
memory used for JIT compiled code
Finally the java heap that stores java objects
If you are not seeing it allocate all the memory immediately on Linux this is probably due to something
+By default, Linux follows an optimistic memory allocation strategy. This means that when malloc() returns non-NULL there is no guarantee that the memory really is available. This is a really bad bug. In case it turns out that the system is out of memory, one or more processes will be killed by the infamous OOM killer. In case Linux is employed under circumstances where it would be less desirable to suddenly lose some randomly picked processes, and moreover the kernel version is sufficiently recent, one can switch off this overcommitting behavior using a command like
echo 2 > /proc/sys/vm/overcommit_memory See also the kernel Documentation directory.
The Linux kernel supports three overcommit handling modes
0 - Heuristic overcommit handling. Obvious overcommits of address space are refused. Used for a typical system. It ensures a seriously wild allocation fails while allowing overcommit to reduce swap usage. root is allowed to allocate slighly more memory in this mode. This is the default.
1 - No overcommit handling. Appropriate for some scientific applications.
2 - (NEW) strict overcommit. The total address space commit for the system is not permitted to exceed swap + a configurable percentage (default is 50) of physical RAM. Depending on the percentage you use, in most situations this means a process will not be killed while accessing pages but will receive errors on memory allocation as appropriate.+