diff --git a/lib/os_mon/c_src/memsup.c b/lib/os_mon/c_src/memsup.c index 96f662da1940..ad4a193d99ba 100644 --- a/lib/os_mon/c_src/memsup.c +++ b/lib/os_mon/c_src/memsup.c @@ -446,9 +446,10 @@ get_extended_mem_apple(memory_ext *me) { } me->free = vm_stat.free_count * mach_page_size; + me->available = (vm_stat.inactive_count + vm_stat.free_count) * mach_page_size; me->total = total_memory_size; me->pagesize = 1; - me->flag = F_MEM_TOTAL | F_MEM_FREE; + me->flag = F_MEM_TOTAL | F_MEM_FREE | F_MEM_AVAIL; } #endif @@ -508,7 +509,11 @@ get_basic_mem(unsigned long *tot, unsigned long *used, unsigned long *pagesize){ } *tot = me.total; *pagesize = me.pagesize; - *used = me.total - me.free; + if (me.flag & F_MEM_AVAIL) { + *used = me.total - me.available; + } else { + *used = me.total - me.free; + } #elif defined(BSD4_4) struct vmtotal vt; long pgsz; @@ -535,9 +540,9 @@ get_basic_mem(unsigned long *tot, unsigned long *used, unsigned long *pagesize){ #elif defined(__APPLE__) { memory_ext me; - me.free = 0; + me.available = 0; get_extended_mem_apple(&me); - *used = me.total - me.free; + *used = me.total - me.available; *tot = total_memory_size; *pagesize = 1; } diff --git a/lib/os_mon/src/memsup.erl b/lib/os_mon/src/memsup.erl index be8188989cfd..6bd6f7df0672 100644 --- a/lib/os_mon/src/memsup.erl +++ b/lib/os_mon/src/memsup.erl @@ -29,7 +29,9 @@ Periodically performs a memory check: - If more than a certain amount of available system memory is allocated, as reported by the underlying operating system, the alarm - `{system_memory_high_watermark, []}` is set. + `{system_memory_high_watermark, []}` is set. How the amount of available + memory is determined depends on the underlying OS and may change as better + values become available. - If any Erlang process `Pid` in the system has allocated more than a certain amount of total system memory, the alarm `{process_memory_high_watermark, Pid}` is set. diff --git a/lib/os_mon/test/memsup_SUITE.erl b/lib/os_mon/test/memsup_SUITE.erl index 1f66ea0afac4..262d3a669625 100644 --- a/lib/os_mon/test/memsup_SUITE.erl +++ b/lib/os_mon/test/memsup_SUITE.erl @@ -758,6 +758,9 @@ improved_system_memory_data(Config) when is_list(Config) -> _ -> {comment, "No available_memory present in result"} end; + {unix,darwin} -> + true = AvailableMemoryPresent, + {comment, "available_memory present in result"}; _ -> ok end.