Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os_mon: Fix use available mem for system_memory_high_watermark alarm #8776

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/os_mon/c_src/memsup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/os_mon/src/memsup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions lib/os_mon/test/memsup_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading