diff --git a/src/hotspot/os/linux/os_linux.cpp b/src/hotspot/os/linux/os_linux.cpp index 20d3c99cd3e..00ee3519301 100644 --- a/src/hotspot/os/linux/os_linux.cpp +++ b/src/hotspot/os/linux/os_linux.cpp @@ -314,7 +314,10 @@ static jlong host_free_swap() { } jlong os::free_swap_space() { - jlong host_free_swap_val = host_free_swap(); + // os::total_swap_space() might return the containerized limit which might be + // less than host_free_swap(). The upper bound of free swap needs to be the lower of the two. + jlong host_free_swap_val = MIN2(os::total_swap_space(), host_free_swap()); + assert(host_free_swap_val >= 0, "sysinfo failed?"); if (OSContainer::is_containerized()) { jlong mem_swap_limit = OSContainer::memory_and_swap_limit_in_bytes(); jlong mem_limit = OSContainer::memory_limit_in_bytes();