RFR: 8352569: NMT: mmap limits [v2]
Erik Österlund
eosterlund at openjdk.org
Mon Apr 7 16:59:49 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
What problem does this feature solve?
-------------
PR Comment: https://git.openjdk.org/jdk/pull/24343#issuecomment-2784005934
More information about the hotspot-runtime-dev
mailing list