How to enforce ram limits on openJDK

  1. What is it when a program runs fine but slowly consumes more memory until the system crashes.
  2. How do I enforce a ram limit on minecraft launcher and ALL OF ITS CHILDREN (once removed twice removed, ALL OF THEM)

Hi there :wave:

  1. The Linux kernel’s OOM (out of memory) killer should kill the most memory consuming and least important program, this shouldn’t cause a system crash. Most often this would rightly kill the offending process, Minecraft in this case.
    Check the output of: sudo journalctl -k -g oom

  2. Use systemd-run to run the application in a transient systemd scope with memory limits:

systemd-run --user --scope -p MemoryMax=4G </path/to/executable>
# from new terminal get the transient scope name
systemctl --user status | grep -v grep | grep -iB1 </path/to/executable>
# verify the mem limit of the scope/process
systemctl --user show run-<truncated>.scope

What would happen when the set memory is full?

Completely depends on the program how it deals with limited memory, maybe it crashes, maybe it manages memory better seeing it only has so much. At least it won’t be able to request a ton of memory from the kernel and fill it all up, the kernel over-commits (gives away) memory in the hopes that not all of it will be actually needed. But when some memory leaking program actually fills it all up, the OOM killer is activated to reap the offending process.

1 Like

I have no idea about how Minecraft is ran.
You might find a java ... line somewhere, and maybe some sort of configuration file or variable where you can use the following parameter. Check Minecraft’s manual.

‐Xmx size
Specifies the maximum size (in bytes) of the heap. This value must be a multiple of 1024 and greater than 2 MB. Append the letter k or K
to indicate kilobytes, m or M to indicate megabytes, or g or G to indicate gigabytes. The default value is chosen at runtime based on
system configuration. For server deployments, ‐Xms and ‐Xmx are often set to the same value. The following examples show how to set the
maximum allowed size of allocated memory to 80 MB using various units:

‐Xmx83886080
‐Xmx81920k
‐Xmx80m

The ‐Xmx option is equivalent to ‐XX:MaxHeapSize.

@40476 Just edit the installation in the Minecraft launcher… (I use optifine here)

1 Like

I’d have thought that the jvm would be defaulting to the standard ~25% physical memory unless there is some large Xmx by default. Kind of odd you saw some system penalties.

@butcherbird oh dear that would be 32GB for me :wink:

1 Like

In my experience that does not work as it should be.

I did do two things:

  1. Installed earlyoom
  2. Double my memory
1 Like

my arguments are the same, but I use fabric with a few other mods, and minecraft has no idea its RAM usage is climbing. which is why I am trying to use the system to enforce a RAM limit

how might i incorporate this into minecraft launcher? (i can edit a config file if need be)

because when i do this it only affects the launcher, not openjdk/java

@40476 so minecraft-launcher is leaking? Not seeing that here…

it is not the launcher, it is openJDK except it has to be launched by minecraft launcher so I need a way to insert the RAM limit into that.

also, you can break telemetry by revoking all access ( including your own) to $HOME/.minecraft/logs/telemetry

@40476 But you configure each one in the Launcher as I indicated

it goes way beyond the RAM limit though, and I dont know whether that is fixed in a newer version of openJDK
I will run minercraft in with btop open and watch the ram, that way we have a screenshot of this stuff

@40476 what is that file list?

the mods i have installed, I was wondering if anyones had a memory related experience with them

@40476 Ahh ok, well I’m using java-11-openjdk here, don’t have an issue… I would suggest remove them, add each one back in one at a time and see which one is causing the issue…

Could you provide the output of:

systemd-run --user --scope -p MemoryMax=4G /path/to/minecraft-launcher
systemctl --user status