<br><br><div class="gmail_quote">On Tue, Mar 12, 2013 at 7:59 PM, <span dir="ltr"><<a href="mailto:Valdis.Kletnieks@vt.edu" target="_blank">Valdis.Kletnieks@vt.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="im">On Tue, 12 Mar 2013 18:38:05 +0530, Prabhu nath said:<br>
<br>
> On Sun, Mar 10, 2013 at 11:30 PM, Christoph Seitz <<a href="mailto:c.seitz@tu-bs.de">c.seitz@tu-bs.de</a>> wrote:<br>
<br>
</div><div class="im">> > I use a char device for reading and writing from/to a pcie dma card.<br>
> > Especially the read function makes me some headache. The user allocates<br>
> > some memory with posix_memalign and call the read function on the<br>
> > device, so that the devices knows where to write to. My driver now uses<br>
> > get_user_pages() to pin the user pages. The memory has never been<br>
> > written or read by the user, so it's not yet in the RAM, right? And<br>
> > get_user_pages returns a valid number of pages, but for every page the<br>
> > same struct. (respectively the same pointer). Is there any way to ensure<br>
> > that the user pages are in the ram and get_user_pages returns a valid<br>
> > page array?<br>
> ><br>
><br>
> If you know the RAM physical address range you can figure out by doing the<br>
> following<br>
</div>> *page_to_pfn(page_ptr) << 12*;<br>
<div class="im">> where page_ptr is a struct page * returned by get_user_pages().<br>
</div>> * page_to_pfn()* will return the pfn of the corresponding page frame and<br>
<div class="im">> left shifting by 12 bits will give you page frame base address.<br>
<br>
</div>Unfortunately, that doesn't actually tell you what Christoph was<br>
worried about - is the page *currently* in RAM? For that, you need<br>
to check some bits in the pfn once you find it.<br>
<br>
Also, note the following:<br>
<br>
It's not always 12, because not everything uses a 4K page - consider hugepage<br>
support, or Power and Itanium where the pages are bigger and often several<br>
different sizes are supported. There's an API for the current page size. Use<br>
it. :)<br></blockquote><div><br> Oops.. it should be page_to_pfn(page_ptr) << PAGE_SHIFT<br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Also, there's an API for pinning pages so they *stay* in RAM so you can target<br>
them for I/O. Use that. ;)<br>
</blockquote></div><br><br clear="all"><br>-- <br>Regards,<br>Prabhunath G<br>Linux Trainer<br>Bangalore<br>