Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDK-8324287: Record total and free swap space in JFR #17581

Closed
wants to merge 7 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions src/hotspot/os/linux/os_linux.cpp
Original file line number Diff line number Diff line change
@@ -291,25 +291,30 @@ julong os::Linux::free_memory() {

jlong os::total_swap_space() {
if (OSContainer::is_containerized()) {
return (jlong)(OSContainer::memory_and_swap_limit_in_bytes() - OSContainer::memory_limit_in_bytes());
} else {
struct sysinfo si;
int ret = sysinfo(&si);
if (ret != 0) {
return -1;
if (OSContainer::memory_limit_in_bytes() > 0) {
return (jlong)(OSContainer::memory_and_swap_limit_in_bytes() - OSContainer::memory_limit_in_bytes());
}
return (jlong)(si.totalswap * si.mem_unit);
}
}

jlong os::free_swap_space() {
// TODO support free swap space in container APIs
struct sysinfo si;
int ret = sysinfo(&si);
if (ret != 0) {
return -1;
}
return (jlong)(si.freeswap * si.mem_unit);
return (jlong)(si.totalswap * si.mem_unit);
}

jlong os::free_swap_space() {
if (OSContainer::is_containerized()) {
// TODO add a good implementation
return -1;
} else {
struct sysinfo si;
int ret = sysinfo(&si);
if (ret != 0) {
return -1;
}
return (jlong)(si.freeswap * si.mem_unit);
}
}

julong os::physical_memory() {
3 changes: 2 additions & 1 deletion test/jdk/jdk/jfr/event/os/TestSwapSpaceEvent.java
Original file line number Diff line number Diff line change
@@ -50,7 +50,8 @@ public static void main(String[] args) throws Throwable {
for (RecordedEvent event : events) {
System.out.println("Event: " + event);
long totalSize = Events.assertField(event, "totalSize").atLeast(0L).getValue();
Events.assertField(event, "freeSize").atLeast(0L).atMost(totalSize);
Events.assertField(event, "freeSize").atLeast(-1L); // we still get on Linux -1 in container envs
Events.assertField(event, "freeSize").atMost(totalSize);
}
}
}