<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jun 26, 2023 at 9:19 AM Stefan Karlsson <<a href="mailto:stefan.karlsson@oracle.com">stefan.karlsson@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I'm asking around to see if I can get an answer how important UseSHM is.<br>
<br>
StefanK<br></blockquote><div><br></div><div>Thank you, Stefan.</div><div><br></div>I did some deeper digging into its history:<br><br>Huge page support using System V shmget predates OpenJDK. The moniker "special", as in "reserve_memory_special()", is also from the initial load.<br><br>Huge page support using mmap had been introduced by JDK-7034464 [1] into JDK 6 [2]. This patch also introduced UseSHM and UseHugeTLBFS. From that point on, mmap-based reservation had been the default, shmget the fallback.<br><br>Comments during review [3] and in the patch suggest that mmap support for TLBFS had been unreliable, and therefore SHM support had been retained as fallback. Looking at the API manpages (shmget and mmap), TLBFS support, there is a version difference (shmget: Linux 2.6, mmap: Linux 2.6.32). If that is not a documentation fluke, there may have been a time window within which mmap support for MAP_HUGETLBFS was flaky. <br><br>I also found mentions of "mmap not being able to use huge pages for anonymous mappings"; this is not true anymore. I looked through the kernel changelogs for kernel 2.6, but could find no explicit mentioning of mmap hugetlb support fixes wrt anonymous mappings. There was, however, a lot of activity for hugetlbfs support so that it may be the 2.6.xx kernel was stabilizing tlbfs support and things had been flaky.<br><br>As an interesting side note, one of the advantages cited for mmap was the ability to uncommit and re-commit arbitrary pages from the range. While true, we stopped doing that with JDK-8007074 [5][6], since the re-commit of these pages cannot be guaranteed (technically also true for small pages, but much more probable for explicit hugepages). Since then, we keep hugepages as committed, and since then today's "special" flag found in various places is synonymous for "precommitted, don't uncommit".<br><br>Linux 2.6 is EOL. The lowest still supported kernel seems to be 3.16. I believe cutting SHM support from JDK 22 onwards should be safe.<br><br>[1] <a href="https://bugs.openjdk.org/browse/JDK-7034464">https://bugs.openjdk.org/browse/JDK-7034464</a> <br>[2] <a href="https://github.com/openjdk/jdk6/commit/c796d80b281c81bee156919378d9afec8c85c220">https://github.com/openjdk/jdk6/commit/c796d80b281c81bee156919378d9afec8c85c220</a><br>[3] <a href="https://mail.openjdk.org/pipermail/hotspot-dev/2011-April/004079.html">https://mail.openjdk.org/pipermail/hotspot-dev/2011-April/004079.html</a><br>[4] <a href="https://mirrors.edge.kernel.org/pub/linux/kernel/v2.6/">https://mirrors.edge.kernel.org/pub/linux/kernel/v2.6/</a><br>[5] <a href="https://bugs.openjdk.org/browse/JDK-8007074">https://bugs.openjdk.org/browse/JDK-8007074</a> <br>[6] <a href="https://github.com/openjdk/jdk8u/commit/7ade7987a0a8ccfde017811623d338b4c4b80237">https://github.com/openjdk/jdk8u/commit/7ade7987a0a8ccfde017811623d338b4c4b80237</a><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
On 2023-06-23 14:11, Thomas Stüfe wrote:<br>
> Hi all,<br>
><br>
> We talked about this [1] and StefanJ opened an issue open for it [2], <br>
> and also I had private talks with various people. I am currently <br>
> digging around in LP initialization again, and getting rid of SHM mode <br>
> would be so nice. Perfect time for it too, just after LTS fork-off.<br>
><br>
> SHM tlbfs mode causes a lot of extra complexity. Since SHM segments <br>
> can only be detached as a whole, they behave more like Windows <br>
> VirtualSpace instead of mmap. As in, the whole mapping cannot be <br>
> split, cannot be partially uncommitted etc. As StefanJ pointed out in <br>
> [2], it also requires more permissions than mmap-tlbfs mode.<br>
><br>
> I have always had the suspicion that this is a dusty corner of hotspot <br>
> that is rarely used and probably broken in many corner cases. For <br>
> example, the sanity checks at VM startup are not correctly <br>
> implemented, see JDK-8310262<br>
><br>
> Therefore, unless someone knows a good reason against removal, I would <br>
> like to remove SHM mode from hotspot.<br>
><br>
> We could get rid of both -XX:+UseSHM and -XX:+UseHugeTLBFS, since one <br>
> is the negation of the other. Large page support on Linux would become <br>
> a lot simpler then and just a matter of: +UseLargePages and +-UseTHP. <br>
> A nice complexity reduction, and we could get rid of a many tests too.<br>
><br>
> (Obviously, this would need a CSR and Release notes etc).<br>
><br>
> Any objections?<br>
><br>
> Thanks, Thomas<br>
><br>
> [1] <br>
> <a href="https://mail.openjdk.org/pipermail/hotspot-dev/2020-December/046885.html" rel="noreferrer" target="_blank">https://mail.openjdk.org/pipermail/hotspot-dev/2020-December/046885.html</a><br>
> [2] <a href="https://bugs.openjdk.org/browse/JDK-8261894" rel="noreferrer" target="_blank">https://bugs.openjdk.org/browse/JDK-8261894</a><br>
> [3] <a href="https://bugs.openjdk.org/browse/JDK-8310262" rel="noreferrer" target="_blank">https://bugs.openjdk.org/browse/JDK-8310262</a><br>
<br>
</blockquote></div></div>