-2

everyone:

My service occured OOM Exception very often,the error message like this:

    OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00007f3f6e360000, 65536, 1) failed; error='Cannot allocate memory' (errno=12)
    #
    # There is insufficient memory for the Java Runtime Environment to continue.
    # Native memory allocation (mmap) failed to map 65536 bytes for committing reserved memory.

My server's JDK version:

    java -version
    openjdk version "1.8.0_121"
    OpenJDK Runtime Environment (build 1.8.0_121-8u121-b13-0ubuntu1.16.04.2-b13)
    OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)

My server's memory info:

  free -m
                  total        used        free      shared  buff/cache   available
    Mem:           3951         515        3107           0         328        3197
    Swap:          4095        1067        3028

my service's start shell is like this:

    nohup java -Xmx2048m -Xms1024m -jar  myService.jar >nohup.out &

the service is running ok on my local computer; but when i deploy the service for my cloud server, the error has happend!

my local computer's memory is 4G; my cloud server's memory is also 4G, and swap memory is 4G;

anyone can help me? very very thanks!!!

Alex
  • 19
  • 2
  • 8
  • 3
    Find what is using that memory and see if you can't optimize that... – AxelH Oct 30 '17 at 10:08
  • 1
    That probably means your server is eating a lot of memory, and there may be problems with memoryleaks. Have [the JVM write a heapdump file on OOM](https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/clopts001.html) and inspect that file using a tool like Eclipse MAT. – fvu Oct 30 '17 at 10:11
  • when i start the service, and see the used memory by "free -m", i can found the server also have a lot of memory. – Alex Oct 30 '17 at 11:12

2 Answers2

1

User a profiling tool like jvisualvm and find out what uses your memory. Then either fix that or give your JVM enough memory.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
  • the service running on my local computer is ok; but deploy on the VM server, has occured oom error. i think the server's memory is enough。 – Alex Oct 30 '17 at 11:10
  • 1
    Then you probably misconfigured your VM (not enough memory) or used a 32-bit version of Java. – J Fabian Meier Oct 30 '17 at 11:32
0

You can run the application with option -XX:MaxDirectMemorySize=55m

The default value for the same is ZERO (default in Java 7&8 is 0)

Amit Kumar
  • 29
  • 2
  • I add the option -XX:MaxDirectMemorySize=200m, but also have error, the commond like this: nohup java -XX:MaxDirectMemorySize=200m -jar myService.jar >nohup.out & – Alex Oct 31 '17 at 09:28