[Samba] smbd reads entire directory when creating files?

Matt Mitchell mmitchell at virtualproperties.com
Wed Dec 8 19:37:23 GMT 2004

Jeremy Allison wrote:

>>A strace on the smbd process receiving the files from the windows box 
>>(it is mapped as a share on the 2k3 server) reveals that smbd is looking 
>>up the entire directory (with getdents64) every time it writes a file. 
>>Several times, in fact.  So as the number of files grows, it churns more 
>>and more.  I'm sure most of it is in cache but the data still has to be 
>>moved around in memory.
>>I know this is not necessary for writing/copying files with unix 
>>semantics, but I wonder if the case-fiddling or any other Windows 
>>imitative behavior is making this getdents64 orgy necessary.  Is there 
>>any way to disable it?

I was also looking at the case sensitivity options, but alas they don't 
seem to be able to prevent the readdir bonanza.

I'm guessing the unix_convert routine is responsible for at least one 
set of traversals.  In this case I don't care at all about converting 
these paths and there are no wildcards.  It seems that, in that 
particular case, the contract of the routine could be satisfied by 
checking to see if we are in "case sensitive" mode and if so we don't 
bother doing the scan_directory (filename.c:284), since the SMB_VFS_STAT 
will tell us if the file really exists or not.

Granted, it's an optimization.  I realize that in the presence of 
wildcards (of which case-insensitivity is a variety) you have to do that 
  scan_directory call.  Of course, ideally, you would cache that 
resulting directory list as long as you possibly can.

Name mangling also complicates this, but it's another feature I'm not 
using at all in this application.

Obviously such a special case would make the code ugly...but I might try 
patching it just for my own testing to see if it makes any difference. 
Any pointers you can offer?


More information about the samba mailing list