From owner-freebsd-current@FreeBSD.ORG Thu May 29 21:31:40 2008 Return-Path: Delivered-To: current@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 59EA71065671; Thu, 29 May 2008 21:31:40 +0000 (UTC) (envelope-from dds@aueb.gr) Received: from mx-out.forthnet.gr (mx-out.forthnet.gr [193.92.150.104]) by mx1.freebsd.org (Postfix) with ESMTP id B64A08FC18; Thu, 29 May 2008 21:31:39 +0000 (UTC) (envelope-from dds@aueb.gr) Received: from mx-av-05.forthnet.gr (mx-av.forthnet.gr [193.92.150.27]) by mx-out-01.forthnet.gr (8.14.3/8.14.3) with ESMTP id m4TKhZp1003510; Thu, 29 May 2008 23:43:35 +0300 Received: from MX-IN-02.forthnet.gr (mx-in-02.forthnet.gr [193.92.150.185]) by mx-av-05.forthnet.gr (8.14.3/8.14.3) with ESMTP id m4TKhZsj006470; Thu, 29 May 2008 23:43:35 +0300 Received: from [192.168.136.22] (adsl164-88.kln.forthnet.gr [62.1.67.88]) by MX-IN-02.forthnet.gr (8.14.3/8.14.3) with ESMTP id m4TKhQVs030304; Thu, 29 May 2008 23:43:27 +0300 Authentication-Results: MX-IN-02.forthnet.gr smtp.mail=dds@aueb.gr; spf=neutral Authentication-Results: MX-IN-02.forthnet.gr header.from=dds@aueb.gr; sender-id=neutral Message-ID: <483F1559.2020600@aueb.gr> Date: Thu, 29 May 2008 23:43:05 +0300 From: Diomidis Spinellis User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080313 SeaMonkey/1.1.9 MIME-Version: 1.0 To: Andriy Gapon References: <20080528110003.Q24259@beagle.kn.op.dlr.de> <483D5DF8.4020504@icyb.net.ua> In-Reply-To: <483D5DF8.4020504@icyb.net.ua> Content-Type: multipart/mixed; boundary="------------060005070704090803030609" X-Mailman-Approved-At: Thu, 29 May 2008 23:01:28 +0000 Cc: Harti Brandt , current@FreeBSD.ORG Subject: Re: cp(1) and mmap X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 May 2008 21:31:40 -0000 This is a multi-part message in MIME format. --------------060005070704090803030609 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Andriy Gapon wrote: > on 28/05/2008 12:02 Harti Brandt said the following: >> Hi all, >> >> it looks like there is no fallback in cp(1) when mmaping the source file >> fails. I'm mounting SMB shares via smbnetfs (which in turn uses fuse) >> and it seems not to support mmaping files. Shouldn't cp just fallback to >> a normal read()/write() loop in this case? > > I would think that it should. > This topic was brought up several times, but no resolution so far. > I think that I've even seen patches. > I've not seen the patches, but the fix is trivial (see the attached patch). If there are no objections, I can commit it. I also think we should use mmap for larger files, mmapping and writing them out in several chunks. Diomidis - dds@ --------------060005070704090803030609 Content-Type: text/plain; name="utils.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="utils.diff" Index: utils.c =================================================================== RCS file: /home/ncvs/src/bin/cp/utils.c,v retrieving revision 1.53 diff -u -r1.53 utils.c --- utils.c 10 Mar 2008 19:58:41 -0000 1.53 +++ utils.c 29 May 2008 20:39:38 -0000 @@ -137,41 +137,39 @@ * Mmap and write if less than 8M (the limit is so we don't totally * trash memory on big files. This is really a minor hack, but it * wins some CPU back. + * Some filesystems, such as smbnetfs, don't support mmap, + * so this is a best-effort attempt. */ #ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED if (S_ISREG(fs->st_mode) && fs->st_size > 0 && - fs->st_size <= 8 * 1048576) { - if ((p = mmap(NULL, (size_t)fs->st_size, PROT_READ, - MAP_SHARED, from_fd, (off_t)0)) == MAP_FAILED) { + fs->st_size <= 8 * 1048576 && + (p = mmap(NULL, (size_t)fs->st_size, PROT_READ, + MAP_SHARED, from_fd, (off_t)0)) != MAP_FAILED) { + wtotal = 0; + for (bufp = p, wresid = fs->st_size; ; + bufp += wcount, wresid -= (size_t)wcount) { + wcount = write(to_fd, bufp, wresid); + if (wcount <= 0) + break; + wtotal += wcount; + if (info) { + info = 0; + (void)fprintf(stderr, + "%s -> %s %3d%%\n", + entp->fts_path, to.p_path, + cp_pct(wtotal, fs->st_size)); + } + if (wcount >= (ssize_t)wresid) + break; + } + if (wcount != (ssize_t)wresid) { + warn("%s", to.p_path); + rval = 1; + } + /* Some systems don't unmap on close(2). */ + if (munmap(p, fs->st_size) < 0) { warn("%s", entp->fts_path); rval = 1; - } else { - wtotal = 0; - for (bufp = p, wresid = fs->st_size; ; - bufp += wcount, wresid -= (size_t)wcount) { - wcount = write(to_fd, bufp, wresid); - if (wcount <= 0) - break; - wtotal += wcount; - if (info) { - info = 0; - (void)fprintf(stderr, - "%s -> %s %3d%%\n", - entp->fts_path, to.p_path, - cp_pct(wtotal, fs->st_size)); - } - if (wcount >= (ssize_t)wresid) - break; - } - if (wcount != (ssize_t)wresid) { - warn("%s", to.p_path); - rval = 1; - } - /* Some systems don't unmap on close(2). */ - if (munmap(p, fs->st_size) < 0) { - warn("%s", entp->fts_path); - rval = 1; - } } } else #endif --------------060005070704090803030609--