From owner-freebsd-current@FreeBSD.ORG Tue May 28 04:30:35 2013 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 58998B31 for ; Tue, 28 May 2013 04:30:35 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) by mx1.freebsd.org (Postfix) with ESMTP id A9F3B6DA for ; Tue, 28 May 2013 04:30:34 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.7/8.14.7) with ESMTP id r4S4UKo4054903; Tue, 28 May 2013 07:30:20 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.8.3 kib.kiev.ua r4S4UKo4054903 Received: (from kostik@localhost) by tom.home (8.14.7/8.14.7/Submit) id r4S4UKjm054900; Tue, 28 May 2013 07:30:20 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Tue, 28 May 2013 07:30:20 +0300 From: Konstantin Belousov To: Luigi Rizzo Subject: Re: copyin+copyout in one step ? Message-ID: <20130528043020.GK3047@kib.kiev.ua> References: <20130527233801.GA32042@onelab2.iet.unipi.it> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="r8byAqrdRIFBlIsc" Content-Disposition: inline In-Reply-To: <20130527233801.GA32042@onelab2.iet.unipi.it> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on tom.home 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 04:30:35 -0000 --r8byAqrdRIFBlIsc Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, May 28, 2013 at 01:38:01AM +0200, 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: >=20 > P1 P2 > +------+ +--------+ > | SRC | | DST | > +--v---+ +--^-----+ > --------|------------------------|---------- > | | kernel > | ^ >=20 > | | > | +--------+ | > +----->| tmpbuf +--------+ > copyin| | copyout > P1 ctx+--------+ P2 ctx >=20 > 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. >=20 >=20 > 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. >=20 > | copyinout() ? |=20 > +------------>-----------+ > issued by P1 >=20 >=20 > 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) Yes, it is doable. If the copy can happen when either P1 or P2 are active context, then proc_rwmem() already perform exactly what you want. The virtual address in the address space of the 'other process' is specified as uio->uio_offset. The iov specifies the region(s) for the current process. If you want to perform the copy from P1 to P2 while some other context P3 is active, the same structure as proc_rwmem() would work, but you=20 obviously would need to do vm_fault_hold() for both sides, and use pmap_copy_pages() instead of uiomove_fromphys(). In either case, you get copy without temporal buffer, but the setup cost could be non-trivial. You never know until measured. --r8byAqrdRIFBlIsc Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.20 (FreeBSD) iQIcBAEBAgAGBQJRpDLbAAoJEJDCuSvBvK1BicIP/1HZ6RCNYOptpCPACQSbbmlS ZxI5JNperAKY9c1eTaAH1FhaSAfdXs47NCf1Lf+vfZTo6eSUEvbP0GAfPEMCI1r5 QVlGZVbShP626DwnrEfmaAuv9Es8vANOm259Coi/3G5LN/NxurHs+1RgLvHu48tD j0dZnfsWmlvwR0XEjPQPn4SZXfUr5Poj0ezf9s8Vz4foA2RJSA3RZo79HwYFSBbp ppM0gJzGMYa/XQtiSfxwa1M13GCnwJ9H4oUJCgQ+fnO6GWJS/jJbDezhi+Ec3A1O 6VfmIL58v19PmqPsH/k0hMvLXOZeqPDfuhf7ClmSjXOLSB4EVVojf1bd1JkM3v5R 65UuGne2C/0FfWwbznkL4ut8DavF3oZO9K+Lc3X6z7303E1Iq9fMn2beB9IevWpC bWh6ggFLcS3KFbb+T1dSNLwJhJbE0H8eOWMWyZ6mh/w00iQdHVDklywhBigfKTv2 o71ODhpvFVgzB0DmVDmLovyXM/xlZCNZq28a49kYzCJKAH8j7IQjL+PQ6eX3SjgR yyxjxpQNjMUAtJR8VR+t4EcVCx710OKQ44c6tavseNox8w8Kvn6Xxu00kX+UJSHS R3l0awZbI6WLnd5XH5ONdsMRiut2zigkOUubKv1daSG6ISnY0IDO44vK71litOnq 9m8cn8ntoFMEmJzPNWJq =Jz0x -----END PGP SIGNATURE----- --r8byAqrdRIFBlIsc--