Skip to content
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

Set MaxRAM and MaxRAMPercentage in launcher for native-image driver #8366

Closed

Conversation

zakkak
Copy link
Collaborator

@zakkak zakkak commented Feb 13, 2024

See #7277 (comment) for motivation.

We have been using this as the default in Mandrel since the 23.1 release.

See oracle#7277 (comment) for
motivation.

We have been using this as the default in Mandrel since the 23.1
release.
Copy link
Collaborator

@jerboaa jerboaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would bring the shell/cmd launchers on par with the native image version of the launcher.

@fniephaus
Copy link
Member

This would bring the shell/cmd launchers on par with the native image version of the launcher.

Sure that makes sense, although this changes it for all users of the launcher scripts, including Truffle languages, no?

@jerboaa
Copy link
Collaborator

jerboaa commented Feb 13, 2024

This would bring the shell/cmd launchers on par with the native image version of the launcher.

Sure that makes sense, although this changes it for all users of the launcher scripts, including Truffle languages, no?

Yes. We have no experience with those. If they have a similar setup of launching a JVM process driving native-image generation, it should still be a safe option to use those. I.e. keep the launching process (which is usually tiny) within certain bounds.

@fniephaus
Copy link
Member

Yes. We have no experience with those.

Ok, let me take a look at this in the next couple of days.

@ansalond
Copy link
Member

ansalond commented Feb 14, 2024

launcher_template.sh and launcher_template.cmd are used to generate bash/cmd launchers for every LauncherConfig that is not built as a native image. This includes, for example, the Toolchain launchers, which pass a different main class.

Rather than modifying the templates, I would pass these Java arguments to the extra_jvm_args of the native-image LauncherConfig: https://github.com/oracle/graal/blob/master/substratevm/mx.substratevm/mx_substratevm.py#L1096

For example:

diff --git a/substratevm/mx.substratevm/mx_substratevm.py b/substratevm/mx.substratevm/mx_substratevm.py
index 9456bd5759a..73983df49ed 100644
--- a/substratevm/mx.substratevm/mx_substratevm.py
+++ b/substratevm/mx.substratevm/mx_substratevm.py
@@ -1054,7 +1054,7 @@ def _native_image_launcher_extra_jvm_args():
     Gets the extra JVM args needed for running com.oracle.svm.driver.NativeImage.
     """
     # Support for running as Java module
-    res = []
+    res = ['-XX:MaxRAM=256m', '-XX:MaxRAMPercentage=80']
     if not mx_sdk_vm.jdk_enables_jvmci_by_default(get_jdk()):
         res.extend(['-XX:+UnlockExperimentalVMOptions', '-XX:+EnableJVMCI'])
     return res

@ansalond
Copy link
Member

BTW, should we pass only -Xmx256m instead of -XX:MaxRAM=256m -XX:MaxRAMPercentage=80?

Looking at #7277 (comment), this seems closer to what the native version does.

@fniephaus
Copy link
Member

BTW, should we pass only -Xmx256m instead of -XX:MaxRAM=256m -XX:MaxRAMPercentage=80?

+1, Xmx seems more standard. On a machine with 64GB memory, I get a max heap of 206M with the two flags, and on one with 1GB I get 199.19M (see below). So maybe fine-tuning is not really worth it?

64GB machine$ java -XX:MaxRAM=256m -XX:MaxRAMPercentage=80 -XshowSettings:vm -version
VM settings:
    Max. Heap Size (Estimated): 206.00M
    Using VM: Java HotSpot(TM) 64-Bit Server VM

java version "21.0.2" 2024-01-16 LTS
Java(TM) SE Runtime Environment Oracle GraalVM 21.0.2+13.1 (build 21.0.2+13-LTS-jvmci-23.1-b30)
Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 21.0.2+13.1 (build 21.0.2+13-LTS-jvmci-23.1-b30, mixed mode, sharing)
1GB machine $ java -XX:MaxRAM=256m -XX:MaxRAMPercentage=80 -XshowSettings:vm -version
VM settings:
    Max. Heap Size (Estimated): 199.19M
    Using VM: Java HotSpot(TM) 64-Bit Server VM

java version "21.0.2" 2024-01-16 LTS
Java(TM) SE Runtime Environment Oracle GraalVM 21.0.2+13.1 (build 21.0.2+13-LTS-jvmci-23.1-b30)
Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 21.0.2+13.1 (build 21.0.2+13-LTS-jvmci-23.1-b30, mixed mode, sharing)

@jerboaa
Copy link
Collaborator

jerboaa commented Feb 14, 2024

BTW, should we pass only -Xmx256m instead of -XX:MaxRAM=256m -XX:MaxRAMPercentage=80?

No. -XX:MaxRAMPercentage has no effect if you set -XX:MaxHeapSize (which is what the short form, -Xmx, is using). MaxRAMPercentage is being used as a percentage of "physical memory". By setting MaxRAM, you tell the JVM to use that for "physical memory". So the effect is that -Xmx will be 80% of 256mb. What you want to tell the JVM that launches the actual native image driver process, is to keep within 256mb including metaspace, jit code blobs, etc. Use most of it for heap, though.

@jerboaa
Copy link
Collaborator

jerboaa commented Feb 14, 2024

Rather than modifying the templates, I would pass these Java arguments to the extra_jvm_args of the native-image LauncherConfig: https://github.com/oracle/graal/blob/master/substratevm/mx.substratevm/mx_substratevm.py#L1096

For example:

diff --git a/substratevm/mx.substratevm/mx_substratevm.py b/substratevm/mx.substratevm/mx_substratevm.py
index 9456bd5759a..73983df49ed 100644
--- a/substratevm/mx.substratevm/mx_substratevm.py
+++ b/substratevm/mx.substratevm/mx_substratevm.py
@@ -1054,7 +1054,7 @@ def _native_image_launcher_extra_jvm_args():
     Gets the extra JVM args needed for running com.oracle.svm.driver.NativeImage.
     """
     # Support for running as Java module
