[kwlug-disc] Debugging for memory use
cdfrey at foursquare.net
Mon Aug 30 11:55:35 EDT 2010
On Mon, Aug 30, 2010 at 11:27:49AM -0400, Chris Irwin wrote:
> Short question: How do I find out why nautilus is using so much
> memory, and maybe fix it. I'm somewhat of a rookie when it comes to
> debugging applications, but I have some C ability, and wouldn't mind
> investing the time to fix my issue.
> Long explanation: I've been having a problem where over time my
> machine has less and less free memory. After some playing around, it
> turns out that about 500MB of 'stuff' had been swapped out. I have 4GB
> of ram, and `free -m` showed very little as 'cached' (maybe 100MB), so
> I'm looking at 'actual' memory usage.
> First thing I did was kill chromium. For a browser, it tends to be
> rather memory intensive. That only freed up a few hundred MB of
> memory. My machine, sitting at an empty Gnome desktop was using ~3.2
> GB doing nothing. After some detective work I killed nautilus and
> suddenly had an extra 1 GB of memory available. This has happened
> twice so far, but the effects are far enough removed from any actual
> nautilus use that I don't know what caused it.
> So, how can I investigate this? Can I install symbols and connect to a
> running nautilus process with gdb? Also, how do I use gdb? Is there
> something else that is better suited for debugging memory issues?
First thing to use is 'ps' or 'top' when this happens again, and
sort by memory usage in top to see what is really eating up all that
Next, you probably want to google around for bug reports of the same
issue. If you are seeing this, then others probably are too, and it might
have been fixed already. Especially with a 1 GB appetite.
It may be that Nautilus is supposed to consume that much memory, and
perhaps there is a setting, or a memory cache limit somewhere, that you
can tweak, before diving into the code.
Before diving into the code, you should subscribe to the Nautilus development
mailing list and describe this problem. They may be able to help you
debug this, and will know the code much better than anyone else, so
they can point you in the right direction faster.
After all this, it might just be a memory leak in the code, and one
of the best tools to find memory leaks is called valgrind. Try to
use the latest valgrind you can get on your system, since you'll want
all the features to help find leaks.
Recompile Nautilus from source and make sure you have debug symbols
turned on (gcc option '-g'). You can test this by running it inside gdb,
breaking on main, and checking for source code. Assuming Nautilus runs
as a usual binary program:
$ gdb /path/to/compiled/nautilus
> break main
If you see source code after 'list', you're good.
Then run Nautilus under valgrind, which might be tricky.... this page
has some instructions on how to do it:
I would also consider adding the --track-origins=yes option when running
valgrind, if your version is new enough.
This is the forest-level view of debugging memory leaks. There's a
whole lot of tree-level details that you'll encounter as you dig into it.
More information about the kwlug-disc