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).