-    res = []
+    res = ['-XX:MaxRAM=256m', '-XX:MaxRAMPercentage=80']
     if not mx_sdk_vm.jdk_enables_jvmci_by_default(get_jdk()):
         res.extend(['-XX:+UnlockExperimentalVMOptions', '-XX:+EnableJVMCI'])
     return res

That makes sense, thanks!

@jerboaa
Copy link
Collaborator

jerboaa commented Feb 14, 2024

We could of course set -XX:MaxRAM=256mb/0.8 -XX:MaxRAMPercentage=80 if you want to exactly match native image.

@fniephaus
Copy link
Member

fniephaus commented Feb 14, 2024

No. -XX:MaxRAMPercentage has no effect if you set -XX:MaxHeapSize (which is what the short form, -Xmx, is using).

I think @ansalond was suggesting to replace both flags with just the -Xmx flag.

@jerboaa
Copy link
Collaborator

jerboaa commented Feb 14, 2024

No. -XX:MaxRAMPercentage has no effect if you set -XX:MaxHeapSize (which is what the short form, -Xmx, is using).

I think @ansalond was suggesting to replace both flags with just the -Xmx flag.

Sure. I'm arguing that it makes more sense to set MaxRAM and MaxRAMPercentage as you can then easier reason about what the rest of the system will get. The point is with both flags, you restrict the whole tiny JVM process, which simply launches the generator, to stay within that setting. You also know what the heap chunk will be.

@fniephaus
Copy link
Member

Ok, let's go with the two flags then, especially because they have been tested with Mandrel.

@zakkak could you update the PR according to #8366 (comment)? Otherwise, I can take care of it and make the adjustment when merging your other PR.

@fniephaus
Copy link
Member

Let me take care of it, will share a PR when it's ready.

@zakkak
Copy link
Collaborator Author

zakkak commented Feb 15, 2024

Let me take care of it, will share a PR when it's ready.

OK if that works better for you, thanks @fniephaus.

@zakkak
Copy link
Collaborator Author

zakkak commented Feb 15, 2024

Superseded by #8384

@zakkak zakkak closed this Feb 15, 2024
@zakkak zakkak deleted the 2024-02-13-set-maxRam-for-driver branch April 18, 2024 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement. redhat-interest
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants