You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To accommodate memory ranges, the weight balancing algorithm is
completely overhauled.
Each way in which a memory size may be specified is equivalent to a
range. Omitting a memory size is equivalent to specifying the range
`0..`. Specifying a single value is equivalent to specifying the
corresponding degenerate range.
In the four dimensional space of memory types (heap, permgen/maxspace,
stack, and native), the Cartesian product of memory ranges is a (four
dimensional) box B, all of whose edges start at a non-negative memory
size but may extend to plus infinity in any dimension if the
corresponding range is unbounded.
The total available memory ($MEMORY_LIMIT) defines a hyperplane T in
which each point has memory size coordinates which sum to the total
available memory. T separates the whole space into two half spaces.
The half space containing the origin consists of points which consume
less than the total available memory. The other half space consists of
points which consume more than the available memory.
The memory weightings describe a line W which intersects T at a single
point D (for default), which is the Cartesian product of the default
memory sizes (in the absence of any memory ranges).
In non-error cases, T intersects B in a "hypersegment" S of points
which lie within all the memory ranges and have total memory equal to
the total available memory. Note that S is convex.
The weight balancing algorithm aims to find the closest point of S to
the point D. If D lies within S, then the closest point is D itself.
If D lies outside S, then since S is convex, there is a unique point
in S which is closest to D.
The weight balancing algorithm works as follows. It first sets a
search point x to the point D. If x lies within S, the algorithm
terminates. If x lies outside S, the algorithm determines in which
dimensions x lies outside S. x is moved by constraining x to B in
those dimensions. This effectively drops a perpendicular onto B in
those dimensions. These dimensions of x are now fixed for the
remainder of the algorithm and the corresponding memory sizes are
deemed to have been allocated. If there are no remaining dimensions,
the algorithm terminates. Otherwise, the remaining dimensions of x are
recalculated by balancing the remaining memory among the remaining
dimensions. x now either lies within S in those dimensions or it does
not, in which case the above steps are repeated.
It remains to be proved that this algorithm always determines the
unique point in S which is closest to D.
Native memory is allowed to have an upper bound. Even though this
isn't particularly useful, there is no need to prohibit it and this
simplifies the documentation.
Stack size handling is improved. If a range of stack sizes is
specified and the floor of the range is non-zero, the floor is used as
the default stack size. Otherwise, the JVM default stack size is used.
Also, the number of threads, determined from the weighted proportion
of total available memory for the stack divided by the default stack
size, is rounded and, if necessary, adjusted upwards to one to behave
better in edge cases. Working in terms of a speculative number of
threads is not ideal, but it does allow stack ranges and sizes to be
converted back and forth between individual stack size and total stack
memory.
Memory weightings are generalised so that they need no longer add up
to 1.
The MemorySize type is extended to cope with a zero memory size with
no unit.
Set max permgen range based on default max permgen size. This will
improve permgen for applications with less than 640M of total memory.
Note that such applications will get less heap and a smaller stack
than would be the case without the permgen range.
[#58060090]
Copy file name to clipboardExpand all lines: docs/jre-openjdk.md
+36-9Lines changed: 36 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,27 +21,54 @@ The JRE can be configured by modifying the [`config/openjdk.yml`][] file. The J
21
21
| `repository_root` | The URL of the OpenJDK repository index ([details][repositories]).
22
22
| `version` | The version of Java runtime to use. Candidate versions can be found in the listings for [lucid][], [mountainlion][], and [precise][].
23
23
| `memory_sizes` | Optional memory sizes, described below under "Memory".
24
-
| `memory_heuristics` | Default memory size proportions, described below under "Default Memory Sizes".
24
+
| `memory_heuristics` | Default memory size weightings, described below under "Default Memory Sizes".
25
25
26
26
### Memory
27
27
28
28
The following optional properties may be specified in the `memory_sizes` mapping.
29
29
30
30
| Name | Description
31
31
| ---- | -----------
32
-
| `heap` | The Java maximum heap size to use. For example, a value of `64m` will result in the Java command line option `-Xmx64m`. Values containing whitespace are rejected with an error, but all others values appear without modification on the Java command line appended to `-Xmx`.
33
-
| `metaspace` | The Java maximum Metaspace size to use. This is applicable to versions of OpenJDK from 1.8 onwards. For example, a value of `128m` will result in the Java command line option `-XX:MaxMetaspaceSize=128m`. Values containing whitespace are rejected with an error, but all others values appear without modification on the Java command line appended to `-XX:MaxMetaspaceSize=`.
34
-
| `permgen` | The Java maximum PermGen size to use. This is applicable to versions of OpenJDK earlier than 1.8. For example, a value of `128m` will result in the Java command line option `-XX:MaxPermSize=128m`. Values containing whitespace are rejected with an error, but all others values appear without modification on the Java command line appended to `-XX:MaxPermSize=`.
35
-
| `stack` | The Java stack size to use. For example, a value of `256k` will result in the Java command line option `-Xss256k`. Values containing whitespace are rejected with an error, but all others values appear without modification on the Java command line appended to `-Xss`.
32
+
| `heap` | The maximum heap size to use. It may be a single value such as `64m` or a range of acceptable values such as `128m..256m`. It is used to calculate the value of the Java command line option `-Xmx`.
33
+
| `metaspace` | The maximum Metaspace size to use. It is applicable to versions of OpenJDK from 1.8 onwards. It may be a single value such as `64m` or a range of acceptable values such as `128m..256m`. It is used to calculate the value of the Java command line option `-XX:MaxMetaspaceSize=`.
34
+
| `permgen` | The maximum PermGen size to use. It is applicable to versions of OpenJDK earlier than 1.8. It may be a single value such as `64m` or a range of acceptable values such as `128m..256m`. It is used to calculate the value of the Java command line option `-XX:MaxPermSize=`.
35
+
| `stack` | The stack size to use. It may be a single value such as `2m` or a range of acceptable values such as `2m..4m`. It is used to calculate the value of the Java command line option `-Xss`.
36
+
| `native` | The amount of memory to reserve for native memory allocation. It should normally be omitted or specified as a range with no upper bound such as `100m..`. It does not correspond to a switch on the Java command line.
36
37
37
-
###Default Memory Sizes
38
+
#### Memory Sizes and Ranges
38
39
39
-
If some memory sizes are not specified using the above properties, default values are provided. For maximum heap, Metaspace, or PermGen size, the default value is based on a proportion of the total memory specified when the application was pushed. For stack size, the default value is one megabyte.
40
+
Memory sizes together with _memory weightings_ (described in the next section) are used to calculate the amount of memory for each memory type. The calculation is described later.
40
41
41
-
If a memory size is specified which is not equal to the default value, the other default values are adjusted proportionately, except that the default stack size is never adjusted.
42
+
Memory sizes consist of a non-negative integer followed by a unit (`k` for kilobytes, `m` for megabytes, `g` for gigabytes; the case is not significant). Only the memory size `0` may be specified without a unit.
42
43
43
-
The default memory size proportions are configured in the `memory_heuristics` mapping of [`config/openjdk.yml`][]. Each memory size is given a weighting between `0` and `1` corresponding to a proportion of the total memory specified when the application was pushed. The weightings should add up to `1`.
44
+
The above memory size properties may be omitted, specified as a single value, or specified as a range. Ranges use the syntax `<lower bound>..<upper bound>`, although either bound may be omitted in which case the defaults of zero and the total available memory are used for the lower bound and upper bound, respectively. Examples of ranges are `100m..200m` (any value between 100 and 200 megabytes, inclusive) and `100m..` (any value greater than or equal to 100 megabytes).
45
+
46
+
Each form of memory size is equivalent to a range. Omitting a memory size is equivalent to specifying the range `0..`. Specifying a single value is equivalent to specifying the range with that value as both the lower and upper bound, for example `128m` is equivalent to the range `128m..128m`.
44
47
48
+
#### Memory Weightings
49
+
50
+
Memory weightings are configured in the `memory_heuristics` mapping of [`config/openjdk.yml`][]. Each weighting is a non-negative number and represents a proportion of the total available memory (represented by the sum of all the weightings). For example, the following weightings:
51
+
52
+
```
53
+
memory_heuristics:
54
+
heap: 15
55
+
permgen: 5
56
+
stack: 1
57
+
native: 2
58
+
```
59
+
60
+
represent a maximum heap size three times as large as the maximum PermGen size, and so on.
61
+
62
+
Memory weightings are used together with memory ranges to calculate the amount of memory for each memory type, as follows.
63
+
64
+
#### Memory Calculation
65
+
66
+
The total available memory is allocated into heap, Metaspace or PermGen (depending on the version of OpenJDK), stack, and native memory types.
67
+
68
+
The total available memory is allocated to each memory type in proportion to its weighting. If the resultant size of a memory type lies outside its range, the size is constrained to
69
+
the range, the constrained size is excluded from the remaining memory, and no further calculation is required for the memory type. If the resultant size of a memory size lies within its range, the size is included in the remaining memory. The remaining memory is then allocated to the remaining memory types in a similar fashion. Allocation terminates when none of the sizes of the remaining memory types is constrained by the corresponding range.
70
+
71
+
Termination is guaranteed since there is a finite number of memory types and in each iteration either none of the remaining memory sizes is constrained by the corresponding range and allocation terminates or at least one memory size is constrained by the corresponding range and is omitted from the next iteration.
45
72
46
73
[`config/openjdk.yml`]: ../config/openjdk.yml
47
74
[Configuration and Extension]: ../README.md#Configuration-and-Extension
0 commit comments