Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a TLB hit lead to page fault in memory?

In UC Berkley Video lectures on OS by John Kubiatowicz (Prof. Kuby) available on web, he mentioned that TLB hit doesn't mean that corresponding page is in main memory. Page fault can still occur.
Technically TLBs are cache for page table entry and since all page table entries don't have their corresponding page available in main memory. Same can be true for TLBs. A TLB hit may lead to page fault.

But according to algorithms given in text books I am unable to find such a case. On a TLB miss kernel refer to page tables and update the TLB cache for appropriate address translation. Next TLB hit can't lead to page fault. When kernel swap out the page, it updates the appropriate bits for that page table entry and invalidate the corresponding TLB, so there can't be a TLB hit next time until page is loaded in main memory.

So can someone stand for correctness of Prof kuby's claim and point out a case when instead of TLB hit (the translated physical address for corresponding virtual address in found in TLB), a page fault can occur?

like image 209
Terminal Avatar asked Jun 18 '11 20:06

Terminal


People also ask

Is a TLB miss a page fault?

Cache Miss, TLB Miss, and Page Fault If it matches, it's a cache hit. Otherwise, it's a cache miss. In this case, we use the physical address to get the block from memory, and the cache will be updated. TLB miss occurs if we don't find the page inside the TLB.

Is TLB updated after page fault?

The processor also updates the TLB to include the new page-table entry. Finally, if the present bit is not set, then the desired page is not in the main memory, and a page fault is issued. Then a page-fault interrupt is called, which executes the page-fault handling routine.

What happens on a TLB hit?

If a TLB hit occurs, the frame number from the TLB together with the page offset gives the physical address. A TLB miss causes an exception to reload the TLB from the page table, which the figure does not show.

Why do TLB misses happen?

A TLB miss occurs when no TLB entry can be found with a matching virtual page and address space ID (unless the global bit is set in which case the address space ID is ignored) with the valid bit set. The operating system creates the illusion of unlimited memory by using physical memory as a cache of virtual pages.


2 Answers

One example is if the memory access is different from the allowed one.

e.g. you want to write to memory that's write protected. A TLB exists, it's a hit and the address is translated. But on access you get a trap, as you're trying to write to memory that's read-only

like image 132
Lyke Avatar answered Oct 11 '22 13:10

Lyke


A page fault doesnt mean a missing page in the memory. A page can still be present and be dirty. This is also a page fault. On a general note, the page fault refers to the scenario where the obtained translation cannot be effectively used. It may be a missing page or a dirty page or access permission mismatch. So a TLB hit can still lead to a page fault.

like image 45
AcidBurn Avatar answered Oct 11 '22 14:10

AcidBurn