On Tue, 1 Dec 2026 13:27:36 GMT, Erik Österlund <[email protected]> wrote:

>> On windows, our available_memory calculation excludes resident file cache 
>> memory. The ullAvailPhys we used before is the sum of the size of the 
>> standby, free, and zero lists (cf. 
>> https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-memorystatusex).
>>  This excludes resident file cache memory which will be made available if we 
>> ask for it.
>> 
>> This lack of accuracy can be quite substantial and causes AHS with ZGC to 
>> OOM prematurely because it thinks we are out of memory when actually there 
>> is plenty available when we prune file caches.
>> 
>> This patch improves the accuracy by querying the appropriate windows perf 
>> counter for the resident cache size. It's using the English counter name to 
>> make sure it works across locales. There is a configurable hard limit though 
>> that can prevent it from being prunable and the calculation takes that into 
>> account.
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> Erik Österlund has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Markus comments

src/hotspot/os/windows/os_windows.cpp line 928:

> 926:   lock->unlock();
> 927: 
> 928:   if (!valid || (cache.CStatus != PDH_CSTATUS_VALID_DATA && 
> cache.CStatus != PDH_CSTATUS_NEW_DATA) ||

This could probably be simplified:


const bool valid_status = cache.CStatus == PDH_CSTATUS_VALID_DATA ||
                          cache.CStatus == PDH_CSTATUS_NEW_DATA;
const bool valid_type = type == PERF_COUNTER_LARGE_RAWCOUNT ||
                        type == PERF_COUNTER_RAWCOUNT;

if (!valid || !valid_status || !valid_type ||
    cache.FirstValue < 0 ||
    static_cast<uint64_t>(cache.FirstValue) > total_physical) {
  return 0;
}

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

PR Review Comment: https://git.openjdk.org/jdk/pull/33895#discussion_r4754843904

Reply via email to