Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is contained in code/internal sections of JCMD?

Dimensioning a docker container for a JVM based service is tricky (as we all know). I'm pretty sure we have slightly under-dimensioned a container and want to clear up a few questions I have relating to specific jcmd (Native Memory Tracker) outputs that we see when monitoring.

Questions:

  • Are Direct Byte Buffers included in "Internal" as reported by jcmd?
  • What else apart from code cache is in "Code" as reported by jcmd?
  • Is there a good way to limit the "Code" section as reported by jcmd. I read https://docs.oracle.com/javase/8/embedded/develop-apps-platforms/codecache.htm but this only covers the code cache limits and it is suggested to leave the JVM default as is.

JCMD output is here.

Direct Byte Buffers JMX properties are here.

Some background details:

The Setup:

  • Spring boot based application
  • JVM Options:

    -server -Xms1792m -Xmx1792m -XX:MetaspaceSize=128M - XX:MaxMetaspaceSize=192M -XX:+UseG1GC -XX:+UseStringDeduplication - XX:MaxDirectMemorySize=256m -XX:NativeMemoryTracking=detail

  • Docker container 2500MiB running in AWS/EC2
like image 696
Ronan B Avatar asked Nov 15 '17 14:11

Ronan B


People also ask

What is JCMD command?

The jcmd utility is used to send diagnostic command requests to the JVM, where these requests are useful for controlling Java Flight Recordings, troubleshoot, and diagnose JVM and Java Applications.

What is JCMD EXE?

The jcmd utility is used to send diagnostic command requests to the JVM. It must be used on the same machine on which the JVM is running, and have the same effective user and group identifiers that were used to launch the JVM.

Where is JCMD?

The jcmd is available at the JDK/bin , not JRE. Make sure the installed Java is JDK, not JRE. Let review the following example, try to use jcmd to enable Java Flight Recorder inside a docker container.


1 Answers

Are Direct Byte Buffers included in "Internal" as reported by jcmd?

(updated) ByteBuffer.allocateDirect internally calls Unsafe.allocateMemory which is counted by NMT in the Internal section (denoted by mtInternal constant).

On the contrary, MappedByteBuffers (obtained by FileChannel.map) are not reflected in NMT report, though they definitely may affect the amount of memory used by the process from OS perspective.

What else apart from code cache is in "Code" as reported by jcmd?

Auxiliary VM structures for maintaining compiled code and generated runtime stubs: hashtables, code strings, adapter fingerprints etc. They all are rather small comparing to the CodeCache itself. These structures make up 'malloc' part in the report while the CodeCache goes into 'mmap' part.

Is there a good way to limit the "Code" section as reported by jcmd.

Turning off tiered compilation (-XX:-TieredCompilation) is likely to reduce the amount of memory used by "Code", just because there will be a lot less generated code. But make sure you understand what tiered compilation is and what performance impact it may have.

like image 158
apangin Avatar answered Nov 12 '22 21:11

apangin