From owner-freebsd-hackers Fri Jul 19 15: 1:41 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 489A837B400 for ; Fri, 19 Jul 2002 15:01:39 -0700 (PDT) Received: from ns.aus.com (adsl-66-127-242-81.dsl.sntc01.pacbell.net [66.127.242.81]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3C00C43E58 for ; Fri, 19 Jul 2002 15:01:38 -0700 (PDT) (envelope-from rsharpe@ns.aus.com) Received: from localhost (rsharpe@localhost) by ns.aus.com (8.11.6/8.11.6) with ESMTP id g6JNEWM04704 for ; Sat, 20 Jul 2002 08:44:33 +0930 Date: Sat, 20 Jul 2002 08:44:32 +0930 (CST) From: Richard Sharpe To: Subject: Any problems with Using sendfile In-Reply-To: <20020719102130.E19831@va.samba.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Hi, I did some testing a couple of days ago with sendfile under FreeBSD and Samba, and observed that in pulling 500MB of data from files on a server I could achieve about 45MB/s over GigE (I have a problem in my switch, I think) but that CPU utilization was at 100% without sendfile and 50% with sendfile. This is a big improvement, but there are potential problems. These problems are due to fact that once you start sending, if anything changes, you cannot stop and say oops, I screwed up. If you promised to send 64kB, you have to send that or drop the connection. The problem is exacerbated by the fact that the Linux sendfile call does not seem to allow you to specify the header on the call, so you are forced to send the header from userspace and the data from the kernel, and you therefor introduce a window during which things can go wrong. For example, the file can be truncated or deleted, and I don't think SMB allows you to send zeros for parts of the file that are not there. This is especially an issue if you don't have kernel oplocks and you have UNIX users sharing files with Windows users. The way Samba does this normally is that it assembles the data in userspace and then sends the response. If a problem occurs, it can determine this before sending anything at all, and can send an error response instead and does not need to drop the connection. However, FreeBSD's sendfile implementation allows you to specify the header to be sent in the call, and I believe that it also locks the vnode prior to trying anything so you are protected against the file changing under you. The only other thing that it could perhaps do is to pin all the pages before trying to send anything. Thus, if any error occurs, it can return to the user saying, sorry, I could not do this, you send an error message. That is, errors are handled in a recoverable way. The question is, does it gain you anything by demanding that the pages involved (up to 16) be pinned before starting to write on the socket? It increases pressure on memory, but it might be that the only problems that could occur mean that really bad things have happened anyway (like the file system has gone because the disk has died), so it might be that there is no need to be worried about this aspect. Are there any comments from here? Regards ----- Richard Sharpe, rsharpe@ns.aus.com, rsharpe@samba.org, sharpe@ethereal.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message