How to get max Java VM higher than 2GB on ubuntu? - java

My virtual memory won't go higher than 2GB when I has 8GB available.
I'm running Ubuntu 10.10 x86 with Java JRE 1.6_25 installed.
When I try to launch the .jar file, it just an instantly crash.
It works just fine when I set the VM to 2048M
These are the arguments I use to define the VM -Xmx4096M -Xms4096M
Thankful for any help :)

If that's a 32bit VM, you won't go higher than 2G (or close to 3G with a kernel configured for 3G/1G userspace/kernel address space split). There is no way to have a 32bit process use more than 2G (or 3G with the right settings) of real memory.
You'll need a 64bit kernel and JVM to reach 4G of heap space (and go much beyond that).
See this question for good info about memory limits on Linux for 32bit applications: Memory limit to a 32-bit process running on a 64-bit Linux OS.
(The accepted answer talks both about 32bit and 64bit kernels. It also suggests that there were some patches where you could nearly reach 4G for userspace on a 32bit kernel, but I don't think those kind of things ever went into Ubuntu kernels - kind of a nich server thing.).

You should strongly consider migrating to a 64 bit operating system if you need that large a Java program. This will allow you to use a 64-bit JVM which allows for larger-than-2Gb Java programs.
I am not aware of a procedure to easily migrate from 32-bit to a 64-bit Ubuntu, but you can save your home directory and then reinstall.
You can then easily install the OpenJDK Java and with a bit more effort the official Sun JDK.

Related

"Could not create the Java Virtual Machine" when increasing the -Xmx

The eclipse on my work computer was working with VM argument -Xms40m and -Xmx512m and it is really slow and freezes a lot, I wanted to increase it to -Xmx1024m, but every time I did so I got the error "Could not create the Java Virtual Machine".
The computer has 3.5GB RAM, WIN XP (32-bit), Java 1.6_18
What could be the reason? Is it related to other arguments?
UPDATE:
I changed the -vm argument so it will use the jvm.dll that comes with the jrockit JDK and I was able to increase the max heap size to 1024m.
Also, on my home computer (WIN 7, 32-bit, 2GB RAM, java 1.7.0_21-b11), I was able to increase it 1024m as well.
The maximum amount of memory available on Windows 32-bit processes is (generally speaking) 2GB. That includes everything for your JVM, not only the application heap. People report various numbers for the maximum heap that can use for a 32-bit JVM, but 1200m is a common figure. It seems to be lower for you. Best would be to switch to the 64-bit JVM, if you can.
Other questions:
How much memory can a 32 bit process access on a 64 bit operating system?
Java maximum memory on Windows XP

multiple java instances -Xms -Xmx

I am running at the same computer a java game-server and a game-client
the game-client with
java -Xms512m -Xmx1024m -cp etc etc
and the game-server
java -Xmx1024M -Xms1024M -jar etc etc
Computer Properties:
Windows 7 64 bit
8GB RAM
CPU i5-2500 # 3.3GHz
Intel HD Graphics
Problem: The game-client experience serious lags. At the game-server is also connected via LAN another player with no lag issues!
Has the problem of the lag to do anything with java virtual machine? Am I using one instance of machine or two?
Can I setup something different in order to optimize the performance?
I am thinking that the problem has to do with the fact that one machine is running and its max memory is not enough for both instances, but I do not really know how to solve that.
Edit: No app run out of memory.
Solution:
1:
Updated Java version from:
java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b05)
Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01, mixed mode)
to
java version "1.7.0_15"
Java(TM) SE Runtime Environment (build 1.7.0_15-b03)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)
2:
Changed the server properties in order to minimize requirements, this seems to be the main reason.
3:
Increased memory:
game-client with java -Xms1024m -Xmx1024m -cp etc etc
and the game-server java -Xmx2048M -Xms2048M -jar etc etc
Server runs at about 700MB now.
Has the problem of the lag to do anything with java virtual machine?
Possibly. You haven't presented enough evidence to be sure one way or the other.
The puzzling thing is that the your client running on a different machine is not laggy.
Am I using one instance of machine or two?
You are running two copies of java then you will have two JVMs.
Can I setup something different in order to optimize the performance?
The answer is probably yes. But you haven't provided enough information to allow us to make solid suggestions.
Lagginess can be caused by a number of things, including:
A network with high latency.
A JVM that has a heap that is too small.
An application that is generating lots of garbage and triggering an excessive number of garbage collection.
A mix of applications that is competing for resources; e.g. physical memory, CPU time or disc or network I/O time.
If you are going to get to the root cause of your problem, you will need to do some monitoring to figure out which of the above is the likely problem. Use the task manager or whatever to check whether the system is CPU bound, short of memory, doing lots of disk or network stuff, etc. Use VisualVM to see what is going on inside the JVMs.
Alternatively, you could try to fix with some totally unscientific "knob twiddling":
try making the -Xms and -Xmx parameters the same (that may reduce lagginess at the start ...)
try increasing the sizes of the JVMs' heaps; e.g. make them 2gb instead of 1gb
try using a more recent version of Java
try using a 64 bit JVM so that you can increase the heap size further
try enabling the CMS or G1 collectors (depending on what version of JVM you are using).
If I knew more about what you were currently using, I could possibly give more concrete suggestions ...
You are using two java apps in same computer, resulting in 2 JVMs running.
For a 64 bit system with 8GB RAM, its recommended to use max 2GB(25% of Physical memory OR 75% of free physical memory up to 2 GB) for JVM for better performance.
You may have to look on JVM size adjustment. For better performance, Xms and Xmx size can be kept same with a max size bracket.
Assigning memory size to Heap is not the only area to think of. JVM uses more memory than just Heap. Others memory areas like Thread Stack, Method areas, Class Loader Subsystem, Native Method Stack etc.
While both of the apps(game-server, game-client) are running, there is a chance of issue in memory management by OS between both apps, resulting in slowness.
In that case, client app can be deployed in another core, if available.

