Subject: Re: Samba memory leak related to a still-open PR?
To: None <netbsd-users@netbsd.org>
From: Mark Cullen <mark.r.cullen@gmail.com>
List: netbsd-users
Date: 06/26/2006 19:53:26
Mark Cullen wrote:
> I am experiencing a memory leak of some sorts related to Samba. I 
> strongly believe it is related to the the PR [1] which is still 'Open'. 
> I have run the included test program from the said PR, and I get the 
> following output:
> 
> (root@bone)/root# ./telldir-memuse.o
> telldir-memuse.o: Used 8192 extra bytes for 250 telldir calls
> telldir-memuse.o: Used 12288 extra bytes for 377 telldir calls
> telldir-memuse.o: Used 16384 extra bytes for 504 telldir calls
> telldir-memuse.o: Used 20480 extra bytes for 631 telldir calls
> telldir-memuse.o: Used 24576 extra bytes for 758 telldir calls
> telldir-memuse.o: Used 28672 extra bytes for 885 telldir calls
> telldir-memuse.o: Failure: leaked 28672 bytes
> 
> Is there any plans to fix this? There is a patch included, but it was 
> filed for 1.6 by the looks of it. I'm not sure if it'll work with 3.x?
> 
> As it stands, Samba is fairly unusable for me because of this, or at 
> least I think it's this. I never had the problem on FreeBSD, but that 
> was with Samba 3.0.21b, I am now using 3.0.22. I've mailed the Samba 
> lists, but I am sure it's related to this bug. The memory of the smbd 
> process increases if I hold down F5 (to refresh) in explorer, in a Samba 
> share. The memory 'leaked' appears to be more when there are more files 
> in the share being refreshed.
> 
> Thanks in advance,
> Mark
> 
> [1] http://mail-index.netbsd.org/netbsd-bugs/2004/02/05/0008.html
> 
> 

I would like to say that the patches in that PR, applied to 3.0.1, 
solves part of the problem. The memory used no longer grows when I hold 
down refresh on shares!

However, if I copy a directory from a share over there appears to be a 
little memory (4 bytes continously) not being free'd still.

Example
-------
A directory containing 8,643 files and 382 directories inside it, 
weighing in at a [rather small] 280MB, copied from Samba to the local 
machine via explorer.

Before copying the memory usage was at:

admin    20699  0.9  1.5  3328  3812 ?      S     7:13PM   0:12.84 
/usr/pkg/sbin/smbd -D

After copying the memory usage is at:

admin    20699  0.2  1.2  6220  3152 ?      S     7:13PM   4:59.94 
/usr/pkg/sbin/smbd -D

Nowhere near as bad as before (I would already be well in to the 30-40MB 
range by now!), but should I ever decide to do any large copy operations 
I imagine I may well hit the same issue. Curiously, if I copy the same 
directory again afterwards the memory doesn't increase any more, e.g if 
I copy the same example directory above, it seems to still stay at 6220.

I think this may be related to an option that was removed by the patch?


  /*
- * The option SINGLEUSE may be defined to say that a telldir
- * cookie may be used only once before it is freed. This option
- * is used to avoid having memory usage grow without bound.
- */
-#define SINGLEUSE


Something to do with these 'cookies' being reused perhaps (from the 
telldir.c patch)?

+               if (lp->_dpseek == dirp->dd_seek &&
+                   lp->_dploc  == dirp->dd_loc)
+               {
+                       /* made before, reuse */
+                       return lp->_dpcookie;
+               }

I also have no idea of the performance implications of using the linked 
list to free memory has, but I would much rather it be slightly slower 
and stable personally :-) I'll leave that for someone else to worry 
about for now (sorry!)

Mark