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." .
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." .
- relates to
-
JDK-8334513 New test gc/TestAlwaysPreTouchBehavior.java is failing on MacOS aarch64
-
- Resolved
-