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

[GR-45673] Tweak GC settings of Native Image builder. #6432

Merged
merged 5 commits into from
May 4, 2023

Conversation

graalvmbot
Copy link
Collaborator

@graalvmbot graalvmbot commented Apr 17, 2023

This PR revises the GC settings of the Native Image builder. It now takes available memory into account to reduce memory pressure, which should make host machines more responsive during development and out-of-memory scenarios less likely. We also optimize for throughput by allowing for more time spent in the GC, which also reduces peak memory usage.

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Apr 17, 2023
@graalvmbot graalvmbot force-pushed the fniephaus/GR-45673/builder-max-heap branch from 44ab73c to 6572935 Compare April 17, 2023 09:08
@graalvmbot graalvmbot force-pushed the fniephaus/GR-45673/builder-max-heap branch from 6572935 to 2614e93 Compare April 24, 2023 14:51
@fniephaus fniephaus changed the title WIP [GR-45673] Adjust initial and max memory usage of builder. [GR-45673] Revise max memory usage of Native Image builder. Apr 24, 2023
@graalvmbot graalvmbot force-pushed the fniephaus/GR-45673/builder-max-heap branch 7 times, most recently from 0dc82ed to 4f8706e Compare April 27, 2023 09:55
@graalvmbot graalvmbot force-pushed the fniephaus/GR-45673/builder-max-heap branch from 4f8706e to c5d0252 Compare May 2, 2023 17:41
@fniephaus fniephaus changed the title [GR-45673] Revise max memory usage of Native Image builder. [GR-45673] Tweak GC settings of Native Image builder. May 2, 2023
@graalvmbot graalvmbot force-pushed the fniephaus/GR-45673/builder-max-heap branch 2 times, most recently from b8cb61d to 64dbd4f Compare May 4, 2023 06:50
Comment on lines +85 to +89
reasonableMaxMemorySize = switch (OS.getCurrent()) {
case LINUX -> getAvailableMemorySizeLinux();
case DARWIN -> getAvailableMemorySizeDarwin();
case WINDOWS -> getAvailableMemorySizeWindows();
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not use osBean.getFreeMemorySize()?

Copy link
Member

Choose a reason for hiding this comment

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

Free memory can be much lower than available memory due to OS caches etc, especially on long running developer machines.

Copy link
Member

Choose a reason for hiding this comment

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

This is from a cloud machine I ran for 20min:

MiB Mem :   7645.6 total,    134.0 free,   3298.8 used,   4212.8 buff/cache

Native Image wouldn't start if we set the max heap to 134MiB.

private static long getAvailableMemorySizeLinux() {
try {
String memAvailableLine = Files.readAllLines(Paths.get("/proc/meminfo")).stream().filter(l -> l.startsWith("MemAvailable")).findFirst().orElse("");
Matcher m = Pattern.compile("^MemAvailable:\\s+(\\d+) kB").matcher(memAvailableLine);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note that this metric is not container aware. I.e. on large systems, say with 1TB of memory, and a container slice of say 50GB you'd still get > 32 Gib since 50/0.8 > 32. Using the OSBean could solve this problem.

Copy link
Member

Choose a reason for hiding this comment

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

Good point and yes, in that case reasonableMaxMemorySize > totalMemorySize is true, so this would return the 80% fallback which actually matches the current behavior (80% of total memory). OSBean takes cgroups into account but it unfortunately only provides access to free, not available memory. Do you have any other suggestions how we could handle such cases?

Copy link
Member

Choose a reason for hiding this comment

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

Following up on this in #6581.

@graalvmbot graalvmbot merged commit 691c375 into master May 4, 2023
@graalvmbot graalvmbot deleted the fniephaus/GR-45673/builder-max-heap branch May 4, 2023 09:54
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.
Projects
Status: Released
Development

Successfully merging this pull request may close these issues.

3 participants