@@ -76,12 +76,16 @@ protected int getHeapSizeMb(Settings nodeSettings, MachineNodeRole role, long av
7676 /*
7777 * Machine learning only node.
7878 *
79- * <p>Heap is computed as:
80- * <ul>
81- * <li>40% of total system memory when total system memory 16 gigabytes or less.</li>
82- * <li>40% of the first 16 gigabytes plus 10% of memory above that when total system memory is more than 16 gigabytes.</li>
83- * <li>The absolute maximum heap size is 31 gigabytes.</li>
84- * </ul>
79+ * The memory reserved for Java is computed as:
80+ * - 40% of total system memory when total system memory 16 gigabytes or less.
81+ * - 40% of the first 16 gigabytes plus 10% of memory above that when total system memory is more than 16 gigabytes.
82+ * - The absolute maximum heap size is 31 gigabytes.
83+ *
84+ * This Java memory is divided as follows:
85+ * - 2/3 of the Java memory is reserved for the Java heap.
86+ * - 1/3 of the Java memory is reserved for the Java direct memory.
87+ *
88+ * The direct memory being half of the heap is set by the JvmErgonomics class.
8589 *
8690 * In all cases the result is rounded down to the next whole multiple of 4 megabytes.
8791 * The reason for doing this is that Java will round requested heap sizes to a multiple
@@ -98,15 +102,6 @@ protected int getHeapSizeMb(Settings nodeSettings, MachineNodeRole role, long av
98102 * could result in ML processes crashing with OOM errors or repeated autoscaling up and down.
99103 */
100104 case ML_ONLY -> {
101- /*
102- * An ML node used to have 40% of the total memory for the Java heap, and the remainder
103- * for ML and overhead (the operating system). This did not account for the Java direct
104- * memory, which equals half of the heap size (see JvmErgonomics).
105- * Right now, a factor of 2/3 is applied to the heap size here, leaving the ML memory
106- * formula the same. That means the formula now also correctly accounts for direct memory,
107- * since the heap (2/3 * 40% of the memory) plus the direct memory (1/3 * 40% of the memory)
108- * equals the original 40% of the total memory.
109- */
110105 if (availableMemory <= (GB * 16 )) {
111106 yield mb ((long ) (availableMemory * .4 * 2 / 3 ), 4 );
112107 } else {
0 commit comments