RFR: 8352569: NMT: mmap limits [v2]

Johan Sjölen jsjolen at openjdk.org
Mon Apr 7 13:57:55 UTC 2025


On Tue, 1 Apr 2025 19:23:56 GMT, Rui Li <duke at openjdk.org> wrote:

>> ### Notes
>> 
>> With [JDK-8291878](https://bugs.openjdk.org/browse/JDK-8291878), we have a way to limit the native memory size created by malloc.
>> 
>> It'll be nice to have a counterpart for mmap. E.g., [JDK-8350860](https://bugs.openjdk.org/browse/JDK-8350860) will have a good use of mmap limit jvm arg.
>> 
>> 
>> ### Usages
>> A new jvm arg `-XX:MmapLimit` is added. Usages:
>> - Impose a global limit to mem allocated by mmap() call: `-XX:MmapLimit=<size>`. e.g.: `-XX:MmapLimit=500m`
>> - Or, impose an nmt category to mem allocated by mmap call: `-XX:MmapLimit=<category>:<size>[,category=size]`. e.g.: `-XX:MmapLimit=gc:100m`. Notice that, not every category uses mmap. E.g.: compiler category. In this case, it would behave the same as the mem limit has not been exceeded.
>> - About failure mode: by default, when the limit is exceeded, the app exits in fatal mode. If we want to mimic os oom, we can do it by appending failure mode like `-XX:MmapLimit=<size>:oom` or `-XX:MmapLimit=<category:size>:oom`. e.g.: `-XX:MmapLimit=500m:oom` or `-XX:MmapLimit=gc:100m:oom`. (`-XX:MmapLimit=500m:fatal` is equivalent to `-XX:MmapLimit=500m` since `fatal` is the default)
>> 
>> Sample error messages for fatal (`fatal` mode is default and can be omitted in the jvm arg):
>> 
>> 
>> x64 (8352569) % /workplace/ruiamzn/github/jdk/build/linux-x86_64-server-fastdebug/jdk/bin/java -XX:NativeMemoryTracking=summary -XX:MmapLimit=gc:10k -version
>> #
>> # A fatal error has been detected by the Java Runtime Environment:
>> #
>> #  Internal Error (/workplace/ruiamzn/github/jdk/src/hotspot/share/nmt/nMemoryLimitPrinter.cpp:77), pid=18248, tid=18249
>> #  fatal error: MmapLimit: reached category "mtGC" limit (triggering allocation size: 836K, allocated so far: 836K, limit: 10240B) 
>> #
>> # JRE version:  (25.0) (fastdebug build )
>> # Java VM: OpenJDK 64-Bit Server VM (fastdebug 25-internal-adhoc.ruiamzn.jdk, mixed mode, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
>> # Problematic frame:
>> # V  [libjvm.so+0x153a4a2]  NMemoryLimitPrinter::category_limit_reached(MemTag, unsigned long, unsigned long, nMemlimit const*, NMemType)+0x182
>> #
>> # Core dump will be written. Default location: /workplace/ruiamzn/github/jdk/core.18248
>> #
>> # An error report file with more information is saved as:
>> # /workplace/ruiamzn/github/jdk/hs_err_pid18248.log
>> 
>> 
>> Sample error messages for oom:
>> 
>> x64 (8352569) % /workplace/ruiamzn/github/jdk/build/linux-x86_64-server-fastdebug/jdk/bin/java -XX:Na...
>
> Rui Li has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Add headers

I'd prefer it if we can expand the name to `NativeMemoryLimit` and not use abbreviations so much. Some names (`_glob`, `_cat`) are pre-existing, but they should also be expanded to `_global` and `_categories`.


I'm still working on reviewing this. It's hard to review through Github. As GH can't recognise that the file has been moved, I can't see what's old and what's new code.

src/hotspot/share/nmt/nMemLimit.hpp line 45:

> 43: };
> 44: 
> 45: struct nMemlimit {

Style: Same NamingStyle as for classes, please.

src/hotspot/share/nmt/nMemLimit.hpp line 51:

> 49: 
> 50: // forward declaration
> 51: class outputStream;

Style: Remove the `// forward declaration` comment, and move it up right after the includes.

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

PR Review: https://git.openjdk.org/jdk/pull/24343#pullrequestreview-2746892523
PR Review Comment: https://git.openjdk.org/jdk/pull/24343#discussion_r2031290534
PR Review Comment: https://git.openjdk.org/jdk/pull/24343#discussion_r2031282923


More information about the hotspot-runtime-dev mailing list