adoptium-support icon indicating copy to clipboard operation
adoptium-support copied to clipboard

Large Pages fails when allocating 8GB+ on Windows/Java 19.

Open brucethemoose opened this issue 3 years ago • 6 comments
trafficstars

Please provide a brief summary of the bug

The title sums it up. It only happens in the Java 19 Adoptium build, not the Java 17 one.

Please provide steps to reproduce where possible

Enter the commands as seen in the cmd output below. Note the "failed to reserve and commit memory" error:

F:\JDKs\jdk-19.0.1+10-jre\bin>java -Xms8G -Xmx8G -XX:+UseLargePages -Xlog:gc+init --version
[0.027s][info][gc,init] CardTable entry size: 512
OpenJDK 64-Bit Server VM warning: Failed to reserve and commit memory using large pages. req_addr: 0x0000000600000000 bytes: 8589934592
[0.231s][info][gc,init] Version: 19.0.1+10 (release)
[0.231s][info][gc,init] CPUs: 16 total, 16 available
[0.231s][info][gc,init] Memory: 15789M
[0.232s][info][gc,init] Large Page Support: Enabled
[0.232s][info][gc,init] NUMA Support: Disabled
[0.232s][info][gc,init] Compressed Oops: Enabled (Zero based)
[0.232s][info][gc,init] Heap Region Size: 4M
[0.233s][info][gc,init] Heap Min Capacity: 8G
[0.233s][info][gc,init] Heap Initial Capacity: 8G
[0.233s][info][gc,init] Heap Max Capacity: 8G
[0.233s][info][gc,init] Pre-touch: Disabled
[0.233s][info][gc,init] Parallel Workers: 13
[0.233s][info][gc,init] Concurrent Workers: 3
[0.233s][info][gc,init] Concurrent Refinement Workers: 13
[0.233s][info][gc,init] Periodic GC: Disabled
openjdk 19.0.1 2022-10-18
OpenJDK Runtime Environment Temurin-19.0.1+10 (build 19.0.1+10)
OpenJDK 64-Bit Server VM Temurin-19.0.1+10 (build 19.0.1+10, mixed mode, sharing)

F:\JDKs\jdk-19.0.1+10-jre\bin>java -Xms7G -Xmx7G -XX:+UseLargePages -Xlog:gc+init --version
[0.007s][info][gc,init] CardTable entry size: 512
[0.014s][info][gc,init] Version: 19.0.1+10 (release)
[0.015s][info][gc,init] CPUs: 16 total, 16 available
[0.016s][info][gc,init] Memory: 15789M
[0.016s][info][gc,init] Large Page Support: Enabled
[0.017s][info][gc,init] NUMA Support: Disabled
[0.017s][info][gc,init] Compressed Oops: Enabled (Zero based)
[0.018s][info][gc,init] Heap Region Size: 4M
[0.018s][info][gc,init] Heap Min Capacity: 7G
[0.018s][info][gc,init] Heap Initial Capacity: 7G
[0.018s][info][gc,init] Heap Max Capacity: 7G
[0.019s][info][gc,init] Pre-touch: Disabled
[0.019s][info][gc,init] Parallel Workers: 13
[0.019s][info][gc,init] Concurrent Workers: 3
[0.019s][info][gc,init] Concurrent Refinement Workers: 13
[0.020s][info][gc,init] Periodic GC: Disabled
openjdk 19.0.1 2022-10-18
OpenJDK Runtime Environment Temurin-19.0.1+10 (build 19.0.1+10)
OpenJDK 64-Bit Server VM Temurin-19.0.1+10 (build 19.0.1+10, mixed mode, sharing)

