0

I have identified that the function do_swap_page in mm/memory.c is used to swap IN pages in the Linux kernel. However, the input parameters of this function contains one pte_t* and one pte_t. What is the difference between the use of these two parameters? Any help would be appreciated.

static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma, 
unsigned long address, pte_t *page_table, pmd_t *pmd, 
unsigned int flags, pte_t orig_pte)
S. Salman
  • 590
  • 1
  • 6
  • 22
  • 1
    Latest [do_swap_page](http://lxr.free-electrons.com/source/mm/memory.c#L2534) accepts single pointer to `struct vm_fault`. Every field of that structure is described with the [definition of the struct](http://lxr.free-electrons.com/source/include/linux/mm.h#L294) itself. Probably, you will find it useful for your purposes. – Tsyvarev Feb 27 '17 at 09:40
  • Thanks for the response @Tsyvarev. Your answer is helpful but I still don't get the need to pass both parameters or the difference between them. – S. Salman Mar 01 '17 at 08:23

1 Answers1

2

With 4.4 do_swap_page still has many parameters: http://lxr.free-electrons.com/source/mm/memory.c?v=4.4#L2439

2446 static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
2447                 unsigned long address, pte_t *page_table, pmd_t *pmd,
2448                 unsigned int flags, pte_t orig_pte)

and it is called from handle_pte_fault function http://lxr.free-electrons.com/source/mm/memory.c?v=4.4#L3257

3272 static int handle_pte_fault(struct mm_struct *mm,
3273                      struct vm_area_struct *vma, unsigned long address,
3274                      pte_t *pte, pmd_t *pmd, unsigned int flags)
3275 {
3276         pte_t entry;
3287         entry = *pte;
3289         if (!pte_present(entry)) {
3298                 return do_swap_page(mm, vma, address,
3299                                         pte, pmd, flags, entry);

So, second pte_t orig_pte is just copy of original pte, and pte_t *page_table is the pointer to the pte entry which will be modified with new pte (actual code will be something like *page_table = pte):

 2560         pte = mk_pte(page, vma->vm_page_prot);
 2570         set_pte_at(mm, address, page_table, pte);
osgx
  • 90,338
  • 53
  • 357
  • 513