Java "Could not reserve enough space for object heap" but lots of RAM free

11,329

Simple answer would be a problem with your limits.conf. Can you post the output of

ulimit -a -S
ulimit -a -H 

Ok, I went ahead and checked this. The problem is with the ''-v'' setting, with the virtual memory setting, not the ''-m'' one. This is on a Fedora 17 machine, but that should matter:

$ ulimit -S -v
unlimited
$ java -version
java version "1.7.0_09-icedtea"
OpenJDK Runtime Environment (fedora-2.3.3.fc17.1-x86_64)
OpenJDK 64-Bit Server VM (build 23.2-b09, mixed mode)

$ ulimit -v 1048576
$ java -version
Error occurred during initialization of VM
Could not reserve enough space for object heap
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Go fix! ;)

Share:
11,329

Related videos on Youtube

Bart van Heukelom
Author by

Bart van Heukelom

Professional software developer, online games, full stack but mostly backend. Electronics tinkerer. Maker. Freelance. See LinkedIn for more details. My UUID is 96940759-b98b-4673-b573-6aa6e38272c0

Updated on September 18, 2022

Comments

  • Bart van Heukelom
    Bart van Heukelom over 1 year

    I have a problem running Java applications on a server.

    root@dobby [/opt]# jdk1.7.0_09/jre/bin/java -version
    Error occurred during initialization of VM
    Could not reserve enough space for object heap
    Error: Could not create the Java Virtual Machine.
    Error: A fatal exception has occurred. Program will exit.
    

    ...but the free RAM is about 4GB (of which 3GB is used by the Linux cache). If I add Xmx to the command:

    root@dobby [/opt]# jdk1.7.0_09/jre/bin/java -Xmx100m -version
    #
    # There is insufficient memory for the Java Runtime Environment to continue.
    # pthread_getattr_np
    # An error report file with more information is saved as:
    # /opt/hs_err_pid32241.log
    

    What's up?

    Details:

    • 64-bit system
    • Linux 2.6.32
    • CentOS 6.2
    • Oracle JDK 1.7.0 update 9 (problem also occurred in an earlier version)

    Java error report: http://pastebin.com/uaxdSyh3

    ulimit:

    root@dobby [/home/bart]# ulimit -a -S
    core file size          (blocks, -c) 0
    data seg size           (kbytes, -d) unlimited
    scheduling priority             (-e) 0
    file size               (blocks, -f) unlimited
    pending signals                 (-i) 62763
    max locked memory       (kbytes, -l) 64
    max memory size         (kbytes, -m) 1048576
    open files                      (-n) 1024
    pipe size            (512 bytes, -p) 8
    POSIX message queues     (bytes, -q) 819200
    real-time priority              (-r) 0
    stack size              (kbytes, -s) 10240
    cpu time               (seconds, -t) unlimited
    max user processes              (-u) 1024
    virtual memory          (kbytes, -v) 1048576
    file locks                      (-x) unlimited
    
    
    root@dobby [/home/bart]# ulimit -a H
    core file size          (blocks, -c) 0
    data seg size           (kbytes, -d) unlimited
    scheduling priority             (-e) 0
    file size               (blocks, -f) unlimited
    pending signals                 (-i) 62763
    max locked memory       (kbytes, -l) 64
    max memory size         (kbytes, -m) 1048576
    open files                      (-n) 1024
    pipe size            (512 bytes, -p) 8
    POSIX message queues     (bytes, -q) 819200
    real-time priority              (-r) 0
    stack size              (kbytes, -s) 10240
    cpu time               (seconds, -t) unlimited
    max user processes              (-u) 1024
    virtual memory          (kbytes, -v) 1048576
    file locks                      (-x) unlimited
    
    • David Schwartz
      David Schwartz over 11 years
      These errors are about the ability to reserve virtual memory. How much physical memory you have or how much of it is available is irrelevant.
    • Govindarajulu
      Govindarajulu over 11 years
      @DavidSchwartz, could be. I can run ''java -version'' on machines with a lot less memory than this though and Linux can overcommit memory pretty well with the default settings. I could be a non-default memory overcommit setting though, I can give you that ;) AFAIK, that could hinder virtual memory reservavtion.
    • 9997
      9997 over 11 years
      This line is your culprit: max memory size (kbytes, -m) 1048576. It is limiting the heap to 1GB maximum. I think the virtual memory one too.
    • Bart van Heukelom
      Bart van Heukelom over 11 years
      @MirceaChirea 1GB may not be an incredible amount for a real application, but shouldn't it be more than enough for java -Xmx100m -version? After all, that shouldn't require more than 100MB, ever.
    • Bart van Heukelom
      Bart van Heukelom over 11 years
      Added a detailed error report
    • David Schwartz
      David Schwartz over 11 years
      @BartvanHeukelom: No, it shouldn't. 1GB is a ridiculously small virtual memory limit on a 64-bit OS. One of the great things about 64-bit operating systems is that they can create nearly unlimited amounts of virtual memory at near zero cost. To impose such a draconian limit is just plain silly. The heap is just one way processes use virtual memory.
    • Bart van Heukelom
      Bart van Heukelom over 11 years
      @DavidSchwartz Well it worked before. I suppose the limit was lowered, though I don't know how or when (I'm not the only server admin). I'll try changing it.
    • Bart van Heukelom
      Bart van Heukelom over 11 years
      @DavidSchwartz Yes, setting it to unlimited fixes my problem. Now to finding out why it isn't set to that.
    • Bart van Heukelom
      Bart van Heukelom over 11 years
      Well, it's not set in limits.conf or limits.d.
    • Bart van Heukelom
      Bart van Heukelom over 11 years
  • Bart van Heukelom
    Bart van Heukelom over 11 years
    Appended to question.