F:\JDKs\jdk-19.0.1+10-jre\bin>"C:\JDKs\OpenJDK17U-jre_x64_windows_hotspot_17.0.4_8\jdk-17.0.4+8-jre\bin\java.exe" -Xms8G -Xmx8G -XX:+UseLargePages -Xlog:gc+init --version
[0.394s][info][gc,init] Version: 17.0.4+8 (release)
[0.395s][info][gc,init] CPUs: 16 total, 16 available
[0.395s][info][gc,init] Memory: 15789M
[0.395s][info][gc,init] Large Page Support: Enabled
[0.396s][info][gc,init] NUMA Support: Disabled
[0.396s][info][gc,init] Compressed Oops: Enabled (Zero based)
[0.396s][info][gc,init] Heap Region Size: 4M
[0.397s][info][gc,init] Heap Min Capacity: 8G
[0.397s][info][gc,init] Heap Initial Capacity: 8G
[0.397s][info][gc,init] Heap Max Capacity: 8G
[0.397s][info][gc,init] Pre-touch: Disabled
[0.398s][info][gc,init] Parallel Workers: 13
[0.398s][info][gc,init] Concurrent Workers: 3
[0.398s][info][gc,init] Concurrent Refinement Workers: 13
[0.398s][info][gc,init] Periodic GC: Disabled
openjdk 17.0.4 2022-07-19
OpenJDK Runtime Environment Temurin-17.0.4+8 (build 17.0.4+8)
OpenJDK 64-Bit Server VM Temurin-17.0.4+8 (build 17.0.4+8, mixed mode, sharing)

Expected Results

Large pages works.

Actual Results

Large pages does not work, even when just running "java -version" from the cmd window.

What Java Version are you using?

19.0.1+10 (release)

What is your operating system and platform?

Windows 10 21H2 on x86-64

Ryzen 4900HS CPU, 16GB of RAM.

Capture

Another user on another machine also experiences this issue.

How did you install Java?

Via a zip download from the Adoptium site.

Did it work before?

Yes, in Java 17.

Did you test with other Java versions?

