JDK-8357570 : [macOS] os::Bsd::available_memory() might return too low values
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 25
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • CPU: generic
  • Submitted: 2025-05-22
  • Updated: 2025-12-01
  • Resolved: 2025-06-11
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 25 JDK 26
25.0.3Fixed 26 b02Fixed
Related Reports
Relates :  
Description
Currently   os::Bsd::available_memory()   returns on macOS 
vmstat.free_count * os::vm_page_size();

But just using free_count is rather conservative because there are other memory categories on macOS that can be made available too  :
https://github.com/openjdk/jdk/pull/25384/files
// Available here means free. Note that this number is of no much use. As an estimate
// for future memory pressure it is far too conservative, since MacOS will use a lot of unused memory for caches, and return it willingly in case of needs.

See also the discussion here : https://github.com/giampaolo/psutil/issues/1277
At least (parts or all of) the other memory categories  inactive_count and maybe speculative_count  .

Looking at the HS API description 
https://github.com/openjdk/jdk/blob/428d33ef3ca0af34d8f164fe9d9b722e81e866a7/src/hotspot/share/runtime/os.hpp#L336
we want to have a  distinction between "available" memory and "free memory" so adding freeable categories might make sense .


There is a bit of additional information here https://developer.apple.com/forums/thread/118867
that confirms that free memory / free_count is only a fraction of what is available :  "Specifically, any report on the amount of free memory is unlikely to be useful."  .

There is also some info here 
https://developer.apple.com/library/archive/documentation/Performance/Conceptual/ManagingMemory/Articles/AboutMemory.html#//apple_ref/doc/uid/20001880-BCICIHAB
containing this relevant info :
"The inactive list contains pages that are currently resident in physical memory but have not been accessed recently. These pages contain valid data but may be removed from memory at any time. The free list contains pages of physical memory that are not associated with any address space of VM object. These pages are available for immediate use by any process that needs them."

and also about purgeable memory at 
https://developer.apple.com/library/archive/documentation/Performance/Conceptual/ManagingMemory/Articles/CachingandPurgeableMemory.html#//apple_ref/doc/uid/TP40013104-SW1
Comments
A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk25u-dev/pull/31 Date: 2025-11-28 10:57:13 +0000
28-11-2025

[jdk25u-fix-request] Approval Request from Aleksey Shipilëv This bugfix improves MacOS reporting, and makes further backports in container code cleaner. Applies cleanly. jdk_management tests pass. Risk is low: looks like only management/diagnostic code paths are affected. No bugtail since original integration a few months ago.
28-11-2025

Changeset: 7d7fc693 Branch: master Author: Matthias Baesken <mbaesken@openjdk.org> Date: 2025-06-11 13:32:57 +0000 URL: https://git.openjdk.org/jdk/commit/7d7fc69355e6f5421cf09f93290270bb16d13182
11-06-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/25657 Date: 2025-06-05 07:53:48 +0000
05-06-2025

[~mbaesken] No idea tbh. Whatever gets us the closest to how we understand "available memory". So, whatever matches Linux' description (see poc file system doc on Linux on /proc/meminfo)
22-05-2025

[~stuefe] what categories should we add on macOS ? Is free_count + inactive_count enough ? Unfortunately the manpage I found here is not very useful : https://developer.apple.com/documentation/kernel/vm_statistics64_data_t
22-05-2025