RFR: 8315923: pretouch_memory by atomic-add-0 fragments huge pages unexpectedly

Thomas Stuefe stuefe at openjdk.org
Wed Oct 4 13:50:36 UTC 2023


On Mon, 18 Sep 2023 07:37:26 GMT, Liming Liu <duke at openjdk.org> wrote:

> As described at [JDK-8315923](https://bugs.openjdk.org/browse/JDK-8315923), this patch uses madvise with MADV_POPULATE_WRITE to pretouch memory when supported (since kernel 5.14).
> 
> Ran the newly added jtreg test on 64c Neoverse-N1 machines with kernel 4.18, 5.13 and 6.1, and observed that transparent huge pages formed right after pretouch on kernel 6.1. Recorded the time spent on the test in *seconds* with `VERBOSE=time` as the table below, and got that the patch takes improvements when the system call is supported, while does not hurt if not supported:
> 
> <table>
>   <tr>
>     <th>Kernel</th>
>     <th colspan="2"><tt>-XX:-TransparentHugePages</tt></th>
>     <th colspan="2"><tt>-XX:+TransparentHugePages</tt></th>
>   </tr>
>   <tr><td></td><td>Unpatched</td><td>Patched</td><td>Unpatched</td><td>Patched</td></tr>
>   <tr><td>4.18</td><td>11.30</td><td>11.30</td><td>0.25</td><td>0.25</td></tr>
>   <tr><td>5.13</td><td>0.22</td><td>0.22</td><td>3.42</td><td>3.42</td></tr>
>   <tr><td>6.1</td><td>0.27</td><td>0.33</td><td>3.54</td><td>0.33</td></tr>
> </table>

Hi @limingliu-ampere,

good catch.

Just to be sure, does this work with concurrent writes to the same pages? As in, it will not break https://bugs.openjdk.org/browse/JDK-8272807 ? 

Like @kimbarrett, I think this needs a better regression test. Ideally (and probably not that difficult to pull off): start the VM with AlwaysPreTouch, `-Xlog:pagesize`, and +UseTHP. Then, scan smaps to check that the heap is not splintered. Please see https://github.com/openjdk/jdk/blob/master/test/hotspot/jtreg/runtime/os/TestTracePageSizes.java . It may be that you can just extend that test to include running with UseTHP. 

I also think a small gtest would be good that tests that a pre-populated page does not lose its content when os::pretouch_memory is called. For examples, see https://github.com/openjdk/jdk/blob/master/test/hotspot/gtest/runtime/test_os.cpp.

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

PR Comment: https://git.openjdk.org/jdk/pull/15781#issuecomment-1746915692


More information about the hotspot-runtime-dev mailing list