question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

set MaxDirectMemorySize, reconsider `Xmx` default size

See original GitHub issue

I discovered that setting the Java option -XX:MaxDirectMemorySize is effective at limiting the game’s seemingly limitless hunger for memory outside the Java heap. I don’t know what heuristic it uses by default, but my processes were regularly multiple gigabytes larger than Xmx led me to believe they should be. (As measured by looking at the process in Linux and noting its Resident Set Size or data+stack size as in #4946).

A value of -XX:MaxDirectMemorySize=512M was sufficient to run a single-player game of Metal Renegades with “Moderate” view distance (plus 6 LOD).

Looking at how much of the process’s memory is not in the Java heap also made me reconsider what value we use for that by default. We currently give it a whopping three gigabytes in development workspaces: https://github.com/MovingBlocks/Terasology/blob/984d9e94e2be5084e2b8a121908070537486252f/build-logic/src/main/kotlin/org/terasology/gradology/exec.kt#L16

—but that single-player MR game seemed content with only a quarter of that (768M).

Places to adjust this:

  • build-logic/exec.kt
    • change DEFAULT_MAX_HEAP_SIZE
    • add an @Option to set MaxDirectMemorySize, provide a default
  • IntelliJ run configs?
  • Launcher. If I recall correctly, it has UI in settings for Xmx. I don’t remember if it sets it by default. I think it also allows you to set additional arbitrary java arguments, but I think it would be worth it to provide explicit support for this one so we don’t rely on users remembering to add it.

Considerations:

Why did we set DEFAULT_MAX_HEAP_SIZE so high? (I think that change was within the last year or two.)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:23 (23 by maintainers)

github_iconTop GitHub Comments

1reaction
jdrueckertcommented, May 29, 2022

From what I saw, memory consumption never went above 3G according to my resource monitor. Would be interesting to see how it behaves in multiplayer testing on the server. But considering that there were no crashes, I’d argue that we can try the memory restriction and if we receive error reports, we can still increase it…? @keturn

1reaction
keturncommented, May 7, 2022

I guess I’m not too surprised to hear it requires hacky workarounds to access at runtime, given that it’s an implementation-specific flag set with -XX.

It looks like one way to check is to add the -XX:+PrintCommandLineFlags flag. With that I get:

Task :facades:PC:game -XX:G1ConcRefinementThreads=8 -XX:GCDrainStackTargetSize=64 -XX:InitialHeapSize=261478272 -XX:+ManagementServer -XX:MaxDirectMemorySize=536870912 -XX:MaxHeapSize=805306368 -XX:+PrintCommandLineFlags -XX:ReservedCodeCacheSize=251658240 -XX:+SegmentedCodeCache -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseG1GC 11:51:52.027 [main] INFO org.terasology.engine.Terasology - homeDir is .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Default for XX:MaxDirectMemorySize - java - Stack Overflow
from what i found in my exploration, it looks like 64 is the default, using -1 as the value sets it to -Xmx....
Read more >
XX:MaxDirectMemorySize - Eclipse
By default, the amount of native memory used for Direct Byte Buffers is limited to 87.5% of the maximum heap size. Start of...
Read more >
Configuring Off-Heap Store - Software AG Documentation
Oracle HotSpot has a default equal to maximum heap size (-Xmx value), although some early versions may default to a particular value. *...
Read more >
Default Java Maximum Heap Size is changed for Java 8
The default values for Xmx is based on the physical memory of the machine. The Xmx value is 25% of the available memory...
Read more >
JVM Memory Settings and System Performance - VMware Docs
JVM heap size—Your JVM may require more memory than is allocated by default. · MaxDirectMemorySize—The JVM has a kind of memory called direct ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found