memsup(3)

MODULE
memsup - A memory Supervisor Process

DESCRIPTION

memsup is part of the os_mon application and all configuration parameters are defined in the reference documentation for the os_mon application.

memsup is a process which supervises the memory usage for the system and for individual processes, as follows:

    *   If more than system_memory_high_watermark of available system memory is allocated, as reported by the underlying operating system, the alarm system_memory_high_watermark is set.

    *   If any Erlang process in the system has allocated more than process_memory_high_watermark of total system memory, the alarm process_memory_high_watermark is set.

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.

The memsup process defines two alarms which are set by the alarm_handler:set_alarm(Alarm) function. Alarm is defined as:

    {system_memory_high_watermark, []}.:
        This alarm is set when the used system memory exceeds system_memory_high_watermark of the total available memory.

    {process_memory_high_watermark, Pid}.:
        This alarm is set when an Erlang process exceeds process_memory_high_watermark of the total available memory.

These alarms are cleared automatically when the alarm cause is no longer valid.

There is also a interface to system dependent memory data, get_system_memory_data/0. The output is highly dependent on the underlying operating system and the interface is targeted primarily for systems without virtual memory (e.g. VxWorks). The output on other systems is however 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.

EXPORTS

get_check_interval() -> Time

    Types
        Time = integer()

    A time interval, in milliseconds, which defines how often memory is checked. The get_system_memory_data() function is in no way affected by this interval.

get_memory_data() -> MemData

    Types
        MemData = {TotalMemorySize, AllocatedBytes, {LargestPid, PidAllocatedBytes}}
        TotalMemorySize = integer()
        AllocatedBytes = integer()
        LargestPid = pid()
        PidAllocatedBytes = integer()

    Returns data about the memory in the system. LargestPid is the Pid of the largest Erlang process in the system. PidAllocatedBytes is the amount of memory the LargestPid has allocated.

get_system_memory_data() -> MemDataList

    Types
        MemDataList = [TaggedValue ...]
        TaggedValue = {Tag, Value}
        Value = integer()
        Tag = atom()

    Gets system dependent memory data. The result is returned as a list containing tagged tuples, where the tag can be one of the following:

        total_memory:
            The total amount of memory (in bytes) available to the Erlang emulator, allocated and free. May or may not be equal to the amount of memory configured in the system.

        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 to total_memory but not necessarily.

        largest_free:
            The size of the largest contiguous free memory block available to the Erlang emulator.

        number_of_free:
            The number of free blocks available to the Erlang runtime system. This gives a fair indication of how fragmented the memory is.

    As with get_memory_data(), the values on Unix-like systems indicate the amount of physical memory that is configured and free. The largest_free and number_of_free tags are currently only returned on a VxWorks system.

    All memory sizes are presented as number of bytes.

get_procmem_high_watermark() -> integer()

    Threshold as a percentage of the total available system memory. It specifies how much memory can be allocated by one Erlang process before an alarm is sent.

get_sysmem_high_watermark() -> integer()

    Threshold as a percentage of the total available system memory. It specifies how much memory can be allocated by the system before an alarm is sent.

See Also

alarm_handler(3), os_mon(3)

AUTHORS
Martin Björklund - support@erlang.ericsson.se
Peter Högfeldt - support@erlang.ericsson.se
Patrik Nyblom - support@erlang.ericsson.se