JDK-8299858 : [Metrics] Swap memory limit reported incorrectly when too large
  • Type: Bug
  • Component: core-svc
  • Sub-Component: java.lang.management
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • CPU: generic
  • Submitted: 2023-01-10
  • Updated: 2024-04-15
  • Resolved: 2023-01-26
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 11 JDK 17 JDK 21
11.0.24Fixed 17.0.12Fixed 21 b08Fixed
Related Reports
Relates :  
Relates :  
Description
This bug is related to JDK-8292541 which fixed the reported memory limit when it (potentially) exceeds physical host memory. However, a similar issue can happen with Metrics.getMemoryAndSwapLimit(), when the memory limit exceeds host swap limit. That should also not happen.

Host system:
$ free -b
               total        used        free      shared  buff/cache   available
Mem:     67174510592 11629891584 32003850240  1106583552 23540768768 53689348096
Swap:     8589930496     3145728  8586784768

I.e. total host swap is '8589930496' (8 GB). Total system memory is 64 GB. The container should not be allowed to exceed the host memory and host swap values (8+64 = 72GB).

Reproducer:

$ sudo podman run --rm -ti -v $(pwd)/build/linux-x86_64-server-fastdebug/images/jdk:/opt/jdk:z --memory 671745105920 --memory-swap 671745105920 fedora:37 /opt/jdk/bin/java -XshowSettings:system -version
Operating System Metrics:
    Provider: cgroupv1
    Effective CPU Count: 12
    CPU Period: 100000us
    CPU Quota: -1
    CPU Shares: -1
    List of Processors, 12 total: 
    0 1 2 3 4 5 6 7 8 9 10 11 
    List of Effective Processors, 12 total: 
    0 1 2 3 4 5 6 7 8 9 10 11 
    List of Memory Nodes, 1 total: 
    0 
    List of Available Memory Nodes, 1 total: 
    0 
    Memory Limit: Unlimited
    Memory Soft Limit: Unlimited
    Memory & Swap Limit: 625.61G
    Maximum Processes Limit: 2048

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

Note the Memory and Swap Limit of '625.61G' It should be 'Unlimited' (=> use host values).
Comments
jdk11u-dev backport request I would like to have that patch in jdk11u-dev as well, because the issue is present there too. The backport is clean and low-to-medium risk.
11-04-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk11u-dev/pull/2644 Date: 2024-04-10 14:27:04 +0000
10-04-2024

jdk17u-dev backport request I would like to have that patch in jdk17u-dev as well, because the issue is present there too. The backport is clean and low-to-medium risk.
11-03-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk17u-dev/pull/2285 Date: 2024-03-11 13:49:42 +0000
11-03-2024

[~mbaesken] It could be, but it's less critical than JDK-8292541 I'd say. Feel free to go ahead and backport it.
11-03-2024

> This bug is related to JDK-8292541 JDK-8292541 has been backported to 17, so should we backport this one too at least to jdk17 ?
11-03-2024

Changeset: 64ddf953 Author: Severin Gehwolf <sgehwolf@openjdk.org> Date: 2023-01-26 14:50:46 +0000 URL: https://git.openjdk.org/jdk/commit/64ddf9536f55fb81956ebde6dfc0a3c4147af371
26-01-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/12118 Date: 2023-01-20 15:53:09 +0000
20-01-2023

Adding link to JDK-8300659 as this fix depends on that refactoring in the test.
19-01-2023