title: 5 BASIC MMAP RELATED QUERY
body: <p>Can you please help me understand below mentioned points w.r.t MMAP on LINUX:-</p>
  
  <p>a) Why is it essential that the memory returned by either KMALLOC , DMA_ALLOC_COHERENT                                should be PAGE_ALLIGNED to be used for MMAP                                             </p>
  
  <p>b) krnl_area=(int *)((((unsigned long)krnl_ptr) + PAGE_SIZE - 1)&amp;PAGE_MASK);
     Through some search I could figure out above code for the same,
     but I still not clear how it is done.</p>
  
  <p>c) How do I confirm PAGE which I have done MMAP and then reserved so 
     that they aren't swapped using SetPageReserved , has being correctly done 
     by kernel . </p>
  
  <p>i.e If I am doing an  SetPageReserved for say 4 PAGE which are MMAPEd, 
     how do I confirm it that the scheduler wont be swapping these pages as
     I have done  SetPageReserved on these pages. </p>
  
  <p>d) Is there any function to UN_RESERVED the page, I tried  SetUnPageReserved 
     but could not figure out header file for this function</p>
  
  <p>e) What is difference i.e which one among (1) &amp; (2) is the correct way to 
     provide physical address in remap_pfn_range ...</p>
  
  <p>(1)  (virt_to_phys((void *)krnl_ptr) >> PAGE_SHIFT) </p>
  
  <pre><code>     or
  </code></pre>
  
  <p>(2)  (vma->vm_pgoff)</p>
  
  <p>Because I have seen sample code using either (1) or (2) but could not 
     understand if they both are same or different?
     If different when to use which form?</p>