memsup(3erl)
โจ memsup(3erl) โ the memory supervisor bestie โจ
Okay so <pink>memsup</pink> is literally a Memory Supervisor Process and it's part of the OS_Mon application (go peek at os_mon(7) for the full tea). It works on Unix and Windows, no cap. ๐ซถ
๐ DESCRIPTION ๐
So <hotpink>memsup</hotpink> is this icon of a process that supervises memory usage โ both for the whole system and for individual processes. Main character energy fr fr. It periodically does a memory check, and here's what goes down:
- If more than a certain amount of available system memory is allocated (as reported by the underlying operating system, not vibes), the alarm
{system_memory_high_watermark, []}gets set. - 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.
Alarms get reported to the SASL alarm handler โ see alarm_handler(3erl). To set an alarm, alarm_handler:set_alarm(Alarm) is called where Alarm is either of the alarms specified above. ๐
The alarms are cleared automatically when the alarm cause is no longer valid. Iconic behavior honestly.
The function get_memory_data() can be used to retrieve the result of the latest periodic memory check. Slay.
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. (iykyk ๐ญ)
A call to get_system_memory_data/0 is more costly than a call to get_memory_data/0 because data is collected synchronously when this function is called. So like, budget accordingly bestie.
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 philosophy major energy tbh. ๐ฆ
๐ธ CONFIGURATION ๐ธ
These configuration parameters can change the default values for time intervals and thresholds, bestie:
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 the memsup process 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 the memsup process 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 tofalseon systems with many concurrent processes, as each process memory check makes a traversal of the entire list of processes. ๐ฎโ๐จ
See config(5) for info about how to change the value of configuration parameters. ๐
๐ EXPORTS ๐
get_memory_data() -> {Total,Allocated,Worst}
Types:
Total = Allocated = int()
Worst = {Pid, PidAllocated} | undefined
Pid = pid()
PidAllocated = int()
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 if is 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. (the way it just *waits*โฆ patient queen ๐)
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_system_memory_data() -> MemDataList
Types:
MemDataList = [{Tag, Size}]
Tag = atom()
Size = int()
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 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 bestie, this is important: - Note that new tagged tuples may be introduced in the result at any time without prior notice. - Note that the order of the tuples in the resulting list is undefined and may change at any time. - 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.
get_os_wordsize() -> Wordsize
Types:
Wordsize = 32 | 64 | unsupported_os
Returns the wordsize of the current running operating system. Simple as that. โจ
get_check_interval() -> MS
Types:
MS = int()
Returns the time interval, in milliseconds, for the periodic memory check.
set_check_interval(Minutes) -> ok
Types:
Minutes = int()>0
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 above. ๐
get_procmem_high_watermark() -> int()
Returns the threshold, in percent, for process memory allocation.
set_procmem_high_watermark(Float) -> 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 above. ๐
get_sysmem_high_watermark() -> int()
Returns the threshold, in percent, for system memory allocation.
set_sysmem_high_watermark(Float) -> 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. ๐ฅ
get_helper_timeout() -> Seconds
Types:
Seconds = int()
Returns the timeout value, in seconds, for memory checks.
set_helper_timeout(Seconds) -> ok
Types:
Seconds = int() (>= 1)
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. ๐ง
๐ SEE ALSO ๐
alarm_handler(3erl), os_mon(3erl)
Ate and left no crumbs. This page was brought to you by Ericsson AB โ os_mon version 2.8.2, dated memsup(3erl). Periodt. ๐๐๐ฆ
๐ฆ where this page comes from
- ubuntu noble: erlang-manpages 1:25.3.2.8+dfsg-1ubuntu4 ยท Apache-2.0
- ubuntu noble: erlang-manpages 1:25.3.2.8+dfsg-1ubuntu4.8 ยท Apache-2.0
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms