[avahi] Memory consumption

Frank Lahm franklahm at googlemail.com
Thu Apr 12 02:45:04 PDT 2012


Am 11. April 2012 17:44 schrieb Lennart Poettering <lennart at poettering.net>:
> On Wed, 11.04.12 16:50, Frank Lahm (franklahm at googlemail.com) wrote:
>
>> > I don't see where the Avahi client libraries cuould do such a big
>> > allocation. My only guess is that this is actually the D-Bus library
>> > that does this (it maintains a message cache). To figure this out it
>> > might be worth to plot the memory usage with a tool like valgrind's
>> > massif tool?
>>
>> I had checked with Valgrind memcheck before to no avail. I've looked
>> at massif as to your recommendation and that is indeed quite revealing
>> (this requires the --pages-as-heap=yes option as the large allocation
>> is apparently not done via malloc et al):
>
>> So it seems it's pthread_create(). Wonder why it allocates such a huge
>> chunk of memory. I guess the only way avoiding this is completely
>> redesigning our application such that the Avahi stuff is not done in
>> the process that later forks and runs user AFP sessions. :(
>
> This might simply be the stack for the thread, which you can influence
> with "ulimit -s" in its size.

This limits the size of the stack of the main thread in the first
place and then that value is used by pthread_create() for the size of
the stack allocation. I've tried setting setrlimit(RLIMIT_STACK,...)
to a smaller value before calling avahi_threaded_poll_new|start(), but
that doesn't alter the allocation.

> However, note that having a large stack doesn't actually mean that this
> uses a lot of memory, it just reserves address space, which is only
> backed when needed. Hence, most likely this is really a
> non-issue. (i.e. don't confuse reservation of memory with reservation of
> address space!)

Yes.

Regards!
-f


More information about the avahi mailing list