JDK-8310841 : Obsolete the UseSHM and UseHugeTLBFS flags in JDK 22
  • Type: CSR
  • Component: hotspot
  • Sub-Component: gc
  • Priority: P4
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 22
  • Submitted: 2023-06-24
  • Updated: 2023-07-11
  • Resolved: 2023-07-11
Related Reports
CSR :  
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() },
```


- [1] https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt
- [2] https://mail.openjdk.org/pipermail/hotspot-dev/2023-June/075924.html
- [3] https://bugs.openjdk.org/browse/JDK-7034464
- [4] https://github.com/openjdk/jdk6/commit/c796d80b281c81bee156919378d9afec8c85c220


Comments
Moving to Approved.
11-07-2023

I've made a slight editorial pass over the text. [~stuefe] CSR requests should not be proposed until they have one or more reviewers. Please move this back to Draft. I will then add myself as a Reviewer and then the request can be Finalized. Thanks.
03-07-2023

We need a "Specification" section to show how the flags have been modified. IIUC the title should be "Obsolete the UseSHM and UseHugeTLBFS flags in JDK 22". The solution and summary should state they will be removed (expired) in JDK 23. > That causes the UseSHM code path to subtly bitrot and had caused efforts in the past. This sentence doesn't read correctly.
30-06-2023