[macOS] os::Bsd::available_memory() might return too low values

XMLWordPrintable

    • b02
    • generic
    • os_x

        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

              Assignee:
              Matthias Baesken
              Reporter:
              Matthias Baesken
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated:
                Resolved: