Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8267475

Heap size rounded up to large page size may cause excessive memory waste

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 17
    • hotspot
    • gc
    • linux, windows

      If we start the VM with UseLargePages, we round up the heap size to the large page size:

      https://github.com/openjdk/jdk/blob/aba22656829913d5f8d619a184c929a7de8431e4/src/hotspot/share/memory/universe.cpp#L815

      Can be easily reproduced even on a normal (2g large pages) linux x64:

      ```
      thomas@starfish:/shared/projects/openjdk$ ./jdk-jdk/output-fastdebug/images/jdk/bin/java -XX:+UseLargePages -Xmx32769k -Xlog:pagesize -version
      ...
      [0.047s][info][pagesize] Heap: min=8M max=34M base=0x00000000fde00000 page_size=2M size=34M
                                              ^^^
      ```

      (We start with 32m+1k, but use 34m)

      This is maybe acceptable for "small" large pages of 2MB, but with larger large pages this becomes an issue.

      See JDK-8267460, where a test error on an AARCH64 machine with 64k base- and 512m huge page size means that a VM started with 128m heap size and UseLargePages will grab a heap of 512m.

      This calculation happens before reservation. If we then fail to grab a huge page, we will use up a virtual size of 512m, which is bearable (apart from the surprisingly large heap limit). But if we actually get a huge page, all that memory is committed and used right away.

      I am sure we face the same issue with 1g pages on x64. But unfortunately I don't have a system with large large pages to test this. I am also not sure whether this would affect Windows.

            Unassigned Unassigned
            stuefe Thomas Stuefe
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: