Linux – When page fault exception is thrown, how does the OS locate content on disk that has not yet been loaded into memory?

When page fault exception is thrown, how does the OS locate content on disk that has not yet been loaded into memory?… here is a solution to the problem.

When page fault exception is thrown, how does the OS locate content on disk that has not yet been loaded into memory?

When the content

that the CPU is trying to access has not been loaded into memory and throws a page exception, how can the OS locate the missing content on secondary storage (such as a hard disk)?

Thanks in advance for the explanation.

– Ivan

Solution

Short version:
Address bits for invalid PTEs are mapped to an offset within the secondary storage (swap file).

Longer version:
To understand what’s going on out there, let’s do a quick recap of how the virtual-to-physical conversion works. I will discuss the answer on the x86 platform.

The CR3 processor registers allocate 20 bits to point to the beginning of the page directory.
Which page directory entry (PDE) is used for the first 10-bit encoded address of the virtual address, which is an array of page table entries (PTEs), and which PTE is encoded by the next 10 bits in the address refers to the actual physical page problem. The last 12 bits are offset within the page.

When the operating system evicts a page from memory, the PTE is marked as invalid, and the address bit of the PTE becomes an offset in the page file (answer your original question).

Memory-mapped files are slightly more complex because they use prototype PTEs.

If you’re interested in more information, I highly recommend Mark Russinovich’s book “Windows Internals.”

Related Problems and Solutions