RFR: JDK-8301749: Tracking malloc pooled memory size
Thomas Stuefe
stuefe at openjdk.org
Wed Feb 8 07:57:01 UTC 2023
On Wed, 8 Feb 2023 02:41:13 GMT, David Holmes <dholmes at openjdk.org> wrote:
>> This PR implements `os::malloc_info` by calling into glibc's `malloc_info` and provides a JCmd for asking the JVM to call `malloc_info` and print out the results. The user can make an informed decision regarding heap trimming by parsing the output of the JCmd. I wanted to avoid parsing the XML inside of the JVM , as this functionality may turn out to be "good enough". A future enhancement would be for the JVM to make this informed decision by parsing the output. Another may be to present this with other data, for example in NMT.
>>
>> @tstuefe, I think you'd be interested in this PR as it builds upon your `trim_native_heap` functionality.
>>
>> I'm using weak symbols (as per ELF) in order to compile this for both GLibc and Musl.
>>
>> The original bug description is this:
>>
>>>Memory not allocated via NMT and uncommitted memory contributes to a discrepancy between NMT and RSS.
>> It can be hard to distinguish between these cases.
>> If the VM can determine the amount of pooled memory by malloc it would help with both determining if a trim_native_memory is needed, or there are some allocations happening outside of NMT.
>>>
>>>It would be good if the VM can summarize the malloc pooled memory by using e.g. malloc_info(3).
>>>
>>>We can thus more precise account for RSS value.
>
> src/hotspot/os/linux/mallocInfoDcmd.cpp line 35:
>
>> 33:
>> 34: void MallocInfoDcmd::execute(DCmdSource source, TRAPS) {
>> 35: #ifdef LINUX
>
> This is a linux-only file. ???
Yes, this is all Linux. Instead, guard with GLIBC, and print in the else branch something like "not a glibc platform".
> src/hotspot/os/linux/os_linux.cpp line 224:
>
>> 222:
>> 223: int os::Linux::malloc_info(FILE* stream) {
>> 224: if (::malloc_info) {
>
> This looks strange as an existence check for a library function. At build time what does this get compiled into such that it runtime it can determine whether `malloc_info` exists or not ??
>
> (also style rules say no implicit booleans so check against nullptr or 0).
I agree, this looks weird. Please do as the Romans do (in this case, as we do with mallinfo/mallinfo2()). Just follow the breadcrumbs.
Additionally, I would put this alongside os::Linux::get_mallinfo and guard it with ifdef GLIBC. You don't need this on muslc.
-------------
PR: https://git.openjdk.org/jdk/pull/12455
More information about the hotspot-runtime-dev
mailing list