Reputation: 5534
I'm trying to allocate a large matrix (around 10GB). I'm working on 64 bit machine with a 64 bit JVM. My process then should have 2^64
bytes available and I've set the JVM heap size to be 128G (I have 16GB of RAM in my machine if that matters). My understanding was that I should get the memory from the OS and that unneeded matrix cells would be swapped out by the OS. However I'm getting the above exception.
Edit:
This is how I'm defining the matrix:
Jama.Matrix A = new Matrix(num_words, num_documents);
Where num_words
is approximately 100k and num_documents
is approximately 35k.
Also worth mentioning that the type is double
Edit2:
Relevant flags:
-Xms40m
-Xmx128g
-d64
Upvotes: 6
Views: 343
Reputation: 533442
A few things you should know.
-d64
only works on Solaris.In short you need about 256 GB of main memory and a large heap you really consider what you are doing. Accessing memory randomly is up to one million times faster than accessing disk space and this means not only is it one million times slower, but it is unlikely to work at all.
What you can do is use off heap memory, and if you really know what you are doing, you can make this work and be perhaps only 100x slower than having the memory you need. esp if you use a fast SSD for swap or your matrix is sparse is just the right ways.
Upvotes: 1
Reputation: 7697
JVM works as native process, in this respect: JVM requests memory from OS that can allocate it either in RAM in swap.
The memory you can allocate in java does not depend on your RAM but on command line option -Xmx
you specify when you are running your JVM. If it is not enough memory in RAM JVM receives it from swap and (I believe) even does not know about that.
However,
If you need to work with large data you need to work with BigMemory products (EhCache or Terracotta).
Finally, run jvisualvm or with the -verbose:gc
prameter to see the heap allocation.
Upvotes: 2
Reputation: 8657
Here some description:
Xms -> the init memory that should be allocated in the start up in MB.
Xmx -> the Max amount of memory that your application can get in MB e.g Xmx2048m.
-XX:MaxNewSize= -> the max S1 and S2 memory size
-XX:NewSize= -> init S1 and S2 size
so in your case if you want to allocate memory as much as you can, so you need to say for example 16 * 1024 = 16384 or 16g
and the -XX:MaxNewSize= and -XX:NewSize=
set it by 40% of your Xmx
Upvotes: 1