I know the MaxMetaspaceSize is unlimited by default,and the biggest memory size is 2^64(18446744073709551616)
in bytes for Windows x64, so why don't set the MaxMetaspaceSize to 2^64
but set it to 18446744073709486080
which equals: 2^64-2^16
?
Asked
Active
Viewed 372 times
1

avocadoLambda
- 1,332
- 7
- 16
- 33

失去同步
- 43
- 4
-
How can the default MaxMetaSpaceSize be 18446744073709486080 if it is unlimited by default? – khelwood Aug 14 '21 at 08:11
-
I think it's just unlimited logically, in fact, it's limited, but we can't reach the bound it for now. – 失去同步 Aug 15 '21 at 09:46
1 Answers
2
The "ulimited" size in the HotSpot JVM is represented by the maximum value that fits 64 bit integer variable, that is, 264-1.
MaxMetaSpaceSize
is then further aligned (rounded down) to the minimum metaspace allocation unit
// Ideally, we would be able to set the default value of MaxMetaspaceSize in
// globals.hpp to the aligned value, but this is not possible, since the
// alignment depends on other flags being parsed.
MaxMetaspaceSize = align_size_down_bounded(MaxMetaspaceSize, _reserve_alignment);
which is equal to 64K (216) on Windows.

apangin
- 92,924
- 10
- 193
- 247
-
I read the source code, and i saw the value of `_reserve_alignment` is the bigger one of `page_size` and the return value of `os::vm_allocation_granularity()` , then i search for the default values of this two, i got they are [4KB and 64KB on Windows X64](https://stackoverflow.com/questions/438863/virtual-allocation-granularity-and-page-size), after that, the value of `_reserve_alignment` is 64KB and `MaxMetaSpaceSize` is aligned (rounded down) to this, so it's 2^64-2^16.And that means `MaxMetaSpaceSize` is not fixed, it will change.But why should `MaxMetaSpaceSize` to be aligned? – 失去同步 Aug 15 '21 at 09:55
-
1@失去同步 Why not? It's just an implementation detail. Metaspace management logic depends on this parameter, and it's convenient in the code to have it aligned. – apangin Aug 15 '21 at 11:56
-
well, so it doesn't have to be aligned, or it doesn't matter if it's not aligned, right? – 失去同步 Aug 15 '21 at 12:35
-
1In theory, `MaxMetaSpaceSize` doesn't need to be aligned, but unaligned values don't make sense anyway. – apangin Aug 15 '21 at 12:52
-
Thanks for your answer. Now i know why the `MaxMetaSpaceSize` is `2^64-2^16`. But I still don't quite understand why to be aligned, what are the disadvantages of not doing so, or there are conventions for this, or there are some benefits by doing so? – 失去同步 Aug 16 '21 at 05:52
-
I have a possible explanation. Because the memory allocation unit is `64KB`, the size of the `MetaSpace` can only be a multiple of `64KB`. When it reaches `18446744073709486080`, the system can no longer allocate memory for it, because the remaining memory is less the `64KB`, but the size of the `Metaspace` does not reach `MaxMetaspaceSize`, so it will try to apply for memory allocation again and again which will make the program to run abnormally. – 失去同步 Aug 16 '21 at 05:53
-
I don't know whether it's right or not. If you are willing to answer this, thanks again! And forgive for my poor english please, hope you can understand my explanation. – 失去同步 Aug 16 '21 at 05:56
-
1@失去同步 that’s a scenario you will never run into. No real system gets even close to having 18446744073709486080 bytes. But consider that this is the general function for reporting the limit, not dedicated to the 2⁶⁴ special case. So don’t focus on that special case. Then, the reason should become obvious. When the limit *n* has been specified, you have to round it down according to the alignment, because that’s the maximum amount of memory you can allocate without exceeding the limit. Allocating only one more byte would actually allocate more than *n* due to the alignment. – Holger Aug 16 '21 at 07:55