Ubuntu detect memory leak

2

1

I run watch free and then observe a continuous memory used increment, about 100 every 2s. How can I know which process contribute to the used memory increment?

top and pmap does not help.

BTW, after I run echo 1 > /proc/sys/VM/drop_caches, the used memory decreased drastically. But it still keep increasing with the same rate.

Gelin Luo

Posted 2011-09-27T07:25:40.050

Reputation: 251

'100 every 2s' ... 100 of what? – akira – 2011-09-27T07:53:10.397

@akira: free reports kbytes by default, so probably "100s of kbytes". – David Andersson – 2011-12-16T17:15:11.490

1To verify that it is a real leak and not caches/buffers: After "echo 1 > /proc/sys/VM/drop_caches", does it drop to the about the same lower value each time, or to a higher value each time? In the output from "free", does the value of "+/- buffers/cache" constantly increase, or only the value of "Mem"? – David Andersson – 2011-12-16T17:23:51.257

Answers

0

I would use top and hit shift-m to sort on memory. If an app is leaking memory it's %MEM should be increasing and the number under the RES column should be going up.

Above the list of the processes, if your free is going down, but buffers and cache are going up, while the apps in the list are about the same, then you should be fine. This just means Linux is using your free RAM to avoid hitting your hard disk and such so it can run faster. If you're worried about it still, open a bunch of applications and Linux should lower how much space it's using for the cache and buffers as the free gets close to 0.

When you tell it to drop_caches, Linux probably has to re-read the same area of the hard disk it just un-cached, and re-caches it. We might be able to figure out how to limit the cache size if you really want to, but Linux is using your unused RAM to speed stuff up. Unless this is a laptop and you're trying to conserve power, you want it to use your RAM so it runs fast.

RLZaleski

Posted 2011-09-27T07:25:40.050

Reputation: 292