Cant give JVM 3072m heap space on 32bit machine

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)
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.
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.
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.
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

more memory allocation in java program

I use ubuntu 10.04 LTS 64bit and my system has 4 GB RAM.
I run a java program that need more than 1.1GB memory but the operating system does not allow my program to get more than 1.1GB while only 2.1GB of RAM is used and 1.9GB are free, what is the problem? (This problem is not just for this program, I run another program and has same problem.)
what should I do?
Looks like you are running a java application. Make sure to
Run a 64 bit JVM, if you need more than about 4GB memory. For this to work, you shold have a 64 bit OS
Increase the max heap size by the JVM switch
-Xms <initial size> -Xmx <max size>
Sounds like you programs are compiled as 32bit programs despite that you are running on a 64bit configuration.

32-bit or 64-bit application on 64-bit OS?

We are developing a swing application written by Java which requires only about 128MB memory, and in the short future I don't see it will require much more memory like 4GB. Previously we provide always 3 different releases, one for 32-bit Windows, one for 32-bit Linux and another for 64-bit Linux, with an installer which has JRE included.
The 64-bit version was not used by anyone until couple of weeks ago, and an OutOfMemoryException was reported because the application consumes about 40-50% more memory than the 32-bit version.
My question is, is it needed at all for us to provide the 64-bit version for 64-bit Linux if the application will never need to use more than 4GB memory? We had some quick test which revealed that 32-bit version works also on 64-bit Linux. But I'm not sure what could be the cons we would have, e.g. performance and/or compatibility issue?
If your application provides no improvements for 64-bit host operating systems and is compatible with your 32-bit releases then I see no immediate need to provide it.
However, most, if not all new system are based on x64 architecture where I advocate that also 64-bit software should be the natural default. This needs grows stronger the closer you get to hardware level. I can't tell you how awkard it is to run a virtual operating just to support some 32-bit VPN client.
Promoting the 64-bit client would probably impact your download statistics if you would decide to make it the preferred choice.
check this 64 bit java
Most 32-bit JVMs are limited to around 1.2-1.5 GB.
If you find your application uses much more memory with 64-bit JVM, try the -XX:+UseCompressedOops which tells the 64-bit JVM to use 32-bit references but can still access 32 GB of memory.
My question is, is it needed at all for us to provide the 64-bit version for 64-bit Linux if the application will never need to use more than 4GB memory?
If the application won't ever need that much memory, 64 bit installer / JVM adds no value. On the contrary, it is a poor option because (as you observed) it simply uses more memory and (probably) runs slower as a result.
(Actually, the actual limit will be less than 4GB. Some parts of the 32-bit address space will be unusable, because of hardware architecture issues.)
I suggest you withdraw the 64 bit version, but provide the user with the ability of using a JVM that they have downloaded and installed separately. (Indeed, you should probably do the latter anyway. Embedded copies of the JRE tend to get overlooked when people upgrade to get the latest JVM security fixes ...)
UPDATE (2019) - Java 8 is the last version of Java which Oracle provides for 32 bit platforms. As of Java 11 (the current LTS version), the Oracle-badged distributions for Linux, MacOS, SunOS / SPARC and Windows are 64 bit only.
My advice now would be to migrate your product offerings away from 32 bit as soon as you can. You don't want to be stuck trying to support a product on an EOL'd version of Java.
Granted, 32-bit Java 11 is available from Azul, according to this Q&A. (I noted 32 bit "Zulu" releases of Java 11 for Linux, but not for Windows or MacOS. YMMV.)

Categories

Resources