Sub-optimal system_memory_high_watermark alarm behavior

Recently I added a memory usage warning panel to Zotonic. It shows an alert when the system_memory_high_watermark alarm is set.

Oddly enough this alert is set when the system has 60 gigs of its 64 gig ram available. Because it looks like Erlang, instead of looking at the available ram, it looks at used ram.

Screenshot 2024-08-27 at 13.59.22

Is there a way to change this behavior? Currently Erlang will set the memory alarm way too early, mainly because the OS chooses to use the available ram for buffering and caching files. When programs need this memory it will be made available.

This is the warning…

After looking at memsup I indeed see Erlang uses the percentage of used vs threshold * total to set the alarm.

%% Check if system alarm should be set/cleared
if
    Alloc > State#state.sys_mem_watermark*Total ->
        set_alarm(system_memory_high_watermark, []);
    true ->
        clear_alarm(system_memory_high_watermark)
end,

Wouldn’t it be more useful if Erlang uses the Available memory instead? I think all modern systems will try to use all the RAM available, making this alarm kind of useless.