Wednesday, April 16, 2008

Teaching kde how to share

First post seemed to have been well received, so I will try keep it up.

Part of the advantage of using KDE is all the libraries and framework available for your program. By using a few shared libraries, you get for free a ton of functionality. The shared libraries can be shared between multiple processes, so memory consumption also goes down.

... or so you would think.

Exmap can list memory consumption by shared library (what a wonderful tool), so I can quickly verify whether they are being efficiently shared by multiple processes.

So here it is:

The number one library that consumes more memory is libGLcore. As you can see from the screenshot, there are 4 processes using it. Each and every single one of them is making an almost full copy of the library in memory. The biggest section in the library ".text" is 6.3 MB big, and it is being completely duplicated between all 4 processes.

This does not seem to be limited with kde, I tried with mplayer and glxgears with same results. It does not share a single byte in the .text entry even with other similar processes.

If I had to guess, and that is all I can do since it is just a binary blob, could be wrong, but it is probably the way the library is compiled, my guess: not using PIC (position independent code). This causes all of the function calls to be relocated when the library is loaded, and make it impossible for the system to share the code since each copy has been modified by the relocation process.

This library is part of the nvidia binary drivers, so there is not much to do there. If the library was compiled in such a way that it could be shared between processes, it could save about 18 MB of ram by not duplicating the code.

I would love to hear from someone to try with intel drivers, do they present the same problem?

So... the score:

ChangePotential memory savings
Change phonon backend from xine to something else22 MB
Avoid nvidia binary drivers18 MB (guesstimate)