Java VM problem in OpenVZ

I bought a vps for hosting my java needs. But I can't run java on it. Everything about java is correctly installed but when I try to run java ("java -version" forexample) I get this error :

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

I don't think this is a java centered problem, Out of memory for sure. I contacted the vps admin, but he says everything is fine, you have 2gb ram, expandable to 4gb! I did a bit search on the subject, here is my BEANS file (numbers converted to humanredable form using a script). By the way do JVM heap memory allocs count on kmemsize or privvmpages ? How much ram does that configuration allows me to allocate with jvm for a single process?

resource                     held              maxheld              barrier                limit              failcnt
kmemsize                  2.25 mb              2.35 mb             13.71 mb             14.10 mb                    0
lockedpages                     0                    0           1024.00 kb           1024.00 kb                    0
privvmpages              20.54 mb             21.33 mb            256.00 mb            272.00 mb                  156
shmpages                  5.00 mb              5.00 mb             84.00 mb             84.00 mb                    0
numproc                        13                   14                  240                  240                    0
physpages                 9.36 mb              9.45 mb                    0            MAX_ULONG                    0
vmguarpages                     0                    0            132.00 mb            MAX_ULONG                    0
oomguarpages              9.36 mb              9.45 mb            MAX_ULONG            MAX_ULONG                    0
numtcpsock                      3                    3                  360                  360                    0
numflock                        3                    3                  188                  206                    0
numpty                          2                    2                   16                   16                    0
numsiginfo                      0                    1                  256                  256                    0
tcpsndbuf                69.17 kb             69.17 kb              1.64 mb              2.58 mb                    0
tcprcvbuf                48.00 kb             48.00 kb              1.64 mb              2.58 mb                    0
othersockbuf              6.80 kb              6.80 kb              1.07 mb              2.00 mb                    0
dgramrcvbuf               0.00 kb              0.00 kb            256.00 kb            256.00 kb                    0
numothersock                    9                   10                  360                  360                    0
dcachesize                0.00 kb              0.00 kb              3.25 mb              3.46 mb                    0
numfile                       704                  746                 9312                 9312                    0
numiptent                      10                   10                  128                  128                    0

Thanks in advance!


Solution 1:

Doublecheck if your script translated the raw beancounters correctly. according to this you only have 256 megs of RAM, not 4 gigs as your admin tells you.

concentrate only on 2 beans:

  • privvmpages - maximum amount of memory your container can allocate (reserve)
  • oomguarpages - guaranteed amount of memory your container will get to actually use. In case of tight memory situation on the host everything using over that amount will probably be killed.

Java is notorious for allocating gobs of memory and then never using them, counting on the OS to overcommit. In my experience you need at least a gig of privvmpages to run JVM reliably, although only couple of dozen megs will be used.

After couple of months experimenting and trying to contain privvmpages in VEs running Java, I have personally given up, I just set the barrier to the max and tweak the oomguarpages appropriately and hope for the best ;)

Solution 2:

I had a similar problem when I was hosted at VPSLink, the Sun/Oracle JVM just doesn't work with OpenVZ (you can search the old threads on the VPSLink forums to get more informations).

In the end, the only thing that worked for me on the OpenVZ container was the IBM JDK, which you can get at https://www.ibm.com/developerworks/java/jdk/linux/download.html

I think however that a better solution would be moving to a dedicated server where you can install the JDK you want and get much less headaches than with OpenVZ.

Solution 3:

You should try JRockit VM it is work perfect on my OpenVZ VPS, it consumes memory much less then Sun/Oracle jvm.