I've seen many people on the web claiming that "the JVM requests a contiguous unfragmented block of memory from the OS when it starts". What I can't understand is how this correlates with the notion of virtual memory.
OS might swap out any process's memory pages to disk, then load them again into RAM - chances are they will be loaded into different locations, so physical memory used by the process will no longer be contiguous.
As for the process's virtual memory - that will always be "contiguous" from the process's point of view, as each process has its own address space.
Thus, what I'd like to understand is:
- Is the statement that memory allocated by OS to a JVM has to be
contiguous really true? - If so, how does OS ensure memory stays contiguous considering it might be swapped out to disk and swapped in back to RAM?
- If the statement it not true, what might be the reasons why OS
would deny the process the virtual memory it asks for? Memory
overcommitting settings?