RFR: 8357086: os::xxx functions returning memory size should return size_t [v13]
Stefan Karlsson
stefank at openjdk.org
Wed Jul 30 15:09:42 UTC 2025
On Wed, 30 Jul 2025 14:37:49 GMT, Anton Artemov <duke at openjdk.org> wrote:
>> src/hotspot/os/linux/os_linux.cpp line 297:
>>
>>> 295: if (OSContainer::is_containerized()) {
>>> 296: if (OSContainer::memory_limit_in_bytes() > 0) {
>>> 297: value = static_cast<size_t>(OSContainer::memory_and_swap_limit_in_bytes() - OSContainer::memory_limit_in_bytes());
>>
>> I might have wondered about this before, but can't `memory_and_swap_limit_in_bytes` return `-1` even when `memory_limit_in_bytes > 0` since -1 is treated as an "unlimited limit" here:
>>
>> jlong CgroupV1MemoryController::read_mem_swap(julong host_total_memsw) {
>> julong memswlimit;
>> CONTAINER_READ_NUMBER_CHECKED(reader(), "/memory.memsw.limit_in_bytes", "Memory and Swap Limit", memswlimit);
>> if (memswlimit >= host_total_memsw) {
>> log_trace(os, container)("Memory and Swap Limit is: Unlimited");
>> return (jlong)-1;
>> }
>>
>> Maybe this will be handled in a cleanup to the container subsystem?
>
> I think we have discussed it above. In `os::free_swap_space(size_t& value)` implementation in `os_linux.cpp` the value returned by `OSContainer::memory_and_swap_limit_in_bytes()` is kept in a signed variable of `jlong` type. Then, if that value is negative, `host_free_swap_val` value will be returned, as that one is non-negative.
My comment above is for the `total_swap_space` function and not the `free_swap_space` function.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25450#discussion_r2243020588
More information about the hotspot-dev
mailing list