From: Roman Zippel <zippel@linux-m68k.org>
To: Steffen Persvold <sp@scali.no>
Cc: lkml <linux-kernel@vger.kernel.org>
Subject: Re: Short question about the mmap method
Date: Sat, 05 Jan 2002 15:17:35 +0100 [thread overview]
Message-ID: <3C370AFF.9385091A@linux-m68k.org> (raw)
In-Reply-To: <3C360FD5.91285F5D@scali.no>
Hi,
Steffen Persvold wrote:
> I have a question regarding drivers implementing the mmap and nopage methods. In some references
> I've read that pages in kernel allocated memory (either allocated with kmalloc, vmalloc or
> __get_free_pages) should be set to reserved (mem_map_reserve or set_bit(PG_reserved, page->flags)
> before they can be mmap'ed to guarantee that they can't be swapped out. Is this true ?
>
> The reason I ask is that I have a test driver that allocates some pages with vmalloc(), reserves
> them with mem_map_reserve(), and uses the "nopage" method to give a userspace app access to them.
> When the userpace app accesses the page, the "nopage" function is invoked as expected and the
> page->count is incremented (by the nopage function).
You must only set PG_reserved or only increment the page count. If you
increment the page count, the kernel will try to free memory by removing
the page from the process and reread the page later by calling the
nopage function again.
If you have the pages allocated all the time anyway, it's better to set
PG_reserved, but these pages can only be freed again when all files are
closed. You probably also want to set VM_RESERVED in vma->vm_flags, so
the kernel won't even look at these pages, while scanning the process
for freeable memory.
> When getting the "struct page" for pages allocated with vmalloc() I use the same method as
> drivers/media/video/bttv-driver.c (checking the page table). Somewhere (I think Rubini) I read that
> the init_mm.page_table_lock should be held before checking the page table. Is this true, or can it
> safely be done without doing that (the bttv-driver.c doesn't) ?
Currently this lock isn't needed, since noone will remove or change this
mapping until you call vfree().
bye, Roman
next prev parent reply other threads:[~2002-01-06 10:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-01-04 20:25 Short question about the mmap method Steffen Persvold
2002-01-04 20:59 ` Tommy Reynolds
2002-01-05 1:07 ` Steffen Persvold
2002-01-05 2:56 ` Steffen Persvold
2002-01-05 3:59 ` Steffen Persvold
2002-01-05 14:17 ` Roman Zippel [this message]
-- strict thread matches above, loose matches on Subject: below --
2002-01-05 17:52 Douglas Gilbert
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=3C370AFF.9385091A@linux-m68k.org \
--to=zippel@linux-m68k.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sp@scali.no \
/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