RFR: JDK-8325139: JFR SwapSpace event - add free swap space information on Linux when running in a container environment [v5]

Matthias Baesken mbaesken at openjdk.org
Thu Feb 29 09:11:55 UTC 2024


On Wed, 28 Feb 2024 15:03:12 GMT, Severin Gehwolf <sgehwolf at openjdk.org> wrote:

>> Matthias Baesken has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   adjust CgroupV1Subsystem::memory_and_swap_usage_in_bytes
>
> src/hotspot/os/linux/cgroupV1Subsystem_linux.cpp line 174:
> 
>> 172:   // isSwapEnabled - maybe compute once and save?
>> 173:   GET_CONTAINER_INFO(julong, _memory->controller(), "/memory.memsw.limit_in_bytes", "Memory and Swap Limit is: ", JULONG_FORMAT, JULONG_FORMAT, memsw_bytes);
>> 174:   GET_CONTAINER_INFO(julong, _memory->controller(), "/memory.swappiness", "Swappiness is: ", JULONG_FORMAT, JULONG_FORMAT, swappiness);
> 
> Why are you reading the memory and swap limit by means of the low level files here? I think what you want to know is whether or not swap is enabled. Note that the `GET_CONTAINER_INFO` macro returns a `julong` (sometimes a negative value cast to `julong`). So you'd need to account for that.
> 
> I suggest something like this:
> 
> 
>    jlong memory_sw_limit = memory_and_swap_limit_in_bytes();
>    jlong memory_limit = CgroupSubsystem::memory_limit_in_bytes();
>    if (memory_sw_limit > 0 && memory_limit > 0) {
>        jlong delta_swap = memory_sw_limit - memory_limit;
>        if (delta_swap > 0) {
>                   GET_CONTAINER_INFO(julong, _memory->controller(), "/memory.memsw.usage_in_bytes",
>                      "mem swap usage is: ", JULONG_FORMAT, JULONG_FORMAT, memory_swap_usage);
>                 return (jlong)memory_swap_usage;
>        } else {
>           // no swap
>           return 0;
>        }
>        return memory_usage_in_bytes();
>    }

Thanks for the suggestion, I adjusted the coding .  Should I add some UL logging in case of negative values returned?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/17966#discussion_r1507244991


More information about the hotspot-runtime-dev mailing list