public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Nick Piggin <nickpiggin@yahoo.com.au>
To: Laurent Pinchart <laurent.pinchart@skynet.be>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: VM_RESERVED and PG_reserved : Allocating memory for video buffers
Date: Fri, 16 Dec 2005 12:27:35 +1100	[thread overview]
Message-ID: <43A21807.70504@yahoo.com.au> (raw)
In-Reply-To: <200512152009.33758.laurent.pinchart@skynet.be>

Laurent Pinchart wrote:
> Hi everybody,
> 
> I'm writing a Linux driver for a USB Video Class compliant USB device. I 
> manage to understand pretty much everything on my own until the point where I 
> have to allocate video buffers.
> 
> I read other drivers to understand how they proceed. Most of them used vmalloc 
> with SetPageReserved and remap_pfn_range to map the memory to user space. I 
> thought I understood that, when I noticed that vm_insert_page has been added 
> in 2.6.15. I wasn't sure how to prevent pages from being swapped out, so I 
> read the excellent "Understanding the Linux Virtual Memory Manager", but I'm 
> still not sure to understand everything. This is where I ask for your help.
> 
> I need to allocate big buffers, so vmalloc is the way to go, as I don't need 
> contiguous memory. I need to map those buffers to user space, and I 
> understand that vm_insert_page will do the job nicely. My fears come from 
> pages being swapped out. I suppose I need to prevent that, as a page fault in 
> interrupt is a Bad Thing(TM). I'm not sure how PG_reserved and VM_RESERVED 
> interract with eachother. Can kernel pages be swapped out if they are not 
> mapped to user space ? Or does kswapd only walk VMAs when it tries to find 
> pages that will be swapped out ? If the later is true, is it enough to set 
> VM_RESERVED on the VMA in the mmap handler ?
> 

PG_reserved no longer does anything (except catching bugs in old code).
If you are writing new code, you shouldn't use it. Don't copy rvmalloc,
you should be able to use vmalloc directly.

vm_insert_page is indeed the right interface for mapping these pages
into userspace.

You do not have to worry about pages being swapped out, and you shouldn't
need to set any unusual vma or page flags. kswapd only walks the lru lists,
and it won't even look at any other pages.

Good luck,
Nick

-- 
SUSE Labs, Novell Inc.

Send instant messages to your online friends http://au.messenger.yahoo.com 

  reply	other threads:[~2005-12-16  1:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-15 19:09 VM_RESERVED and PG_reserved : Allocating memory for video buffers Laurent Pinchart
2005-12-16  1:27 ` Nick Piggin [this message]
2005-12-16 11:33   ` Laurent Pinchart
2005-12-16 13:34     ` Nick Piggin
2005-12-16 14:10       ` Markus Rechberger

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=43A21807.70504@yahoo.com.au \
    --to=nickpiggin@yahoo.com.au \
    --cc=laurent.pinchart@skynet.be \
    --cc=linux-kernel@vger.kernel.org \
    /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