-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Force GC on auto-pause to save RAM #2687
Comments
Thanks, that is a good suggestion. My concern is that garbage collection will compact the JVM's heap memory, but I don't believe it will release any of that heap allocation back to the operating system. Can you research that with one of your running instances? I'm also pretty sure that |
You're right, it seems JVM really doesn't like releasing memory back to the OS. However I found a few flags that may help. I'm not a Java developer, so perhaps there is some performance cost or nuance I wasn't aware of.
I haven't yet had the opportunity to test any of this but perhaps this can force the JVM to not hold onto memory when paused. Also, how is the pause feature implemented? Is the process itself paused or is the JVM aware of it? If any of this is enabled, could JVM regard this as idle state and release the unused memory? I'm anything but an expert here, so please correct me if I am wrong. |
Good research. So it might turn out that users adding those options for Java 8 containers and relying on the default G1 for Java 17 etc might the best that can be done anyway. To answer your question it pauses the process as a whole with a STOP signal
So I don't believe the JVM will be aware of that or even given a chance to interpret it. |
I wonder if it can be called inside the container to instantly swap most of the server's memory usage. Sadly though, after testing it, it doesn't seem it swaps out more than ~25% of the memory...
|
Problem
Auto-pause, despite saving the CPU power, does little to curb the rather enormous RAM usage a Minecraft server, especially with Forge, can impose on the system, being rather problematic for installations where Minecraft lives alongside other services like a home server. Auto-shutdown may seem like a solution, but as far as I can see, it doesn't support automatic startup on new network connections like auto-pause, so isn't considered a viable alternative.
Proposed solution
I propose to amend this feature by forcing the JVM to perform a garbage collection before pausing. One way I found of achieving it would look something like
jcmd $(jps -l | grep forge-1.12.2-14.23.5.2860.jar | awk '{print $1}') GC.run
which would require the following options for the JVM to enable debugging
Perhaps there is a better implementation, but this serves as illustration for my proposal. This simple feature may make a great difference for many RAM-scarce homelabs.
Alternatives considered
The text was updated successfully, but these errors were encountered: