[mythtv] [mythtv-commits] Ticket #3317: mythbackend memory leak

Rob Smith kormoc at gmail.com
Mon May 7 16:50:13 UTC 2007

On 5/7/07, Carl Fongheiser <carlfongheiser at gmail.com> wrote:
> On 5/7/07, Kevin Kuphal <kuphal at dls.net> wrote:
> > I didn't find anything generic about a fork error with memory
> > allocation.  Is there additional information I can provide to diagnose
> > this?  My top shows:
> >
> > top - 08:56:07 up 6 days, 42 min,  3 users,  load average: 0.10, 0.13,
> 0.09
> > Tasks:  97 total,   3 running,  94 sleeping,   0 stopped,   0 zombie
> > Cpu(s):  1.0%us,  3.0%sy,  0.0%ni, 90.4%id,  4.0%wa,  0.0%hi,  1.7%si,
> > 0.0%st
> > Mem:    775856k total,   767484k used,     8372k free,      108k buffers
> > Swap:   524280k total,   240864k used,   283416k free,   175920k cached
> >
> > with the backend process
> >
> > 31439 root      18   0  987m 499m  12m S  3.3 65.9  45:08.63 mythbackend
> Your machine is seriously short on swap space.  A good rule of thumb is to
> allocate about 2x the amount of physical RAM for swap space.  As to why
> you're getting a fork() error, fork() will attempt to clone the entire
> address space.  In this case, that's 987MB worth.  Not all of that will need
> to be backed by swap, but most of it will.  Since you've only got 280 MB
> free, the fork() fails.
> Carl Fongheiser

That's not quite true. Sure, the process will 'take' 987mb worth, but
a large chunk of that is in shared libs and the like, so it won't take
all that in swap *or* main memory.

pmap -d `pidof mythbackend` will tell you how much is truely used and
required, under the writable/private line. on mine it had mapped
160640k, and writable/private of 114768k, which means it's 'total'
footprint is a tad over 270m, but it is only using 115m by itself and
that's all it needs to page into swap.

If you really want to see where the memory is being used, just look
above the last line and it will tell you what it is using where.

That being said, 2x ram for swap is a huge waste. I've maxed out on
512m swap and that's been absolutely fine. keeps the system up when my
ram runs out, but won't take forever when it starts swapping or to
clean out the swap.

See the reply from:
From: John Bradford [email blocked]
Subject: Re: why swap at all?
Date: 	Wed, 26 May 2004 10:23:32 +0100

on here:
namely this chunk:
"A run-away process on a server with too much swap can cause it to grind to
almost a complete halt, and become almost compltely unresponsive to remote

If the total amount of storage is just enough for the tasks the server is
expected to deal with, then a run-away process will likely be terminated
quickly stopping it from causing the machine to grind to a halt.

If, on the other hand, there is excessive storage, it can continue running
for a long time, often consuming a lot of CPU."

I've had times where with 512m of swap on my desktop that it takes
upwards of 30 minutes to cleanup after a swap storm, when you have 2
gigs, that's at least 4x as long. Sure, in *theory*, more swap ==
better, but in reality, there's a fine line before it gets worse.


More information about the mythtv-dev mailing list