4

seems like i am stuck with allocating memory to my java vm on a linux server.

I am using this command to test:

java -Xmx9g -Xms6g -d64 -server

memory on the server:

    [root@….~]$ free -m
             total       used       free     shared    buffers     cached
Mem:         16017       1058      14958          1         41        758
-/+ buffers/cache:        259      15758
Swap:         1498          0       1498

Ulimit settings:

core file size          (blocks, -c) 1
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 128053
max locked memory       (kbytes, -l) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) 64000
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 128053
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

Linux version is SUSE Linux Enterprise Server 11 (x86_64).

Java version:

java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)

I found out that it actually still works with -Xmx8330m, but no longer with -Xmx8331m. I do not have any idea what happens here and why i am capped at this specific memory allocation?

Edit: The exact error message is this:

root@…..:/root> java -d64 -Xmx9g -server
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.

Thanks! Indy

Indygoof
  • 51
  • 6
  • You have plenty of free memory so this should work. I would use a larger swap space like 8 GB - 32 GB ( 0.5x - 2x main memory) , but I don't think this will help in your case. – Peter Lawrey Aug 27 '15 at 12:21
  • 2
    Can you try Java 8 for comparison to check this isn't a bug which was fixed in a later version? – Peter Lawrey Aug 27 '15 at 12:22
  • BTW This says SUSE 11.x was supported for Java 7. http://www.oracle.com/technetwork/java/javase/config-417990.html – Peter Lawrey Aug 27 '15 at 12:22
  • 1
    What happens when you use `-Xmx8331m` or higher? Does the JVM supply an error message? – mthmulders Aug 27 '15 at 12:24
  • Added edit for the exact error message; Please note that the error message with -Xmx8331 is actually that it cannot create new native threads. It seems that it can allocate the heap itself successfully but then fails in the next step when it tries to allocate additional memory. – Indygoof Aug 27 '15 at 12:45
  • have you tried using smaller heap sizes ? this post suggests to do so http://stackoverflow.com/questions/6642184/could-not-reserve-enough-space-for-object-heap-to-start-jvm – Westranger Aug 27 '15 at 13:06
  • Check with a small C program using malloc/brk/sbrk how much memory you are able to allocate to a new process. Then you shall know whether this is a JVM issue or not. – Dakshinamurthy Karra Aug 27 '15 at 13:06
  • @Westranger of course it would work with a smaller heap. The issue is that i actually need a heap of at least 10g here. We could discuss now why the JVM would need that much of a heap and that java applications should be more optimized, but for example with big elasticsearch clusters you would usually go with a heap of 8-16Gb. – Indygoof Aug 27 '15 at 13:16
  • @user3271203 Sry for the misunderstanding, I mean why to use Xms anyway? When I work on our 512 GB machine I never use Xms only Xmx. Maybe Its my lack of understanding how the JVM works but you application will allocate the needed memory anyway up the the max you specified. Or is the Xms related to the perfomance? – Westranger Aug 27 '15 at 13:26
  • It might be similar to http://stackoverflow.com/questions/21558207/couldnt-reserve-enough-space-for-object-heap - so try changing `vm.overcommit_memory` or add few gigs of swap and see if it changes anything. – user158037 Aug 27 '15 at 13:38

1 Answers1

1

Just an update, for future reference: I have now changed the swap space to 8Gb, and now it worked without any problem. So it seems that the JVM is somehow calculating the swap space in when allocating the heap.

Cheers, Indy

Indygoof
  • 51
  • 6