[FreeNX-kNX] Gradual performance decrease of nxagent related to Create/FreePixmap

Mario Becroft mb at gem.win.co.nz
Sat Feb 7 10:38:17 UTC 2009

There is a performance problem in nxagent where after a session has been
running for a while (several days to a week) the performance of some X
clients gradually decreases noticably.

Examples are firefox web browser, where scrolling a window (normally
very fast) causes nxagent to become CPU-bound, and openoffice, where
drawing menus and toolbars becomes progressively slower until it can
take hundreds of milliseconds to draw a menu, with 100% CPU utilisation
of nxagent.

It turns out these clients are doing many CreatePixmap() and
FreePixmap() requests, and as the problem progresses, these calls become
increasingly slower. (Why those particular clients are so pixmap-crazy
is a question for another day.)

Most of the CPU time is spent in nxagentSwitchResourcesType() (called
from AddResource()) and nxagentFindClientResource(), called from
ProcCreatePixmap() and ProcFreePixmap(), respectively. The number of
resources belonging to the server (client 0) increases over time until
it is very large, and since these two functions iterate over each
resource, they become extremely slow.

Considering that popular software like firefox and openoffice exercises
these routines hundreds of times just to draw some menus or scroll a
page, this looks like a clear case for optimisation, perhaps by hashing
clientTable[] on resources.type and resources.value.

The other question is where is the resource leak. I tried killing all
clients but that did not help, so it is apparently not a client leak,
unless it involves XSetCloseDownMode(RetainPermanent), but I can't think
why any client would be doing that. It could be that the server has a
leak of client resources on client exit, or an internal leak. The same
leak could be happening on non-nx X servers, but nobody notices because
there is not a performance problem.

The clients I am running are all fairly standard (fvwm, xterm, emacs,
firefox, Tcl/Tk). We have seen similar behaviour on gnome sessions, but
I cannot be sure it is the same underlying cause.

One thing that looks suspicious is how for fonts and pixmaps, nxagent
calls AddResource() when they are being freed, if refcnt > 0. I am not
100% sure yet what this means. It may have nothing to do with the

Has anyone else noticed this problem? Any ideas?

Completely unrelated, I happened to notice that the ProcCreatePixmap()
in NXdispatch.c is missing a bounds check that exists in the normal
dix/dispatch.c version. Should this check not be ported to the nx
version of the function?

Mario Becroft <mb at gem.win.co.nz>

More information about the FreeNX-kNX mailing list