I seem to have a larger memory leak on my current ubuntu System
After reporting strange Eclipse memory errors ( https://askubuntu.com/questions/148998/eclipse-constant-different-out-of-memory-errors ) I started to get 'Not enough Memory' error messages in my console today - while doing simple tasks like typing in sudo -s
- or even - free -m
Typing in 'free -m' repeadetly showed me how my RAM quickly goes up from 700M to 900M, growing up to the size of 2000M in a few seconds (after freeing up memory with echo 3 > /proc/sys/vm/drop_caches
)
Eclipse isnt the cause, I completly killed the process and the ram still was going up. Is there any way to detect where the leak is coming from? I cant even update my system anymore, since apt-get update
fails (probably because it's out of memory)
Using Ubuntu 11.10
First, make sure to have a temp folder available which has enough free space. The following commands create dumps which can be several GBs in size.
You can create a new tmp folder using the following command. You may want to change
/tmp
to a different filesystem with enough spaceSteps to find Memory Leak
Find out the PID of the process which causing memory leak (you can also use e.g.
htop
if available) and store it in a variable calledpid
Given that the PID is available in the variable
pid
, you can capture the memory consumption using/proc/$pid/smaps
and save into some file likebeforeMemInc.txt
.Capture
/proc/$pid/smaps
again and save it asafterMemInc.txt
Find the difference between first
smaps
and 2ndsmaps
, e. g. withNote down the address range where memory got increased, for example:
Use GDB to dump memory on running process or get the coredump using
I used gdb on the running process to dump the memory to some file.
Now, use
strings
command orhexdump -C
to print thememory.dump
From this you get readable information which helps you locate those strings in your source code.
The drop_cache trick will not free memory, it will reset the cache. Uses ps command if you want to identify which processes uses the more memory.
For instance to monitor the list of the top 15 of resident memory users.
You could check also the shared memory reservation but you will only know who is the owner of the segments.
Pmap allocation:
note that reserved allocations are much higher than real the allocated pages (df 'used')
System V allocations :
Edit: Need to pass
--sort -rss
tops
to get the processes with the most memory usage, otherwise the process list is sorted increasing numerical and gives the processes with least memory usage.memprof
Source: Ubuntu Manual
I have an older machine that I use that constantly spits out memory leak messages:
My script:
Named it
cache.sh
You can see I was down to 374 MB, ran the
sync; sudo echo 3 > /proc/sys/vm/drop_caches
and gained 417 MB back. One cancron
it to run every 5 minutes or just have a terminal open and run it when you see slow performance. Yes, I need to add memory to the machine...memstat is also a good tool that will show the amount of memory used by each block as well as how much memory is used by loaded libraries. Not the best tool but is worth using to gather details and statistics.
memstat -w -p pid
is a good command to use.I had a similar problem but with a very weird solution.
For some unknown reason I had a mail server on my laptop setup and running.I don't know why I had it...However I shut its service down and it turned out that that software on my laptop was under a ddos attack.After that everything was normal.