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

Linux: THPs enabled even if system support missing

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • tbd
    • 21, 22
    • hotspot

      If user enabled +UseTransparentHugePages, we do a sanity check to check support for THP:

      ```
      bool os::Linux::transparent_huge_pages_sanity_check(bool warn,
                                                          size_t page_size) {
        bool result = false;
        void *p = mmap(nullptr, page_size * 2, PROT_READ|PROT_WRITE,
                       MAP_ANONYMOUS|MAP_PRIVATE,
                       -1, 0);
        if (p != MAP_FAILED) {
          void *aligned_p = align_up(p, page_size);

          result = madvise(aligned_p, page_size, MADV_HUGEPAGE) == 0;

          munmap(p, page_size * 2);
        }

        if (warn && !result) {
          warning("TransparentHugePages is not supported by the operating system.");
        }

        return result;
      }
      ```

      That does not work as expected. The madvice returns success even if THPs are disabled at the system level. As a result, the UseTransparentHugePages flag stays enabled:

      ```
      thomas@starfish$ cat /sys/kernel/mm/transparent_hugepage/enabled
      always madvise [never]
      thomas@starfish$ ./images/jdk/bin/java -XX:+UseTransparentHugePages -XX:+PrintFlagsFinal | grep Pages
           bool LargePagesIndividualAllocationInjectError = false {develop} {default}
           intx StackRedPages = 1 {pd product} {default}
           intx StackReservedPages = 1 {pd product} {default}
           intx StackShadowPages = 24 {pd product} {default}
           intx StackYellowPages = 2 {pd product} {default}
           bool UseLargePages = true {pd product} {default}
           bool UseLargePagesIndividualAllocation = false {pd product} {default}
           bool UseTransparentHugePages = true {product} {command line}
      ```

      Also verified with gdb.

      The real test would be to check /sys/kernel/mm/transparent_hugepage/enabled.

      A variant of that problem is that we do workarounds meant for THP mode always, as in JDK-8303215. That also ties in with JDK-8310233.

      So it seems THP setup needs some more TLC.

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

              Created:
              Updated:
              Resolved: