mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8253727: [cgroups v2] Memory and swap limits reported incorrectly
Account for interface files for swap and memory being reported independently. The cgroup v1-like value is now reported by adding the memory.max value to the memory.swap.max value, and memory.current and memory.swap.current respectively. Reviewed-by: bobv, shade
This commit is contained in:
parent
7779ce9fb4
commit
3e96721cd9
3 changed files with 47 additions and 5 deletions
|
@ -274,15 +274,37 @@ public class CgroupV2Subsystem implements CgroupSubsystem {
|
|||
return CgroupV2SubsystemController.getLongEntry(unified, "memory.stat", "sock");
|
||||
}
|
||||
|
||||
/**
|
||||
* Note that for cgroups v2 the actual limits set for swap and
|
||||
* memory live in two different files, memory.swap.max and memory.max
|
||||
* respectively. In order to properly report a cgroup v1 like
|
||||
* compound value we need to sum the two values. Setting a swap limit
|
||||
* without also setting a memory limit is not allowed.
|
||||
*/
|
||||
@Override
|
||||
public long getMemoryAndSwapLimit() {
|
||||
String strVal = CgroupSubsystemController.getStringValue(unified, "memory.swap.max");
|
||||
return limitFromString(strVal);
|
||||
long swapLimit = limitFromString(strVal);
|
||||
if (swapLimit >= 0) {
|
||||
long memoryLimit = getMemoryLimit();
|
||||
assert memoryLimit >= 0;
|
||||
return memoryLimit + swapLimit;
|
||||
}
|
||||
return swapLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note that for cgroups v2 the actual values set for swap usage and
|
||||
* memory usage live in two different files, memory.current and memory.swap.current
|
||||
* respectively. In order to properly report a cgroup v1 like
|
||||
* compound value we need to sum the two values. Setting a swap limit
|
||||
* without also setting a memory limit is not allowed.
|
||||
*/
|
||||
@Override
|
||||
public long getMemoryAndSwapUsage() {
|
||||
return getLongVal("memory.swap.current");
|
||||
long swapUsage = getLongVal("memory.swap.current");
|
||||
long memoryUsage = getMemoryUsage();
|
||||
return memoryUsage + swapUsage;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue