1

Short description of a problem: Operation system (Windows 7 x64) failed to create JVM while another C++ program has already fragmented the memory.

Details of the problem: I have a workstation with 8 or 16 GB RAM. When I start my JVM program (which requires up to 2 GB RAM) it works fine. It works fine because JVM can allocate a big continuous piece of memory. But if I try to start C++ program (and I can say the program uses new and delete operations VERY often) JVM won’t start despite large amount of free memory. The obvious solution is to start the JVM program first. Problems will start if the JVM program crashes. In such case I have to either start the JVM program (while OS have a big continuous piece of memory) or restart the C++ program.

Question: Can I somehow reserve memory of operation system exactly for JVM (in spite of potential crashes)? And can I keep the memory while OS runs?

Curiosity
  • 651
  • 1
  • 5
  • 12
  • Please mention the operating system, and whether it is 32 or 64-bit. – PaulMcKenzie Dec 13 '14 at 09:17
  • The easiest would be to use VirtualAlloc with MEM_RESERVE. With this you can reserve a block of memory for later use. – mkaes Dec 13 '14 at 09:46
  • 2
    Fragmentation: what makes you think this. I do not believe that the OS needs contiguous RAM pages. Virtual memory does not work like that. – Raedwald Dec 13 '14 at 09:59
  • It is not possible, in any OS I'm aware of, to "reserve" memory in one application, to be used by another application. I also agree with Raedwald - it's unlikely your problem is ACTUALLY caused by fragmentation - more likely is that the OS simply says "no, I can't give you enough memory". Possibly, if the JVM is using something like "allocate in huge pages", it could fail due to fragmentation, but I doubt that's the reason - all OS's that I know how their memory allocation works will fall back to allocating 4KB pages if huge pages can't be done. – Mats Petersson Dec 13 '14 at 10:12
  • The problem is the same (I mean the error code) as in the case http://stackoverflow.com/questions/7302604/eclipse-error-failed-to-create-the-java-virtual-machine . And I saw a lot of memory was free. As I understand the system just hasn't 2 Gb in a one piece. – Curiosity Dec 13 '14 at 10:41
  • It doesn't *need* a contiguous 2GB. A process's virtual address space is defined by a lookup table that maps the contiguous *virtual* pages to *physical* pages that can be scattered anywhere in RAM. Page size is typically 4k, but can be 4M if the process is using "huge pages" (on x86). So all system really needs is enough 4k or 4M chunks, located anywhere in RAM, to make up 2GB in total. It's very unlikely that your problem is caused by physical RAM fragmentation. – Wyzard Dec 13 '14 at 15:20

0 Answers0