Optimization with sendfile

Jeremy Allison jra at samba.org
Wed Sep 6 15:56:56 GMT 2006


On Wed, Sep 06, 2006 at 09:35:19AM +0300, Shlomi Yaakobovich wrote:
> 
> We have been doing some performance tests (streaming read/write), and I've noticed that whenever we use sendfile (in reply.c/send_file_readX), there is a call to SMB_VFS_FSTAT before the actual sendfile call. If I understand it correctly, then this is to figure out what size of data we're going to handle, and if the file has enough data to send (so we can build an appropriate header).

Yes.

> First of all, I see a race condition here, if someone is writing to the file, or worse, truncating it - then the sendfile would fail, although we already sent the header. I wonder if locking the file is a valid solution here ?  It will require a few system calls, which might render the use of sendfile useless.

Failing the sendfile is correct here. This is essentially "what
Windows does". Note we only use sendfile if the file was oplocked.

Jeremy.


More information about the samba-technical mailing list