-2

Sorry for asking the question, should have searched a bit more.

Im running weka with a rather large dataset and a memory intesive algoithm. I need all the heap space I cant get!

This works:

java -jar -Xmx2048m weka.jar &

But this does not

java -jar -Xmx4096m weka.jar &

I get:

Error occurred during initialization of VM Could not reserve enough 
space for object heap Could not create the Java virtual machine.

By some quick searching I found that this is the upper limit

java -jar -Xmx2594m weka.jar &

I have 4GB ram but a 32 bit machine. Why can't I use 2^32 bytes = 4096MB of memory?

For the future I am wondering if I can run java with e.g. hundreds of GB of heap space if I have the correct hardware and OS?

I have both 1.6 and 1.7 JVM installed:

$java -showversion
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.4) (6b24-1.11.4-1ubuntu0.12.04.1)
OpenJDK Server VM (build 20.0-b12, mixed mode)
user1443778
  • 581
  • 1
  • 5
  • 20

4 Answers4

2

Use the 64-bit version of Java which allows you to use more memory. This is the limit of the 32-bit Java virtual machine.

icza
  • 389,944
  • 63
  • 907
  • 827
2

I have 4GB ram but a 32 bit machine. Why can't I use 2^32 bytes = 4096MB of memory? For the future I am wondering if I can run java with e.g. hundreds of GB of heap space if I have the correct hardware and OS?

For 4 GB I suggest you use a 64-bit OS and possibly a 64-bit JVM as the limit for the heap size can be as small as 1.2 GB (on Windows XP)

If you want larger JVMs I suggest making sure you have 64-bit OS and JVM and you have more memory than the size of the JVM. e.g. if you want a 40 GB heap you need something like 48 GB or 64 GB of memory.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • Any info why the heap size is smaller than 2<<32 B? E.g. 1.2 GB? – user1443778 Oct 05 '12 at 09:23
  • 3
    The heap has to be a continuous memory region. In 32-bit Windows it uses 2 GB of the OS and a number of memory regions for shared resources which fragment the memory. For different versions of 32-bit windows, this means the limit is between 1.2 GB and 1.6 GB. BTW Windows XP can't even use a full 4 GB, it reports 3.5 GB on such a system. – Peter Lawrey Oct 05 '12 at 09:26
2

If you have 4GB of RAM how can you expect that all will be available to your JVM? What about the OS the JVM is running in, this will also require memory. The way it works is that even though you can address all 4GB generally an OS will limit the amount available per process.

ramsinb
  • 1,985
  • 12
  • 17
  • 1
    @user1443778 JVM + swap = _really_ bad idea, as the JVM manages the objects on the heap, moving them during GC. So the JVM often walks all the memory pages, and if some of them are swapped it's a real performance killer. – Frank Pavageau Oct 05 '12 at 09:30
  • @FrankPavageau I was hoping for a quick fix (quicker than installing a new OS etc) so running it over night would be OK. But If the JVM has to do that then I understand why it is a bad idea. – user1443778 Oct 05 '12 at 09:33
  • You can try it and see what happens when GC occurs... Basically if your application can't run on the physical memory allocated (and if there is not enough physically memory available) then change your code to cope or upgrade the OS to 64bit and use a lot of memory without swapping. – ramsinb Oct 05 '12 at 09:33
0

You are not able to have an allocation of 4096m because. It tries to get a single block of 4096m. Which is not possible at any given point of time. So you can use some smaller values between 3000-4000. or make sure your RAM is not used by any of the processes

ankit
  • 4,919
  • 7
  • 38
  • 63