Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.
[root@lab ~]# java
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.

Any idea how to fix this?

[root@lab ~]# uname -a
Linux lab 2.6.18-194.8.1.el5.028stab070.5 #1 SMP Fri Sep 17 19:10:36 MSD 2010 x86_64 x86_64 x86_64 GNU/Linux

Here are some additional details that are probably pretty important, its an openvz vps

[root@lab /]# free -m
             total       used       free     shared    buffers     cached
Mem:           384         27        356          0          0          0
-/+ buffers/cache:         27        356
Swap:            0          0          0

I can get it to load the jvm if I set the max memory to 100 or less, but I should have more than 300mb available shouldn't I?:

[root@thehacklab /]# java -Xms32M -Xmx100M -version
java version "1.6.0_0"
OpenJDK Runtime Environment (IcedTea6 1.6) (rhel-1.13.b16.el5-x86_64)
OpenJDK 64-Bit Server VM (build 14.0-b16, mixed mode)
[root@thehacklab /]# java -Xms32M -Xmx128M -version
Error occurred during initialization of VM
java.lang.OutOfMemoryError: unable to create new native thread
        at java.lang.Thread.start0(Native Method)
        at java.lang.Thread.start(Thread.java:614)
        at java.lang.ref.Finalizer.<clinit>(Finalizer.java:194)

[root@thehacklab /]# java -Xms32M -Xmx140M -version
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.

Also, I noticed provvmpages failcounter increments everytime I run java so this is probably hwhere its hitting a limit:

[root@thehacklab /]# cat /proc/user_beancounters
Version: 2.5
       uid  resource                     held              maxheld              barrier                limit              failcnt
    10913:  kmemsize                  4349290              6173197           2147483646           2147483646                    0
            lockedpages                     0                    0               999999               999999                    0
            privvmpages                  7198                98262                98304                98304                   35
            shmpages                      671                 1647                98304                98304                    0
            dummy                           0                    0                    0                    0                    0
            numproc                        16                   33               999999               999999                    0
            physpages                    4411                43452                    0           2147483647                    0
            vmguarpages                     0                    0                98304           2147483647                    0
            oomguarpages                 4412                43453                98304           2147483647                    0
            numtcpsock                      5                   31              7999992              7999992                    0
            numflock                        5                    9               999999               999999                    0
            numpty                          1                    2               500000               500000                    0
            numsiginfo                      0                    4               999999               999999                    0
            tcpsndbuf                  107352               216752            214748160            396774400                    0
            tcprcvbuf                   81920             13351808            214748160            396774400                    0
            othersockbuf                 6984                44232            214748160            396774400                    0
            dgramrcvbuf                     0                 8472            214748160            396774400                    0
            numothersock                   10                   27              7999992              7999992                    0
            dcachesize                      0                    0           2147483646           2147483646                    0
            numfile                       674                 1154             23999976             23999976                    0
            dummy                           0                    0                    0                    0                    0
            dummy                           0                    0                    0                    0                    0
            dummy                           0                    0                    0                    0                    0
            numiptent                      14                   14               999999               999999                    0
share|improve this question
    
How much ram is left? Try free –  TheLQ Oct 5 '10 at 2:05
    
I updated with more info –  tehryan Oct 5 '10 at 3:12

2 Answers 2

The java program itself will consume some memory. And more importantly, you forgot to count the "PermGen". I don't know what is the default perm gen size, but it could be 128M or even 256M. The total heap size required by JVM is PermGen + Heap size.

Why don't you just add some swap?

Also there should be a parameter to allow Linux to overcommit memory...google may help.

share|improve this answer

With 132M free on my VPS, the largest maximum heap size I can specify is 22M. Between 22M and 30M, various things run out of memory (like pthreads), and after 32M, I get the "Could not reserve enough space for object heap" error. I also played around with various -Xmn values, but it doesn't seem to have any affect on the outcome.

I used sun-java6-jre debian package for these tests.

Can you try to run with "java -client -Xmx...", and see if you can use higher memory sizes? With my VM, java -server doesn't run at all.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.