From owner-freebsd-current@FreeBSD.ORG Tue May 28 01:10:15 2013 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 5F3BCC77 for ; Tue, 28 May 2013 01:10:15 +0000 (UTC) (envelope-from bright@mu.org) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.freebsd.org (Postfix) with ESMTP id 5186EC17 for ; Tue, 28 May 2013 01:10:15 +0000 (UTC) Received: from Alfreds-MacBook-Pro-9.local (c-67-180-208-218.hsd1.ca.comcast.net [67.180.208.218]) by elvis.mu.org (Postfix) with ESMTPSA id 9978E1A3C3F; Mon, 27 May 2013 18:10:11 -0700 (PDT) Message-ID: <51A403F3.1080905@mu.org> Date: Mon, 27 May 2013 18:10:11 -0700 From: Alfred Perlstein User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 MIME-Version: 1.0 To: Luigi Rizzo Subject: Re: copyin+copyout in one step ? References: <20130527233801.GA32042@onelab2.iet.unipi.it> <51A3F297.5000201@mu.org> In-Reply-To: <51A3F297.5000201@mu.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: current@freebsd.org X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.14 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: Tue, 28 May 2013 01:10:15 -0000 On 5/27/13 4:56 PM, Alfred Perlstein wrote: > On 5/27/13 4:38 PM, Luigi Rizzo wrote: >> Hi, >> say a process P1 wants to use the kernel to copy the content of a >> buffer SRC (in its user address space) to a buffer DST (in the >> address space of another process P2), and assume that P1 issues the >> request to the kernel when P2 has already told the kernel where the >> data should go: >> >> P1 P2 >> +------+ +--------+ >> | SRC | | DST | >> +--v---+ +--^-----+ >> --------|------------------------|---------- >> | | kernel >> | ^ >> >> | | >> | +--------+ | >> +----->| tmpbuf +--------+ >> copyin| | copyout >> P1 ctx+--------+ P2 ctx >> >> I guess the one above is the canonical way: P1 does a copyin() to a >> temporary buffer, then notifies P2 which can then issue or complete >> a syscall to do a copyout from tmpbuf to DST in P2's context. >> >> >> But I wonder, is it possible to do it as follows: P2 tells the kernel >> where the data should go (DST); later, P1 issues a system call and >> through a combined "copyinout()" moves data directly from SRC to DST, >> operating in the context of P1. >> >> | copyinout() ? | >> +------------>-----------+ >> issued by P1 >> >> >> Is this doable at all ? I suspect that "tell DST to the kernel" >> might be especially expensive as it needs to pin the page >> so it is accessible while doing the syscall for P1 ? >> (the whole point for this optimization is saving the extra >> copy through the buffer, but it may be pointless if pinning >> the memory is more expensive than the copy) >> > I suspect you'll want to use something like vslock(9) and sf_bufs. > > Have a look at vm/vm_glue.c -> vslock() vm_imgact_hold_page(). > > On amd64, I *think* mapping an sfbuf or if you are really evil you can > optimistically wire the page in the vm (cheap). If it's present then > you can just use the direct map to access it. However, if it's not > present, then fall back to another method, or maybe just fault it in > (which will have to happen anyhow) and then retry. > > Sounds like a cool project! > > -Alfred Oh, one other thing.. look at the pipe code. It used to do what you suggest, I think however it was driven by the READER pinning the WRITER's address space and doing a direct copy. However it may not be optimized for NOT-mapping into kva as I suggested doing. -Alfred