I also tested this in GraalVM EE ('19.0.1+10-jvmci-22.3-b07'. It does appear to be an upstream bug, but I am not 100% sure:

F:\JDKs\graalvm-ee-java19-22.3.0\bin>java -Xms8G -Xmx8G -XX:+UseLargePages -Xlog:gc+init --version
[0.007s][info][gc,init] CardTable entry size: 512
Java HotSpot(TM) 64-Bit Server VM warning: Failed to reserve and commit memory using large pages. req_addr: 0x0000000600000000 bytes: 8589934592
[0.161s][info][gc,init] Version: 19.0.1+10-jvmci-22.3-b07 (release)
[0.161s][info][gc,init] CPUs: 16 total, 16 available
[0.161s][info][gc,init] Memory: 15789M
[0.161s][info][gc,init] Large Page Support: Enabled
[0.162s][info][gc,init] NUMA Support: Disabled
[0.162s][info][gc,init] Compressed Oops: Enabled (Zero based)
[0.163s][info][gc,init] Heap Region Size: 4M
[0.163s][info][gc,init] Heap Min Capacity: 8G
[0.163s][info][gc,init] Heap Initial Capacity: 8G
[0.164s][info][gc,init] Heap Max Capacity: 8G
[0.164s][info][gc,init] Pre-touch: Disabled
[0.164s][info][gc,init] Parallel Workers: 13
[0.165s][info][gc,init] Concurrent Workers: 3
[0.165s][info][gc,init] Concurrent Refinement Workers: 13
[0.165s][info][gc,init] Periodic GC: Disabled
java 19.0.1 2022-10-18
Java(TM) SE Runtime Environment GraalVM EE 22.3.0 (build 19.0.1+10-jvmci-22.3-b07)
Java HotSpot(TM) 64-Bit Server VM GraalVM EE 22.3.0 (build 19.0.1+10-jvmci-22.3-b07, mixed mode, sharing)

Relevant log output

(See repro steps section)

brucethemoose avatar Nov 06 '22 22:11 brucethemoose

https://bugs.openjdk.org/browse/JDK-8296467

karianna avatar Nov 07 '22 12:11 karianna

Also happens on lower than 8 gb allocated

C:\Users\%username%\Desktop>"C:\Users\%username%\Desktop\jdk-19.0.1+10\bin\java.exe" -Xms2G -Xmx2G -XX:+UseLargePages -Xlog:gc+init --version
[0.020s][info][gc,init] CardTable entry size: 512
OpenJDK 64-Bit Server VM warning: Failed to reserve and commit memory using large pages. req_addr: 0x0000000080000000 bytes: 2147483648
[0.743s][info][gc,init] Version: 19.0.1+10 (release)
[0.744s][info][gc,init] CPUs: 4 total, 4 available
[0.744s][info][gc,init] Memory: 8107M
[0.744s][info][gc,init] Large Page Support: Enabled
[0.745s][info][gc,init] NUMA Support: Disabled
[0.745s][info][gc,init] Compressed Oops: Enabled (32-bit)
[0.745s][info][gc,init] Heap Region Size: 1M
[0.746s][info][gc,init] Heap Min Capacity: 2G
[0.746s][info][gc,init] Heap Initial Capacity: 2G
[0.747s][info][gc,init] Heap Max Capacity: 2G
[0.747s][info][gc,init] Pre-touch: Disabled
[0.748s][info][gc,init] Parallel Workers: 4
[0.748s][info][gc,init] Concurrent Workers: 1
[0.751s][info][gc,init] Concurrent Refinement Workers: 4
[0.751s][info][gc,init] Periodic GC: Disabled
openjdk 19.0.1 2022-10-18
OpenJDK Runtime Environment Temurin-19.0.1+10 (build 19.0.1+10)
OpenJDK 64-Bit Server VM Temurin-19.0.1+10 (build 19.0.1+10, mixed mode, sharing)

Mustish avatar Nov 07 '22 14:11 Mustish

Oh possibly related, see the last comment here (from a previous report I did): https://bugs.openjdk.org/browse/JDK-8292905

brucethemoose avatar Nov 07 '22 16:11 brucethemoose

We are marking this issue as stale because it has not been updated for a while. This is just a way to keep the support issues queue manageable. It will be closed soon unless the stale label is removed by a committer, or a new comment is made.

github-actions[bot] avatar Feb 06 '23 00:02 github-actions[bot]

We are marking this issue as stale because it has not been updated for a while. This is just a way to keep the support issues queue manageable. It will be closed soon unless the stale label is removed by a committer, or a new comment is made.

github-actions[bot] avatar May 13 '23 00:05 github-actions[bot]

@brucethemoose - You most likely need to reboot your machine to free up enough contiguous space for the large page allocations to succeed.

Can this failure be reproduced after rebooting the machine? The failure to commit warning was introduced in JDK 19 - Use largest available large page size smaller than LargePageSizeInBytes when available. The absence of this warning on JDK 17 does not necessarily imply that JDK 17 successfully reserves large pages on Windows. To get more diagnostic info about this failure, run

java.exe -Xms8G -Xmx8G -XX:+UseLargePages -Xlog:gc+init -Xlog:pagesize=trace:file=pagesize.txt::filecount=0 -Xlog:os=trace:file=os.txt::filecount=0 --version

When the Windows VirtualAlloc function fails, the os.txt log will contain the error code. We have seen ERROR_NO_SYSTEM_RESOURCES on one machine. As per https://learn.microsoft.com/en-us/windows/win32/memory/large-page-support "large-page memory regions may be difficult to obtain after the system has been running for a long time because the physical space for each large page must be contiguous, but the memory may have become fragmented."

karianna avatar Sep 07 '23 05:09 karianna

For anyone else running into this issue as I just did, while the NT kernel unfortunately does not have any mechanism to defragment physical memory pages, running enable-mmagent -pagecombining in powershell to force a page deduplication run may get you just enough space to get a successful allocation. Probably not a bad idea to run before launching your application if failure means you have to reboot anyways.

The only 'reliable' way to get large pages on Windows is to strip it down as much as possible to reduce memory allocation calls from other things on the system and lock the pages ASAP early in the startup process. There is no way to reserve space for large pages without getting into ACPI memory hotplugging land, which is well out of scope for most places that are going to be running a JVM anyways.

timber-schroeder avatar Sep 15 '24 22:09 timber-schroeder