3

I am having some issues running java in an environment with memory controls. My use case is sun grid engine (SGE), but I can reproduce with ulimit.

When I try to run java with a limit on memory, (-Xmx), I find that I still need to allow a much larger amount of memory from ulimit.

evaben@evaben:~$ (ulimit -v 1000000; java -Xmx500m -version; )
Error occurred during initialization of VM
Could not allocate metaspace: 1073741824 bytes
evaben@evaben:~$ (ulimit -v 2000000; java -Xmx500m -version; )
Error occurred during initialization of VM
Could not allocate metaspace: 1073741824 bytes
evaben@evaben:~$ (ulimit -v 4000000; java -Xmx500m -version; )
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-2ubuntu0.18.04.1-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)
evaben@evaben:~$ 

So a -Xmx of 500m requires 4G of space from ulimit. I know that Xmx only limits some aspects of java memory usage, maybe only the heap. But a 3.5G or 700% overhead seems excessive.

I have tried some strace-ing, and I see the above java is mmap-ing multiple large blocks, maybe from different threads or child processes.

strace -f -e memory java -Xmx500M -version 2>&1 1>/dev/null  | grep mmap | grep ENOMEM | wc -l
96

strace -f -e memory java -Xmx500M -version 2>&1 1>/dev/null  | grep mmap | awk '$1 == "[pid"{print $2}' | sort | uniq -c 
> many pids mmapping

/bin/time only reports RSS, around 30 Mbytes in this example. Is there an easy way to show total alloc/mmap requests?

Why does java need so much memory? Is there any way to get java to run with less memory allocation required?

Evan Benn
  • 1,571
  • 2
  • 14
  • 20

0 Answers0