RFR: JDK-8301749: Tracking malloc pooled memory size [v2]
    Thomas Stuefe 
    stuefe at openjdk.org
       
    Thu Feb  9 05:19:49 UTC 2023
    
    
  
On Wed, 8 Feb 2023 13:49:27 GMT, Johan Sjölen <jsjolen 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.
>
> Johan Sjölen has updated the pull request incrementally with four additional commits since the last revision:
> 
>  - Fix the test
>  - Note man section
>  - Add test
>  - Reimplement malloc_info as requested
Small nits remain, otherwise fine.
src/hotspot/os/linux/mallocInfoDcmd.cpp line 41:
> 39:   ALLOW_C_FUNCTION(::open_memstream, FILE* stream = ::open_memstream(&buf, &size);)
> 40:   if (stream == nullptr) {
> 41:     _output->print("Error: Could not call malloc_info(3)");
end with a newline? or does the caller take care of that? (same below, and the musl path)
src/hotspot/os/linux/mallocInfoDcmd.cpp line 48:
> 46:   if (err == 0) {
> 47:     ALLOW_C_FUNCTION(::fflush, fflush(stream);)
> 48:       _output->print_raw(buf);
indentation
src/hotspot/os/linux/mallocInfoDcmd.cpp line 59:
> 57:   ALLOW_C_FUNCTION(::free, ::free(buf);)
> 58: #else
> 59:     _output->print(malloc_info_unavailable);
intendation
test/hotspot/jtreg/serviceability/dcmd/vm/MallocInfoTest.java line 45:
> 43:         output.reportDiagnosticSummary();
> 44:         output.shouldNotMatch(".*Error.*");
> 45:         output.shouldMatch(".*<malloc version=.*");
small nit, you could probably get by with shouldContain here to save some cycles.
-------------
PR: https://git.openjdk.org/jdk/pull/12455
    
    
More information about the hotspot-runtime-dev
mailing list