RFR: 8364248: Separate memory limit detection

Joel Sikström jsikstro at openjdk.org
Tue Jul 29 11:34:07 UTC 2025


The function os::has_allocatable_memory() is intended to determine whether there is a system-imposed limit on how much memory can be committed, and if so, what that limit is. On POSIX systems, limiting committable memory is typically enforced by restricting the available virtual address space, such as via RLIMIT_AS. As a result, os::has_allocatable_memory() tells us both how much memory can be committed and how much virtual address space is available. On Windows however, os::has_allocatable_memory() always returns true, along with the size of the available virtual address space. This is misleading because it is not possible to limit how much memory can be committed via virtual address space, and also the virtual address space cannot be limited.

ZGC currently uses os::has_allocatable_memory() to check if the virtual address space is limited. To make it clear that the virtual address space cannot be limited on Windows, I propose that we create a new function called os::has_limited_virtual_address_space() which simply returns false on Windows, since the virtual address space cannot be limited there.

As a follow-up, I think it is reasonable to re-visit the implementation of os::has_allocatable_memory() on Windows, since it doesn't follow any user-set limits, apart from how much virtual memory is available. Perhaps looking at limit(s) set by Job Objects could be more fruitful, and would improve the support for native Windows containers (Hyper-V).

Testing:
* Oracle's tier1-2
* Manual testing on Linux by limiting the virtual address space:

$ ulimit -v 8388608 && java -XX:+UseZGC -Xlog:gc+init -version

-------------

Commit messages:
 - 8364248: Separate memory limit detection

Changes: https://git.openjdk.org/jdk/pull/26530/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=26530&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8364248
  Stats: 38 lines in 4 files changed: 26 ins; 7 del; 5 mod
  Patch: https://git.openjdk.org/jdk/pull/26530.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/26530/head:pull/26530

PR: https://git.openjdk.org/jdk/pull/26530


More information about the hotspot-gc-dev mailing list