Skip to content

Commit 6ef45dd

Browse files
committed
Reuse direct memory to heap factor
1 parent 36c9b20 commit 6ef45dd

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

distribution/tools/server-cli/src/main/java/org/elasticsearch/server/cli/JvmErgonomics.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
*/
2929
final class JvmErgonomics {
3030

31+
static final double DIRECT_MEMORY_TO_HEAP_FACTOR = 0.5;
32+
3133
private JvmErgonomics() {
3234
throw new AssertionError("No instances intended");
3335
}
@@ -44,7 +46,7 @@ static List<String> choose(final List<String> userDefinedJvmOptions, Settings no
4446
final long heapSize = JvmOption.extractMaxHeapSize(finalJvmOptions);
4547
final long maxDirectMemorySize = JvmOption.extractMaxDirectMemorySize(finalJvmOptions);
4648
if (maxDirectMemorySize == 0) {
47-
ergonomicChoices.add("-XX:MaxDirectMemorySize=" + heapSize / 2);
49+
ergonomicChoices.add("-XX:MaxDirectMemorySize=" + (long) (DIRECT_MEMORY_TO_HEAP_FACTOR * heapSize));
4850
}
4951

5052
final boolean tuneG1GCForSmallHeap = tuneG1GCForSmallHeap(heapSize);

distribution/tools/server-cli/src/main/java/org/elasticsearch/server/cli/MachineDependentHeap.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,15 @@ protected int getHeapSizeMb(Settings nodeSettings, MachineNodeRole role, long av
102102
* could result in ML processes crashing with OOM errors or repeated autoscaling up and down.
103103
*/
104104
case ML_ONLY -> {
105-
if (availableMemory <= (GB * 16)) {
106-
yield mb((long) (availableMemory * .4 * 2 / 3), 4);
105+
double heapFractionBelow16GB = 0.4 / (1.0 + JvmErgonomics.DIRECT_MEMORY_TO_HEAP_FACTOR);
106+
double heapFractionAbove16GB = 0.1 / (1.0 + JvmErgonomics.DIRECT_MEMORY_TO_HEAP_FACTOR);
107+
if (availableMemory <= GB * 16) {
108+
yield mb((long) (availableMemory * heapFractionBelow16GB), 4);
107109
} else {
108-
yield mb((long) min(((GB * 16) * .4 + (availableMemory - GB * 16) * .1) * 2 / 3, MAX_HEAP_SIZE), 4);
110+
yield mb(
111+
(long) min(GB * 16 * heapFractionBelow16GB + (availableMemory - GB * 16) * heapFractionAbove16GB, MAX_HEAP_SIZE),
112+
4
113+
);
109114
}
110115
}
111116
/*

0 commit comments

Comments
 (0)