On 19 October 2010 22:46, Mike Hopper <[email protected]> wrote:

> I've been doing Java development for many years but sometimes
> something surprises me. A coworker was explaining to me that many JVMs
> allocate all of the memory specified by the -Xmx parameter at
> application startup time. He said that this was an optimization
> feature and that the JVM needs to ensure that it gets a contiguous
> address space for its heap at startup. Some google searches confirmed
> that this is the case for the IBM JVM.
>
> One reason this discussion came up is because we could not start a web
> app with -Xmx=1gb (even though 2gb were free) because (according to
> his explanation) the OS could not find 1gb of contiguous memory. He
> resolved the issue by rebooting the machine (thus defragging the
> physical memory).
>
> Anyone here familiar with this. It seemed strange to me because (a)
> why have both Xms and Xmx settings if the JVM is just going to grab
> all the memory it will ever need at startup? (b) Eclipse, which is a
> Java app, seems to grow and shrink its memory footprint throughout the
> day (at least on Windows). Perhaps different JVMs have different
> strategies for grabbing memory from OS.
>

IIRC the JVM uses mmap to check the OS has enough contiguous address space
for -Xmx,
but it uses the MAP_NORESERVE flag which means the OS won't actually
allocate system
resources to the process until pages are actually used (which is where -Xms
comes in)

[ I haven't delved into JVM code for a while, so this might not be accurate
or up-to-date!
  Memory allocation code also varies from OS to OS, but the general idea is
the same ]


> Any insight would be appreciated.
>
> Mike
>
> --
> You received this message because you are subscribed to the Google Groups
> "The Java Posse" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<javaposse%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/javaposse?hl=en.
>

-- 
Cheers, Stuart

-- 
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

Reply via email to