RFR: 8357086: os::xxx functions returning memory size should return size_t [v13]

Anton Artemov duke at openjdk.org
Wed Jul 30 14:40:58 UTC 2025


On Tue, 29 Jul 2025 11:11:47 GMT, Stefan Karlsson <stefank at openjdk.org> wrote:

>> Anton Artemov has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 12 commits:
>> 
>>  - 8357086: Fxied return value
>>  - 8357086: Fixed whitespaces
>>  - 8357086: Introduced usage pattern
>>  - 8357086: Fixed typo
>>  - 8357086: Refactored physical_memory in different OS
>>  - 8357086: Small fixes 2
>>  - 8357086: Small fixes 1.
>>  - 8357086: Refactored physical_memory()
>>  - 8357086: Refactored free_swap_space()
>>  - 8357086: Refactored total_swap_space()
>>  - ... and 2 more: https://git.openjdk.org/jdk/compare/75ce44aa...e4698333
>
> 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.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25450#discussion_r2242929678


More information about the hotspot-dev mailing list