[erlang-questions] Memory issue: big swap usage

Gustav Simonsson gustav.simonsson@REDACTED
Mon Jul 16 12:06:26 CEST 2012


Hi,

The swap column in top does not represent the current swap usage of processes.
Rather, it represents how much swap would be necessary if the process was swapped out.

If you want to find out how much swap your BEAM process is really using,
look at the smaps file of the process and sum up the "Swap:" fields.

For example:

ps -e | grep beam
 4726 pts/1    00:46:14 beam.smp

grep "Swap:" /proc/4726/smaps | awk '{swap = swap + $2} END {print swap}'

The output is in kilobytes.

man proc | grep -A 15 smaps

Regards,
Gustav Simonsson

Sent from my PC

----- Original Message -----
> From: "龙第九子" <physacco@REDACTED>
> To: "Erlang-Questions" <erlang-questions@REDACTED>
> Sent: Monday, 16 July, 2012 10:02:21 AM
> Subject: [erlang-questions] Memory issue: big swap usage
> 
> Hi all,
> 
> Recently I wrote a service-monitoring program in Erlang. It uses
> httpc
> (the HTTP client shipped with Erlang/OTP) to fetch web server
> statistics data, does some calculations, and then sends results to
> another service. It works fine, however, the memory usage is very
> strange. While VmRSS stays at a reasonable level, but VmSize and
> VmData keep increasing (about 40m per day). Please look at the
> following data:
> 
> System memory usage:
> 
>     $ free -m
>                  total       used       free     shared    buffers
>                      cached
>     Mem:          2012       1486        525          0        216
>            713
>     -/+ buffers/cache:        557       1455
>     Swap:         2047          5       2041
> 
> 
> `top` shows that the beam.smp process consumes 51m physical memory :)
> and 857m swap memory :(
> 
>       PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  SWAP
>       COMMAND
>     27100 root      20   0  909m  51m 2288 S    2  2.6 149:54.65 857m
>     beam.smp
> 
> 
> Current VM status of the process:
> 
>     $ cat /proc/27100/status|grep Vm
>     VmPeak:      932260 kB
>     VmSize:      931616 kB
>     VmLck:           0 kB
>     VmHWM:       54624 kB
>     VmRSS:       52968 kB
>     VmData:      907556 kB
>     VmStk:          88 kB
>     VmExe:        1860 kB
>     VmLib:        2412 kB
>     VmPTE:         208 kB
> 
> 
> And Erlang reported memory usage (seems good):
> 
>     15> erlang:memory().
>     [{total,46487136},
>      {processes,1283144},
>      {processes_used,1251480},
>      {system,45203992},
>      {atom,509577},
>      {atom_used,497728},
>      {binary,169912},
>      {code,4395539},
>      {ets,323224}]
> 
> 
> I use Erlang R14B03 (erts-5.8.4) compiled with GCC 4.4.5 on Debian 6
> Linux 2.6.32-5-amd64. I'm not sure if there is a memory-leaking bug.
> The problem is too hard for me and I have no choice but to restart
> the
> process. Could someone be kind enough to help me out? Please.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
> 



More information about the erlang-questions mailing list