X Server: abused or buggy?

Glynn Clements glynn at gclements.plus.com
Tue Dec 9 09:55:13 PST 2008


Óscar Fuentes wrote:

> >> Why should it be a KDE bug if the X server is leaking memory?  I used to
> >
> > The KDE app told X to cache all those pixmaps. X is just doing what it
> > was asked to. The alternative would be that it decided to kill off that
> > client for being dumb.
> 
> So in your opinion using X as a cache for 500 MB of pixmaps is dumb. I
> tend to agree, but it is reasonable to expect that when the app closes
> and the pixmaps are freed, all that memory is returned to the OS?

Not really. Most applications just use malloc() and free(), or
something similar. If they want memory, they try to get it from the
heap. If there isn't a large enough block on the heap, they first
obtain more memory from the OS in order to enlarge the heap. When they
have finished using the memory, they return it to the heap.

In most cases, they *won't* return the memory to the OS. It's
only possible to do so under very specific circumstances:

1. If the memory was allocated via brk/sbrk, it can only be returned
if it is at the end of the data segment.

2. If the memory was allocated via mmap(MAP_ANONYMOUS), it can only be
returned if it is at the end of the mapped region.

Usually, once an application has obtained memory from the OS, it will
simply keep "free" memory around in order to satisfy future
allocations. If it isn't being used, it will just get swapped out.

> In other words, is a bug that under this usage mode the memory
> asigned to X grows monotonically?

No. Most long-lived applications have memory "usage" which grows
monotonically, for the reasons outlined above. I put "usage" in quotes
because they won't necessarily be *using* the memory; they'll just
have it allocated (and swapped out).

-- 
Glynn Clements <glynn at gclements.plus.com>



More information about the xorg mailing list