Integrated: 8364248: Separate commit and reservation limit detection
Joel Sikström
jsikstro at openjdk.org
Fri Aug 1 07:46:01 UTC 2025
On Tue, 29 Jul 2025 11:24:48 GMT, Joel Sikström <jsikstro at openjdk.org> wrote:
> The function os::has_allocatable_memory_limit() 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_limit() tells us both how much memory can be committed and how much virtual address space is available. On Windows, os::has_allocatable_memory_limit() 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 on Windows, and also the virtual address space cannot be limited.
>
> ZGC currently uses os::has_allocatable_memory_limit() to check if the virtual address space is limited (i.e. if there's a limit on how much memory can be reserved). To make it clear that the virtual address space cannot be limited on Windows, I propose that we create a new function called os::reserve_memory_limit(), which returns the upper-bound of how much memory can be reserved. This should just be SIZE_MAX on Windows, since the virtual address space cannot be limited.
>
> Additionally, we should rename os::has_allocatable_memory_limit() to os::commit_memory_limit(), to be more in line with os::reserve_memory_limit() and read nicely next to the os::commit_memory() and os::reserve_memory() functions. The return type of the new os::commit_memory_limit() should also only be size_t, not bool + out-parameter, to fit better next to os::reserve_memory_limit().
>
> As a follow-up, I think it is reasonable to re-visit the implementation of os::has_allocatable_memory_limit() (will be os::commit_memory_limit()) 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
This pull request has now been integrated.
Changeset: ae11d8f4
Author: Joel Sikström <jsikstro at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/ae11d8f44689502d35cb511e9ce288ab7cc0acae
Stats: 107 lines in 5 files changed: 45 ins; 38 del; 24 mod
8364248: Separate commit and reservation limit detection
Reviewed-by: stuefe, ayang
-------------
PR: https://git.openjdk.org/jdk/pull/26530
More information about the hotspot-dev
mailing list