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

Fix THP detection on Linux

    XMLWordPrintable

Details

    • b07

    Backports

      Description

        Today, if we use UseTransparentHugePages, we assume that the static hugepage detection we do is valid for THPs:
        - that THPs use the page size (in hotspot used as "default large page size") found in /proc/memlimit Hugepagesize)
        - that THPs are enabled if that page size is >0.

        Both assumptions are incorrect. THPs are enabled depending on the mode in `/sys/kernel/mm/transparent_hugepage/enabled` (tri-state). And the pagesize used by khugepaged is the one set in `/sys/kernel/mm/transparent_hugepage/hpage_pmd_size`. The latter can differ from the default large page size on the system (e.g. static hugepage default size could be 1g, whereas THP hugepage size is 2m).

        -------------

        Example 1: System has THPs disabled, but static hugepages (1g, 2m) configured:

        ```
        thomas@starfish $ cat /sys/kernel/mm/transparent_hugepage/enabled
        always madvise [never]
        thomas@starfish $ cat /proc/meminfo | grep Hugepage
        Hugepagesize: 1048576 kB
        ```

        We incorrectly assume THPs are enabled, and that THP page size is 1G (!), which we then proceed and use as heap page size, causing the heap size to be rounded up from 512m -> 1G:

        ```
        thomas@starfish $ ./images/jdk/bin/java -Xmx512m -XX:+UseLargePages -XX:+UseTransparentHugePages -Xlog:pagesize -version
        [0.001s][info][pagesize] Using the default large page size: 1G
        [0.001s][info][pagesize] Usable page sizes: 4k, 2M, 1G
        ...
        [0.016s][info][pagesize] Heap: min=1G max=1G base=0x00000000c0000000 size=1G page_size=1G
        ```

        ----------

        Example 2: System has THPs enabled, but THP page size is just *2M*, whereas the system uses a static default hugepage size of *1G*:

        ```
        thomas@starfish $ cat /sys/kernel/mm/transparent_hugepage/enabled
        always [madvise] never
        thomas@starfish $ cat /sys/kernel/mm/transparent_hugepage/hpage_pmd_size
        2097152
        thomas@starfish $ cat /proc/meminfo | grep Hugepage
        Hugepagesize: 1048576 kB
        ```

        WTHP page size is not correctly recognized as 2M. Instead, we again use 1G as page size for the heap:

        ```
        thomas@starfish $ ./images/jdk/bin/java -Xmx512m -XX:+UseLargePages -XX:+UseTransparentHugePages -Xlog:pagesize -version
        [0.001s][info][pagesize] Using the default large page size: 1G
        [0.001s][info][pagesize] Usable page sizes: 4k, 2M, 1G
        ...
        [0.010s][info][pagesize] Heap: min=1G max=1G base=0x00000000c0000000 size=1G page_size=1G
        ```

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                  Created:
                  Updated:
                  Resolved: