public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: Short question about the mmap method
@ 2002-01-05 17:52 Douglas Gilbert
  0 siblings, 0 replies; 7+ messages in thread
From: Douglas Gilbert @ 2002-01-05 17:52 UTC (permalink / raw)
  To: Steffen Persvold; +Cc: linux-kernel

Steffen Persvold <sp@scali.no> 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 ?

Steffen,
I recently implemented the mmap() call in the SCSI generic
(sg) driver. See that driver in lk 2.4.17 or go to
   http://www.torque.net/sg 
and download version 3.1.22 of the sg driver from the table.
It will run on any kernel in the 2.4 series. It should
answer most of your questions (at least about mmap-ing
memory obtained from __get_free_pages() which is a bit 
tricky).  

Doug Gilbert

^ permalink raw reply	[flat|nested] 7+ messages in thread
* Short question about the mmap method
@ 2002-01-04 20:25 Steffen Persvold
  2002-01-04 20:59 ` Tommy Reynolds
  2002-01-05 14:17 ` Roman Zippel
  0 siblings, 2 replies; 7+ messages in thread
From: Steffen Persvold @ 2002-01-04 20:25 UTC (permalink / raw)
  To: lkml

Hi lkml readers,

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). When this application exits the page->count
should have been decremented by the kernel, but it seems like it doesn't since the page is reserved
and this causes a giant memleak when the driver is unloaded since the pages are not put back to the
free list unless page->count is zero (I do mem_map_unreserve before vfree). If I avoid using
mem_map_reserve (and _unreserve) the page count is 1 at the time I unload the driver and everything
goes fine.

The kernel I'm using is RedHat 7.2 2.4.9-12

One more question:

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) ?

Any ideas & comments are appreciated.

Thanks,
-- 
  Steffen Persvold   | Scalable Linux Systems |   Try out the world's best   
 mailto:sp@scali.no  |  http://www.scali.com  | performing MPI implementation:
Tel: (+47) 2262 8950 |   Olaf Helsets vei 6   |      - ScaMPI 1.12.2 -         
Fax: (+47) 2262 8951 |   N0621 Oslo, NORWAY   | >300MBytes/s and <4uS latency

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2002-01-06 10:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-01-05 17:52 Short question about the mmap method Douglas Gilbert
  -- strict thread matches above, loose matches on Subject: below --
2002-01-04 20:25 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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox