Search code examples
virtual-memorytlbpage-tables

When there's a page fault, do you read the page into the TLB as well as PT?


I'm currently learning virtual memory and I've come across a few questions about TLB miss and page fault. My understanding is:

When you have a TLB miss, you go to PT. If PT has a hit, then great, you copy the PT entry from memory to TLB.

When you have a TLB miss, and you also miss when you go to PT, then you go to the disk and copy the page to PT.

At this point, you've copied the page to PT, but do you update TLB? e.g., do you copy the page to TLB as well? Or do you only update PT?

Thanks!


Solution

  • You're leaving out some steps. First, you much check that the page table entry exists. It very well may not. In that case you have a memory access trap (of some kind depending upon what the system calls it). Second (entry exists), you have compare the access to the page and the processor mode with the those allowed by the page table entry. If not allowed, you have a memory access trap. Fourth, you check if the page is mapped to memory already. If so, all is well. If not, you generate a page fault exception. The OS has to handle that in some way.

    Fifth, the OS needs to restart the instruction that caused the fault.

    At that point, you probably could add the page to the TLB.