Sunday, April 09, 2006

Fighting Daemons

One of the things I love about GNOME and Linux in general is the philosophy of "do one thing, and do it right". However, we may have taken this to an extreme in the GNOME community. The GNOME desktop has seperate daemons for a plethora of simple tasks. nm-applet sits around and waits for the network connection status to change. Great, I love nm-applet. But does this task warrent 2.7 MB of memory? According to my smem script, this is the amount of private dirty rss the task takes.

To initialize the GTK+ framework (among other frameworks), one must allocate a given amount of memory on the heap. Depending on what parts of the stack (dbus, libgnomeui, etc) one loads, this ranges from 1-3 MB. While it's important to work to fix this (eg, by mmaping things), there's only so much we can do.

I believe it would be beneficial to have a host process for daemons like this. The system would need to be set up in such a way so that mini-daemons could be put into a different process via configuration (eg, for debugging).

One of the types daemons on the desktop is panel applets. We have a process to display the clock, the volume switcher, etc. The panel already has a framework for doing these in process. What would be the benefit of using this? To find out, I put two applets in process: the wnck-applet which handles the workspace switcher and task list and the notification-area-applet, which handles the notification tray.

I actually already had the patch for this. openSUSE already uses a similar patch thanks to Federico. I decided to modify the patch so that it would not put clock-applet in process. Some people have complained that because this links to evo, it might be at risk for crashing. Fine, whatever. Let's start with some low hanging fruit.

Here are the results for private dirty rss, before and after the patch.

ProcessBeforeAfter
gnome-panel4008 kb4248 kb
notification-area-applet1368 kb--
wnck-applet3056 kb--
TOTAL8432 kb4248 kb

This is over 4mb! Just for putting two things in process. There are three other applets on my Dapper computer that could benefit just as easily: trash-applet (trivial), mixer applet (see below), clock applet (links to evo stuff. maybe?). I hope other distros follow the led of openSUSE in this area.

One thing to look at: the mixer applet loads every single part of gstreamer. This causes extra memory usage (gstreamer plugins badly need constification), as well as extra spinning of the disk. Can this be fixed?

2 comments:

Alexandre Gomes said...

I really would love to be a GNOME hacker, I would just drop half their sources, lol.

Seriously, I believe there are many things we need to optimize and refactor before thinking about new features. GNOME hackers should think that now that we are almost at the same level as Windows XP, we should improve memory and performance (2 flag points we advocate about Linux) and make it really worth. When Vista comes out we would be ready to battle again.

Matt Solnit said...

Hi Ben. I read your blog entry with interest because the idea you are proposing is something that Microsoft Windows already does. The process SVCHOST.exe, which can be loaded more than once, contains multiple services at a time. This is done (AFAIK) precisely because of the high cost of creating a new process in Windows.

I think implementing this in Linux or in GNOME is a great idea. You can read more about how the Windows implementation works at http://support.microsoft.com/?kbid=314056.