Search code examples
linuxoperating-systemkernelminix

How does the OS know disk address of an absent page?


Paging acts as indirection layer between virtual address space and physical address space. Given an address, the Operating System(OS)/Memory Management Unit(MMU) translates it to a primary memory location.

My questions are:

In the scenario that the page is absent in primary memory

  1. How does the OS know where to find the page on disk?
  2. Where does it store information for 1?(It is not stored in the page table entry). Links to code examples would be great!

Solution

  • You can find the detailed explanation of the process here

    1. How does the OS know where to find the page on disk?

    2. Where does it store information for 1?(It is not stored in the page table entry). Links to code examples would be great!

    Everything kernel needs to know is actually stored in PTE (it stores index to swap_info and offset within the swap_map).

    swap_info_struct is there for every swap area (file or the partition), so using the first index kernel knows in what area to look. Now every area has a swap_map which is an array with elements that are one page each. Using offset stored in PTE, it can access the particular page.