mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jeremy Elson <jelson@circlemud.org>
To: Marcelo Tosatti <marcelo@conectiva.com.br>
Cc: Alexander Viro <viro@math.psu.edu>, linux-kernel@vger.kernel.org
Subject: Re: Mapping a piece of one process' addrspace to another?
Date: Wed, 07 Mar 2001 00:13:30 -0800	[thread overview]
Message-ID: <200103070813.f278DUw06475@servo.isi.edu> (raw)
In-Reply-To: Message from Marcelo Tosatti <marcelo@conectiva.com.br>  of "Wed, 07 Mar 2001 03:02:14 -0300." <Pine.LNX.4.21.0103070301310.1548-100000@freak.distro.conectiva>

Marcelo Tosatti writes:
>On Wed, 7 Mar 2001, Alexander Viro wrote:
>> You are reinventing the wheel.
>> man ptrace (see PTRACE_{PEEK,POKE}{TEXT,DATA} and PTRACE_{ATTACH,CONT,DETACH})
>
>With ptrace data will be copied twice. As far as I understood, Jeremy
>wants to avoid that. 

Yes - I've been looking at the sys_ptrace code and it seems that it
does two copies through the kernel (but, using access_process_vm
instead of copy_from_user -- I'm not sure how they differ).  I'm
trying to reduce the number of copies by giving one process a pointer
into another process's address space.

Right now, my code looks something like this: (it might make more
sense if you know that I've written a framework for writing user-space
device drivers... I'm going to be releasing it soon, hopefully after I
resolve this performance problem.  Or maybe before, if it's hard.)

   Process X: (any arbitrary process)
        read(fd, my_local_buffer);
   Kernel:
        [notifies process Y that X needs data]
   Process Y: (the userspace device driver)
        memcpy(my_local_buffer, data_destined_for_process_x);
        write(fd, my_local_buffer);
   Kernel (in sys_write:)
        copy_from_user(kernel_buffer, Y's my_local_buffer);
        copy_to_user(X's my_local_buffer, kernel_buffer);     

Now, this all works fine, but it's slower than I'd like.  I used SGI's
kernprof (oss.sgi.com/projects/kernprof) and found that the kernel was
spending most of its time (like 70%) in copy_to_user and
copy_from_user.  So, I am hoping to make this all go faster, while
hopefully preserving correctness, by changing to something like this:

   Process X:
        read(fd, my_local_buffer);
   Kernel:
        [maps X's my_local_buffer to Y's address space]
        [notifies process Y that X needs data, and sends along a
	 pointer to write data to, or a handle usable by shmat,
         or something]
   Process Y:
         memcpy(X's my_local_buffer, data_destined_for_process_x);

If I'm lucky we can avoid both copy_to_user and copy_from_user.

This would be easy if X was a "cooperative" process because we could
just set up a shared memory segment between the two processes.  The
problem is that X is not cooperative -- it can be any existing
program.

Regards,
Jeremy

  reply	other threads:[~2001-03-07  8:14 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-07  5:19 Jeremy Elson
2001-03-07  5:55 ` Alexander Viro
2001-03-07  6:02   ` Marcelo Tosatti
2001-03-07  8:13     ` Jeremy Elson [this message]
2001-03-07  8:40       ` Alexander Viro
2001-03-07  8:54         ` Jeremy Elson
2001-03-07  9:09           ` Alexander Viro
2001-03-07 23:22             ` James H. Cloos Jr.
2001-03-07  9:04         ` Abramo Bagnara
2001-03-07  9:10           ` Alexander Viro
2001-03-07  9:20             ` Abramo Bagnara
2001-03-07  9:49               ` Alexander Viro
2001-03-07 13:01                 ` Abramo Bagnara
2001-03-07 21:02                 ` Jeremy Elson
2001-03-07  8:58       ` Abramo Bagnara
2001-03-07 18:17     ` Pavel Machek
2001-03-07 10:51 Manfred Spraul
2001-03-07 13:57 Jesse Pollard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200103070813.f278DUw06475@servo.isi.edu \
    --to=jelson@circlemud.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcelo@conectiva.com.br \
    --cc=viro@math.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®