From de55db2352f84c101f8197ee7aca80d72807fbc5 Mon Sep 17 00:00:00 2001 From: Matthias Baesken Date: Mon, 10 Jun 2024 08:14:23 +0000 Subject: [PATCH] 8333522: JFR SwapSpace event might read wrong free swap space size Reviewed-by: sgehwolf, lucy --- src/hotspot/os/linux/os_linux.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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();