RFR: 8352569: NMT: mmap limits [v2]
Rui Li
duke at openjdk.org
Tue Apr 1 19:23:56 UTC 2025
> ### 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.
>
> ### Implementation
>
> Mostly it keeps the existing MallocLimit implementation that was done in [JDK-8293313](https://bugs.openjdk.org/browse/JDK-8293313), which is to check whether limit has been exceeded whenever there is a new allocation event:
> - For malloc, it's in [`Arena::grow`](https://github.com/openjdk/jdk/blob/07fd666d998cd8a485012eac4fab11b7e0f909d3/src/hotspot/share/memory/arena.cpp#L306) and [`os::malloc`](https://github.com/openjdk/jdk/blob/07fd666d998cd8a485012eac4fab11b7e0f909d3/src/hotspot/share/runtime/os.cpp#L646) (neither was changed in this pr).
> - For mmap, nmt tracks reserved regions and committed regions. Committed regions is more of our interest since it's related to RSS. I found the places where new mmap regions are committed by tracking the usages of `VirtualMemorySummary::record_committed_memory`. There are two places:
> - [`ReservedMemoryRegion::add_committed_region`](https://github.com/openjdk/jdk/blob/6891490892cc0405882658e067d587ffe5401a6d/src/hotspot/share/nmt/virtualMemoryTracker.cpp#L112), where new a mem region is committed
> - [`ReservedMemoryRegion::set_mem_tag`](https://github.com/openjdk/jdk/blob/6891490892cc0405882658e067d587ffe5401a6d/src/hotspot/share/nmt/virtualMemoryTracker.cpp#L293), where it's possible to retag a committed mem region and hence [move committed memory](https://github.com/openjdk/jdk/blob/6891490892cc0405882658e067d587ffe5401a6d/src/hotspot/share/nmt/virtualMemoryTracker.cpp#L299)
>
> Except for renaming the original `malloc` related things to more generic `nMem`, this pr keeps the original implementation and passes additional type `NMemType::Malloc` / `NMemType::Mmap` , so that each function can differentiate between these two different mem types.
Rui Li has updated the pull request incrementally with one additional commit since the last revision:
Add headers
-------------
Changes:
- all: https://git.openjdk.org/jdk/pull/24343/files
- new: https://git.openjdk.org/jdk/pull/24343/files/78b74f71..ed903bd5
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jdk&pr=24343&range=01
- incr: https://webrevs.openjdk.org/?repo=jdk&pr=24343&range=00-01
Stats: 4 lines in 1 file changed: 4 ins; 0 del; 0 mod
Patch: https://git.openjdk.org/jdk/pull/24343.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/24343/head:pull/24343
PR: https://git.openjdk.org/jdk/pull/24343
More information about the hotspot-runtime-dev
mailing list