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

Obsolete the UseSHM and UseHugeTLBFS flags in JDK 22

    XMLWordPrintable

Details

    • CSR
    • Resolution: Approved
    • P4
    • 22
    • hotspot
    • gc
    • behavioral
    • low
    • Hide
      Both switches will continue to be accepted, but the JVM will ignore them and print a warning. These warnings may inconvenience existing installations that set one of these switches.

      The sole remaining code path (mmap-based) is well supported and stable in today's Linuxes; I don't expect any problems.

      I did a google- and github search for UseSHM in particular. I found nothing of note (albeit quite some confused, wrong explanations; getting rid of these switches will be good for clarity too).
      Show
      Both switches will continue to be accepted, but the JVM will ignore them and print a warning. These warnings may inconvenience existing installations that set one of these switches. The sole remaining code path (mmap-based) is well supported and stable in today's Linuxes; I don't expect any problems. I did a google- and github search for UseSHM in particular. I found nothing of note (albeit quite some confused, wrong explanations; getting rid of these switches will be good for clarity too).

    Description

      Summary

      Obsolete the UseSHM and UseHugeTLBFS flags in JDK 22 and expire them in JDK 23.

      Problem

      On Linux, with -XX:+UseLargePages, the JVM supports two modes to allocate static (non-transparent) hugepages:

      • using mmap(2), controlled by UseHugeTLBFS
      • using shmget(2), controlled by UseSHM

      Keeping both switches and code paths is an unnecessary technical debt and increases maintenance costs.

      Both ways control the same backend functionality in the kernel [1]. The only difference is the API entry point. Short history - please see [2] for more details:

      The shmget-based implementation came first, preceding the initial OpenJDK code drop.

      With JDK 6, JDK-7034464 [3][4] introduced mmap-based static hugepage allocation. The old shmget code path was preserved as a precaution. Two switches were introduced: UseSHM and UseHugeTLBFS. One is the negation of the other (in hindsight, a single boolean or mode switch would have been better).

      Since JDK 6, UseHugeTLBFS had been the default, UseSHM the fallback if mmap failed.

      Both hugepage allocation paths are equally well supported since Linux 2.6. That is ancient and EOL.

      I believe that in practice UseSHM - and hence shmget - usage dropped to almost zero since JDK 6 because:

      • there is no benefit of explicitly enforcing -XX:+UseSHM
      • situations where UseHugeTLBFS would fail but UseSHM succeed are unknown - in fact, it can be the other way around since shmget may lack permissions that mmap does not need.

      Since UseSHM has been rarely used, it is prone to bitrot. In addition, the semantics of using large page reservations with shmget differs from mmap, since shmget reservations cannot be split. But that property is not well abstracted for upper layers, and there may be broken corner cases (e.g., in NMT).

      Solution

      Remove the coding underlying UseSHM.

      Obsolete UseSHM.

      Since the only remaining implementation is the one backing UseHugeTLBFS, and there is no alternative, we can also obsolete UseHugeTLBFS.

      Specification

      diff --git a/src/hotspot/os/linux/globals_linux.hpp b/src/hotspot/os/linux/globals_linux.hpp
      index 9dc070233fe..aa419cd0d25 100644
      --- a/src/hotspot/os/linux/globals_linux.hpp
      +++ b/src/hotspot/os/linux/globals_linux.hpp
      @@ -44,18 +44,12 @@
         product(bool, UseLinuxPosixThreadCPUClocks, true,                     \
                 "enable fast Linux Posix clocks where available")             \
                                                                               \
      -  product(bool, UseHugeTLBFS, false,                                    \
      -          "Use MAP_HUGETLB for large pages")                            \
      -                                                                        \
         product(bool, UseTransparentHugePages, false,                         \
                 "Use MADV_HUGEPAGE for large pages")                          \
                                                                               \
         product(bool, LoadExecStackDllInVMThread, true,                       \
                 "Load DLLs with executable-stack attribute in the VM Thread") \
                                                                               \
      -  product(bool, UseSHM, false,                                          \
      -          "Use SYSV shared memory for large pages")                     \
      -                                                                        \
         product(bool, UseContainerSupport, true,                              \
                 "Enable detection and runtime container configuration support") \
                                                                               \
      diff --git a/src/hotspot/share/runtime/arguments.cpp b/src/hotspot/share/runtime/arguments.cpp
      index 210635f9bd2..d23eeaa7842 100644
      --- a/src/hotspot/share/runtime/arguments.cpp
      +++ b/src/hotspot/share/runtime/arguments.cpp
      @@ -523,6 +523,10 @@ static SpecialFlag const special_jvm_flags[] = {
         { "G1ConcRSHotCardLimit",         JDK_Version::undefined(), JDK_Version::jdk(21), JDK_Version::undefined() },
         { "RefDiscoveryPolicy",           JDK_Version::undefined(), JDK_Version::jdk(21), JDK_Version::undefined() },
         { "MetaspaceReclaimPolicy",       JDK_Version::undefined(), JDK_Version::jdk(21), JDK_Version::undefined() },
      +#ifdef LINUX
      +  { "UseHugeTLBFS",                 JDK_Version::undefined(), JDK_Version::jdk(22), JDK_Version::jdk(23) },
      +  { "UseSHM",                       JDK_Version::undefined(), JDK_Version::jdk(22), JDK_Version::jdk(23) },
      +#endif
      
       #ifdef ASSERT
         { "DummyObsoleteTestFlag",        JDK_Version::undefined(), JDK_Version::jdk(18), JDK_Version::undefined() },

      Attachments

        Issue Links

          Activity

            People

              stuefe Thomas Stuefe
              sjohanss Stefan Johansson
              David Holmes
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: