1memsup(3)                  Erlang Module Definition                  memsup(3)
2
3
4

NAME

6       memsup - A Memory Supervisor Process
7

DESCRIPTION

9       memsup  is  a  process which supervises the memory usage for the system
10       and for individual processes. It is part of the OS_Mon application, see
11       os_mon(6). Available for Unix and Windows.
12
13       Periodically performs a memory check:
14
15         * If  more  than a certain amount of available system memory is allo‐
16           cated, as reported by the underlying operating  system,  the  alarm
17           {system_memory_high_watermark, []} is set.
18
19         * If  any  Erlang process Pid in the system has allocated more than a
20           certain amount of total  system  memory,  the  alarm  {process_mem‐
21           ory_high_watermark, Pid} is set.
22
23       Alarms are reported to the SASL alarm handler, see alarm_handler(3). To
24       set an alarm, alarm_handler:set_alarm(Alarm) is called where  Alarm  is
25       either of the alarms specified above.
26
27       The  alarms are cleared automatically when the alarm cause is no longer
28       valid.
29
30       The function get_memory_data() can be used to retrieve  the  result  of
31       the latest periodic memory check.
32
33       There  is  also  a  interface to system dependent memory data, get_sys‐
34       tem_memory_data(). The result is highly  dependent  on  the  underlying
35       operating  system  and  the interface is targeted primarily for systems
36       without virtual memory. However, the output on other systems  is  still
37       valid, although sparse.
38
39       A  call  to  get_system_memory_data/0  is  more  costly  than a call to
40       get_memory_data/0 as data is collected synchronously when this function
41       is called.
42
43       The  total  system memory reported under UNIX is the number of physical
44       pages of memory times the page size, and the available  memory  is  the
45       number  of available physical pages times the page size. This is a rea‐
46       sonable measure as swapping should be avoided anyway, but the  task  of
47       defining total memory and available memory is difficult because of vir‐
48       tual memory and swapping.
49

CONFIGURATION

51       The following configuration  parameters  can  be  used  to  change  the
52       default values for time intervals and thresholds:
53
54         memory_check_interval = int()>0:
55           The  time  interval, in minutes, for the periodic memory check. The
56           default is one minute.
57
58         system_memory_high_watermark = float():
59           The threshold, as percentage of system memory, for how much  system
60           memory  can be allocated before the corresponding alarm is set. The
61           default is 0.80 (80%).
62
63         process_memory_high_watermark = float():
64           The threshold, as percentage of system memory, for how much  system
65           memory  can  be  allocated  by one Erlang process before the corre‐
66           sponding alarm is set. The default is 0.05 (5%).
67
68         memsup_helper_timeout = int()>0:
69           A timeout, in seconds, for how long the memsup process should  wait
70           for a result from a memory check. If the timeout expires, a warning
71           message "OS_MON (memsup) timeout" is issued  via  error_logger  and
72           any  pending,  synchronous  client calls will return a dummy value.
73           Normally, this situation should not occur. There have been cases on
74           Linux,  however,  where  the  pseudo file from which system data is
75           read is temporarily unavailable when the system is heavily loaded.
76
77           The default is 30 seconds.
78
79         memsup_system_only = bool():
80           Specifies whether the memsup process should only check system  mem‐
81           ory  usage (true) or not. The default is false, meaning that infor‐
82           mation regarding both system memory usage and Erlang process memory
83           usage is collected.
84
85           It  is  recommended  to set this parameter to false on systems with
86           many concurrent processes, as each process  memory  check  makes  a
87           traversal of the entire list of processes.
88
89         memsup_improved_system_memory_data = bool():
90           Determines  the behaviour of the get_system_memory_data() function.
91           When  this  configuration  parameter  is   false,   get_system_mem‐
92           ory_data()  behaves as it has done up until the point of the intro‐
93           duction of the configuration parameter. When set to true new tagged
94           tuples are allowed in the result. Such new tuples may be introduced
95           at any time without prior notice. The classification of cached_mem‐
96           ory  on Linux systems will also change so that more memory is clas‐
97           sified as cached_memory.
98
99     Note:
100         This configuration parameter defaults false and will do so  up  until
101         OTP 23. As of OTP 24 this configuration parameter will be removed and
102         get_system_memory_data() will begin behaving as it does now when  the
103         configuration parameter has been set to true.
104
105
106       See config(4) for information about how to change the value of configu‐
107       ration parameters.
108

EXPORTS

110       get_memory_data() -> {Total,Allocated,Worst}
111
112              Types:
113
114                 Total = Allocated = int()
115                 Worst = {Pid, PidAllocated} | undefined
116                  Pid = pid()
117                  PidAllocated = int()
118
119              Returns the result of the latest memory check,  where  Total  is
120              the  total  memory size and Allocated the allocated memory size,
121              in bytes.
122
123              Worst is the pid and number of allocated bytes  of  the  largest
124              Erlang process on the node. If memsup should not collect process
125              data, that is if the configuration parameter  memsup_system_only
126              was set to true, Worst is undefined.
127
128              The  function is normally asynchronous in the sense that it does
129              not invoke a memory check,  but  returns  the  latest  available
130              value.  The  one exception if is the function is called before a
131              first memory check is finished, in which case it does not return
132              a value until the memory check is finished.
133
134              Returns  {0,0,{pid(),0}}  or  {0,0,undefined}  if  memsup is not
135              available, or if all memory checks so far have timed out.
136
137       get_system_memory_data() -> MemDataList
138
139              Types:
140
141                 MemDataList = [{Tag, Size}]
142                  Tag = atom()
143                  Size = int()
144
145              Invokes a memory check and returns the resulting, system  depen‐
146              dent,  data  as a list of tagged tuples, where Tag can be one of
147              the following:
148
149                total_memory:
150                  The total amount of memory available to the Erlang emulator,
151                  allocated and free. May or may not be equal to the amount of
152                  memory configured in the system.
153
154                free_memory:
155                  The amount of free memory available to the  Erlang  emulator
156                  for allocation.
157
158                system_total_memory:
159                  The  amount  of memory available to the whole operating sys‐
160                  tem. This may well be equal to total_memory but  not  neces‐
161                  sarily.
162
163                buffered_memory:
164                   The  amount of memory the system uses for temporary storing
165                  raw disk blocks.
166
167                cached_memory:
168                   The amount of memory the system uses for cached files  read
169                  from disk.
170
171                total_swap:
172                   The  amount of total amount of memory the system has avail‐
173                  able for disk swap.
174
175                free_swap:
176                   The amount of memory the  system  has  available  for  disk
177                  swap.
178
179              Note that the order of the tuples in the resulting list is unde‐
180              fined and may change at any time.
181
182              All memory sizes are presented as number of bytes.
183
184              Returns the empty list [] if memsup is not available, or if  the
185              memory check times out.
186
187          Note:
188              On  Linux  the memory available to the emulator is cached_memory
189              and buffered_memory in addition to free_memory.
190
191
192              The above describes how it works if the configuration  parameter
193              memsup_improved_system_memory_data  has  been set to false which
194              currently also is the default  behavior.  If  the  configuration
195              parameter is set to true the behavior is slightly changed:
196
197                * New  tagged tuples may be added in the resulting list at any
198                  time.
199
200                * On Linux systems the following changes will be made:
201
202                  * A new tuple with the tag available_memory will be added to
203                    the  result when this value is provided by the kernel. The
204                    available_memory value informs  about  the  amount  memory
205                    that  is available for use if there is an increased memory
206                    need. This value is not based  on  a  calculation  of  the
207                    other  provided  values  and should give a better value of
208                    the amount of memory that actually is available than  cal‐
209                    culating a value based on the other values reported.
210
211                  * The  classification of cached_memory is changed. Also mem‐
212                    ory marked as reclaimable in  the  kernel  slab  allocator
213                    will be added to the value presented as cached_memory.
214
215          Note:
216              As  of  OTP  24 memsup_improved_system_memory_data configuration
217              parameter will  be  removed  and  get_system_memory_data()  will
218              begin  behaving  as it does now when the configuration parameter
219              has been set to true.
220
221
222       get_os_wordsize() -> Wordsize
223
224              Types:
225
226                 Wordsize = 32 | 64 | unsupported_os
227
228              Returns the wordsize of the current running operating system.
229
230       get_check_interval() -> MS
231
232              Types:
233
234                 MS = int()
235
236              Returns the time interval, in  milliseconds,  for  the  periodic
237              memory check.
238
239       set_check_interval(Minutes) -> ok
240
241              Types:
242
243                 Minutes = int()>0
244
245              Changes  the  time  interval, given in minutes, for the periodic
246              memory check.
247
248              The change will take effect after the next memory check  and  is
249              non-persistent.  That  is,  in  case  of a process restart, this
250              value is forgotten and the default value will be used. See  Con‐
251              figuration above.
252
253       get_procmem_high_watermark() -> int()
254
255              Returns  the  threshold,  in percent, for process memory alloca‐
256              tion.
257
258       set_procmem_high_watermark(Float) -> ok
259
260              Changes the threshold, given as  a  float,  for  process  memory
261              allocation.
262
263              The  change  will  take  effect  during the next periodic memory
264              check and is non-persistent. That  is,  in  case  of  a  process
265              restart,  this  value is forgotten and the default value will be
266              used. See Configuration above.
267
268       get_sysmem_high_watermark() -> int()
269
270              Returns the threshold, in percent, for system memory allocation.
271
272       set_sysmem_high_watermark(Float) -> ok
273
274              Changes the threshold, given as a float, for system memory allo‐
275              cation.
276
277              The  change  will  take  effect  during the next periodic memory
278              check and is non-persistent. That  is,  in  case  of  a  process
279              restart,  this  value is forgotten and the default value will be
280              used. See Configuration above.
281
282       get_helper_timeout() -> Seconds
283
284              Types:
285
286                 Seconds = int()
287
288              Returns the timeout value, in seconds, for memory checks.
289
290       set_helper_timeout(Seconds) -> ok
291
292              Types:
293
294                 Seconds = int() (>= 1)
295
296              Changes the timeout value, given in seconds, for memory checks.
297
298              The change will take effect for the next  memory  check  and  is
299              non-persistent.  That is, in the case of a process restart, this
300              value is forgotten and the default value will be used. See  Con‐
301              figuration above.
302

SEE ALSO

304       alarm_handler(3), os_mon(3)
305
306
307
308Ericsson AB                      os_mon 2.6.1                        memsup(3)
Impressum