linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Stephen C. Tweedie" <sct@redhat.com>
To: David Woodhouse <dwmw2@infradead.org>
Cc: "Stephen C. Tweedie" <sct@redhat.com>,
	lord@sgi.com, linux-kernel@vger.rutgers.edu, linux-mm@kvack.org,
	riel@conectiva.com.br
Subject: Re: kmap_kiobuf()
Date: Thu, 29 Jun 2000 10:09:33 +0100	[thread overview]
Message-ID: <20000629100933.A3473@redhat.com> (raw)
In-Reply-To: <Pine.LNX.4.21.0006281930220.987-100000@imladris.demon.co.uk>; from dwmw2@infradead.org on Wed, Jun 28, 2000 at 07:45:57PM +0100

Hi,

On Wed, Jun 28, 2000 at 07:45:57PM +0100, David Woodhouse wrote:
> On Wed, 28 Jun 2000, Stephen C. Tweedie wrote:
> 
> > The pinning of user buffers is part of the reason we have kiobufs.
> > But why do you need to pass it to functions expecting kernel buffers?  
> 
> So far I've encountered two places where I've wanted to do this.
> 
> First, in copying a packet from userspace to a PCI card, where I have to
> have interrupts disabled locally (spin_lock_irq()).

How much data is involved?

If it's not too much, then your current scheme looks like the right
way to do this.  You really should try to keep things per-page and not
rely on the pages being contiguous, since using the kernel's vmalloc
area for contiguifying the pages will be enormously expensive on SMP.
I can certainly add kiobuf support routines for kmapping and
memcpy()ing kiobuf pages to the kiobuf core patches to clean the code
a bit.

> If it's really that difficult to map them contiguously into VM, I suppose
> it can stay the way it is - actually I can probably get away without the
> array of virtual addresses by discarding the return value of kmap() and
> using page_address() from within the spinlock, can't I?

Yes, that should work fine.

> Secondly, for the character device access to MTD devices. Almost all
> access to MTD devices uses kernel-space buffers. I don't really want to
> bloat _every_ MTD driver by making it conditionally user/kernel.
> 
> The only exception is the direct chardevice access, for which I'm
> currently using bounce buffers, but would like to just lock down the pages
> and pass a contiguously-mapped VM address instead.

Why does it need to be *contiguous*???  The right way to code this is
most definitely in terms of kiobufs.  That's basically the only way
we'll support user-space direct access.  If I can give you a
memcpy_to_kiovec() and memcpy_from_kiovec() patch, then that gives you
a canonical way of representing buffers from either user or kernel
space without any assumption at all that the pages are contiguous, and
you get direct IO for free.

The whole point of kiobufs is to abstract away the source of the
pages.  You don't have to know whether the pages were originally
kernel or user space.

> I noticed that kmap ptes seem to be allocated from array of static size,
> which is different to the method used for vmalloc(). Why is this?

vmalloc() and kmap() are meant for completely different purposes.
vmalloc() is designed for long-term persistent regions (such as
loadable moules).  However, it is slow.  kmap() is very fast, but is
designed for transient mappings of individual pages.  The fixed kmap
pte list is used as a ring buffer.  If we kmap a page twice without
wrapping, we can reuse the old virtual address of the page, so it's
pretty fast to repeatedly kmap and kunmap a single page (there's a
spinlock cost but not much more).  

The big advantage of kmap is that we only have to do an SMP TLB IPI
once every wrap of the kmap ring buffer.  vmalloc incurs that cost
every time.

Cheers,
 Stephen
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/

  reply	other threads:[~2000-06-29  9:09 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-06-28 15:54 kmap_kiobuf() lord
2000-06-28 16:06 ` kmap_kiobuf() David Woodhouse
2000-06-28 16:24   ` kmap_kiobuf() Benjamin C.R. LaHaise
2000-06-28 18:07   ` kmap_kiobuf() Stephen C. Tweedie
2000-06-28 18:45     ` kmap_kiobuf() David Woodhouse
2000-06-29  9:09       ` Stephen C. Tweedie [this message]
2000-06-28 17:46 ` kmap_kiobuf() Stephen C. Tweedie
  -- strict thread matches above, loose matches on Subject: below --
2000-06-28 20:16 kmap_kiobuf() lord
2000-06-28 21:22 ` kmap_kiobuf() Benjamin C.R. LaHaise
2000-06-29  9:34 ` kmap_kiobuf() Stephen C. Tweedie
2000-06-29 13:45   ` kmap_kiobuf() Steve Lord
2000-06-28 16:52 kmap_kiobuf() lord
2000-06-28 18:06 ` kmap_kiobuf() Stephen C. Tweedie
2000-06-28 19:06   ` kmap_kiobuf() Manfred Spraul
2000-06-28 21:05   ` kmap_kiobuf() Andi Kleen
2000-06-28 15:41 kmap_kiobuf() David Woodhouse
2000-06-28 17:44 ` kmap_kiobuf() Stephen C. Tweedie
2000-06-29 10:52 ` kmap_kiobuf() Stephen C. Tweedie

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=20000629100933.A3473@redhat.com \
    --to=sct@redhat.com \
    --cc=dwmw2@infradead.org \
    --cc=linux-kernel@vger.rutgers.edu \
    --cc=linux-mm@kvack.org \
    --cc=lord@sgi.com \
    --cc=riel@conectiva.com.br \
    /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