Is there any performance downsides to using the `-XX:+PerfDisableSharedMem` JVM flag?

From what I’ve read online, it sounds like a lot of people recommend setting the -XX:+PerfDisableSharedMem JVM flag to fix high GC pause latencies due to IO blocking when the garbage collector tries to write to /tmp (hsperfdata).

I’m trying to optimize the performance of our system’s garbage collection, and I tried running a load test before setting the -XX:+PerfDisableSharedMem flag and after, and it actually performed slightly better without the flag! I even reran the load tests a second time and got the same results.

So my question is: Was this just a fluke, or does -XX:+PerfDisableSharedMem actually have any potentially negative performance impacts?

(I understand that using -XX:+PerfDisableSharedMem will mean that certain diagnostics tools like jstat that depend on this file won’t work, but we don’t use any of those tools — I’m just asking about potential performance downsides, not tooling downsides.)

Answer

HotSpot JVM maintains certain Performance Counters that can be read by various serviceability tools.

By default, these performance counters are exported onto the file system under /tmp/hsperfdata_<user> directory, so that external tools like jstat can read them without direct communication to the JVM. jps tool also looks for these counters to find active JVMs.

JVM does not update the file directly; instead it maps the file into memory and updates the counters in memory. Any such memory update can potentialy cause file I/O. For example, when GC counters are updated during a GC pause, the operating system may decide to flush data to disk, and this in turn may extend the pause. This blog post describes the mentioned effect.

-XX:+PerfDisableSharedMem option forces JVM to use anonymous memory for Performance Counters instead of a mapped file. This helps to avoid random VM pauses caused by spontaneous disk I/O.

With this option, jps, jstat, JConsole and other tools won’t be able to find the JVM. However, the performance counters will be still collected. jcmd <pid> PerfCounter.print will be able to print the counters anyway.

There is no other negative performance impact of -XX:+PerfDisableSharedMem option. JVM updates counters exactly the same way in both cases; the only difference is whether the counters memory is mapped to a file or not.

Leave a Reply

Your email address will not be published. Required fields are marked *