memsup(3)
πΎ memsup(3) β the memory supervisor bestie π
okay so. this is the man page for memsup, a Memory Supervisor Process, straight outta the Erlang docs. it's a <pink>3</pink> page (library function, iykyk). buckle up, we're talking RAM. π§ β¨
πΈ NAME πΈ
memsup β A Memory Supervisor Process π«Ά
β¨ DESCRIPTION β¨
so memsup is a process whose whole job β its main character energy, honestly β is supervising the memory usage of the system and of individual processes. it lives inside the OS_Mon application (go peek at os_mon π
). available for Unix and Windows, because inclusivity. π
every so often it does a little memory check, period:
- 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, []}gets set. π¨ how the amount of available memory is determined depends on the underlying OS and may change as better values become available β so don't get too attached to the method, bestie. - if any Erlang process
Pidin the system has allocated more than a certain amount of total system memory, the alarm{process_memory_high_watermark, Pid}gets set. π that one process said "i'll take everything."
alarms get reported to the SASL alarm handler, see alarm_handler. to set an alarm, alarm_handler:set_alarm(Alarm) is called where Alarm is either of the alarms specified above. periodt.
and bestie β the alarms are cleared automatically when the alarm cause is no longer valid. self-care. π
the function get_memory_data() can be used to retrieve the result of the latest periodic memory check.
there's also an interface to system dependent memory data, get_system_memory_data(). the result is highly dependent on the underlying operating system, and the interface is targeted primarily for systems without virtual memory. however, the output on other systems is still valid, although sparse. π
a call to get_system_memory_data/0 is more costly than a call to get_memory_data/0 as data is collected synchronously when this function is called. so likeβ¦ it's the expensive one. β
the total system memory reported under UNIX is the number of physical pages of memory times the page size, and the available memory is the number of available physical pages times the page size. this is a reasonable measure as swapping should be avoided anyway, but the task of defining total memory and available memory is difficult because of virtual memory and swapping. it's giving it's complicated. π
π Configuration π
the following configuration parameters can be used to change the default values for time intervals and thresholds:
memory_check_interval = int()>0β the time interval, in minutes, for the periodic memory check. the default is one minute. β°system_memory_high_watermark = float()β the threshold, as percentage of system memory, for how much system memory can be allocated before the corresponding alarm is set. the default is0.80(80%). π₯process_memory_high_watermark = float()β the threshold, as percentage of system memory, for how much system memory can be allocated by one Erlang process before the corresponding alarm is set. the default is0.05(5%). πmemsup_helper_timeout = int()>0β a timeout, in seconds, for how long thememsupprocess should wait for a result from a memory check. if the timeout expires, a warning message"OS_MON (memsup) timeout"is issued viaerror_loggerand any pending, synchronous client calls will return a dummy value. normally, this situation should not occur. there have been cases on Linux, however, where the pseudo file from which system data is read is temporarily unavailable when the system is heavily loaded. the default is 30 seconds. βmemsup_system_only = bool()β specifies whether thememsupprocess should only check system memory usage (true) or not. the default isfalse, meaning that information regarding both system memory usage and Erlang process memory usage is collected. it is recommended to set this parameter totrueon systems with many concurrent processes, as each process memory check makes a traversal of the entire list of processes. πβοΈπ¨
see config for information about how to change the value of configuration parameters.
π¦ See Also π¦
alarm_handler, os_mon
π FUNCTIONS π
get_check_interval() -> Milliseconds :: timer:time().
returns the time interval, in milliseconds, for the periodic memory check. β±οΈ
get_helper_timeout() -> Seconds :: integer().
returns the timeout value, in seconds, for memory checks.
get_memory_data() -> {Total, Allocated, Worst}
when
Total :: integer(),
Allocated :: integer(),
Worst :: {Pid, PidAllocated} | undefined,
Pid :: pid(),
PidAllocated :: integer().
returns the result of the latest memory check, where Total is the total memory size and Allocated the allocated memory size, in bytes. π
Worst is the pid and number of allocated bytes of the largest Erlang process on the node. if memsup should not collect process data β that is, if the configuration parameter memsup_system_only was set to true β Worst is undefined.
the function is normally asynchronous in the sense that it does not invoke a memory check, but returns the latest available value. the one exception is if the function is called before a first memory check is finished, in which case it does not return a value until the memory check is finished. π€ patience, bestie.
returns {0,0,{pid(),0}} or {0,0,undefined} if memsup is not available, or if all memory checks so far have timed out. π
get_os_wordsize() -> Wordsize
when Wordsize :: 32 | 64 | unsupported_os.
returns the wordsize of the current running operating system. π₯οΈ
get_procmem_high_watermark() -> integer().
returns the threshold, in percent, for process memory allocation.
get_sysmem_high_watermark() -> integer().
returns the threshold, in percent, for system memory allocation.
get_system_memory_data() -> MemDataList
when
MemDataList :: [{Tag, Size}],
Tag :: atom(),
Size :: integer().
invokes a memory check and returns the resulting, system dependent, data as a list of tagged tuples, where Tag currently can be one of the following:
total_memoryβ the total amount of memory available to the Erlang emulator, allocated and free. may or may not be equal to the amount of memory configured in the system. π€·βοΈavailable_memoryβ informs about the amount of memory that is available for increased usage if there is an increased memory need. this value is not based on a calculation of the other provided values and should give a better value of the amount of memory that actually is available than calculating a value based on the other values reported. this value is currently only present on newer Linux kernels. if this value is not available on Linux, you can use the sum ofcached_memory,buffered_memory, andfree_memoryas an approximation. π§β¨free_memoryβ the amount of free memory available to the Erlang emulator for allocation.system_total_memoryβ the amount of memory available to the whole operating system. this may well be equal tototal_memorybut not necessarily.buffered_memoryβ the amount of memory the system uses for temporary storing raw disk blocks.cached_memoryβ the amount of memory the system uses for cached files read from disk. on Linux, also memory marked as reclaimable in the kernel slab allocator will be added to this value.total_swapβ the amount of total amount of memory the system has available for disk swap.free_swapβ the amount of memory the system has available for disk swap.
NOTE: note that new tagged tuples may be introduced in the result at any time without prior notice. π no cap.
note that the order of the tuples in the resulting list is undefined and may change at any time. so don't you dare pattern match like it's a fixed order, bestie. π
all memory sizes are presented as number of bytes.
returns the empty list [] if memsup is not available, or if the memory check times out.
set_check_interval(Minutes :: non_neg_integer()) -> ok.
changes the time interval, given in minutes, for the periodic memory check.
the change will take effect after the next memory check and is non-persistent. that is, in case of a process restart, this value is forgotten and the default value will be used. see Configuration. π«
set_helper_timeout(Seconds :: non_neg_integer()) -> ok.
changes the timeout value, given in seconds, for memory checks.
the change will take effect for the next memory check and is non-persistent. that is, in the case of a process restart, this value is forgotten and the default value will be used. see Configuration above. π«
set_procmem_high_watermark(Float :: term()) -> ok.
changes the threshold, given as a float, for process memory allocation.
the change will take effect during the next periodic memory check and is non-persistent. that is, in case of a process restart, this value is forgotten and the default value will be used. see Configuration. π«
set_sysmem_high_watermark(Float :: term()) -> ok.
changes the threshold, given as a float, for system memory allocation.
the change will take effect during the next periodic memory check and is non-persistent. that is, in case of a process restart, this value is forgotten and the default value will be used. see Configuration above. π«
and that's the whole page, bestie!! π brought to you by Ericsson AB, <pink>os_mon</pink> version <pink>2.12</pink>, and the memsup(3) manual page. go forth and monitor that memory, queen. ππ¦π
π¦ where this page comes from
- nixos 26.05: erlang 29.1.2
- nixpkgs unstable: erlang 29.1.2
- ubuntu stonking: erlang-doc 1:29.0.6+dfsg-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms