JDK-8300658 : memory_and_swap_limit() reporting wrong values on systems with swapaccount=0
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 21
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • CPU: generic
  • Submitted: 2023-01-19
  • Updated: 2023-02-23
  • Resolved: 2023-02-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 21
21 b11Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
JDK-8250984 and JDK-8253797 fixed this on the Java side of container support code. If reading file memory.memsw.limit_in_bytes returns an error Metrics.getMemoryAndSwapLimit() returns the memory limit (i.e. no swap). Same for cg2's memory.swap.max. Yet, on the hotspot side this isn't being treated the same way. Swap reporting is off, which yields to confusing trace output:

# podman run --rm -ti [...] --memory=200M --memory-swap=250M fedora:37
Your kernel does not support swap limit capabilities or the cgroup is not mounted. Memory limited without swap.
[root@dc3a44d5100a /]# cd /testclasses/
[root@dc3a44d5100a testclasses]# /opt/jdk/bin/java -Xlog:os+container=trace -Xbootclasspath/a:whitebox.jar -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI PrintContainerInfo | grep os,container | grep -A1 memsw.limit_in_bytes
[0.099s][trace][os,container] Path to /memory.memsw.limit_in_bytes is /sys/fs/cgroup/memory/memory.memsw.limit_in_bytes
[0.099s][debug][os,container] Open of file /sys/fs/cgroup/memory/memory.memsw.limit_in_bytes failed, No such file or directory
[0.099s][trace][os,container] Memory and Swap Limit is: 18446744073709551614

It also shows up via VM.info or hs_err files like so:

[root@dc3a44d5100a testclasses]# /opt/jdk/bin/java -Xbootclasspath/a:whitebox.jar -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI PrintContainerInfo | grep -A20 cgroup
container (cgroup) information:
container_type: cgroupv1
cpu_cpuset_cpus: 0-3
cpu_memory_nodes: 0
active_processor_count: 4
cpu_quota: no quota
cpu_period: 100000
cpu_shares: no shares
memory_limit_in_bytes: 204800 k
memory_and_swap_limit_in_bytes: not supported
memory_soft_limit_in_bytes: unlimited
memory_usage_in_bytes: 28504 k
memory_max_usage_in_bytes: 28908 k
kernel_memory_usage_in_bytes: 1196 k
kernel_memory_max_usage_in_bytes: unlimited
kernel_memory_limit_in_bytes: 1324 k
maximum number of tasks: 2048
current number of tasks: 15

KVM virtualization detected
Steal ticks since vm start: 0
Steal ticks percentage since vm start:  0.000

These:
memory_limit_in_bytes: 204800 k
memory_and_swap_limit_in_bytes: not supported

Should be:
memory_limit_in_bytes: 204800 k
memory_and_swap_limit_in_bytes: 204800 k


# cat /proc/cmdline | grep swapaccount
BOOT_IMAGE=(hd0,gpt2)/vmlinuz-5.19.7-300.fc37.x86_64 root=UUID=fcdabdd6-70cf-4a94-905d-86c966fed17d ro rootflags=subvol=root rhgb quiet systemd.unified_cgroup_hierarchy=0 swapaccount=0


Comparing this to the java level which we can see with -XshowSettings:system we see:

# /opt/jdk/bin/java -XshowSettings:system -version
Operating System Metrics:
    Provider: cgroupv1
    Effective CPU Count: 4
    CPU Period: 100000us
    CPU Quota: -1
    CPU Shares: -1
    List of Processors, 4 total: 
    0 1 2 3 
    List of Effective Processors, 4 total: 
    0 1 2 3 
    List of Memory Nodes, 1 total: 
    0 
    List of Available Memory Nodes, 1 total: 
    0 
    Memory Limit: 200.00M
    Memory Soft Limit: Unlimited
    Memory & Swap Limit: 200.00M
    Maximum Processes Limit: 2048

openjdk version "21-internal" 2023-09-19
OpenJDK Runtime Environment (fastdebug build 21-internal-adhoc.sgehwolf.jdk-jdk)
OpenJDK 64-Bit Server VM (fastdebug build 21-internal-adhoc.sgehwolf.jdk-jdk, mixed mode, sharing)

I.e. memory and swap limit match. Both are 200.00M. I.e. no swap.
Comments
Changeset: e47e9ec0 Author: Severin Gehwolf <sgehwolf@openjdk.org> Date: 2023-02-20 17:07:04 +0000 URL: https://git.openjdk.org/jdk/commit/e47e9ec05b630c82182c7843365dfd90fdaa18a0
20-02-2023

Note that JDK-8300645 fixed the trace logging for 'Memory and Swap Limit is: ' that the test change in TestMemoryWithCgroupV1.java depends on. Linking the issue.
15-02-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/12262 Date: 2023-01-27 17:09:35 +0000
27-01-2023