0

If the TLB is responsible for caching virtual and physical addresses, then what happens to it when a process tries to access an address space that doesn't belong to it? Can the TLB also handle empty address spaces?

I asked my TAs for my OS course and they didn't really have a concrete answer, would love some help.

tstanisl
  • 13,520
  • 2
  • 25
  • 40
  • The [wikipedia article](https://en.wikipedia.org/wiki/Translation_lookaside_buffer) has a decent explanation of the basics. Pages that don't belong to you should not be cached, the TLB [gets cleared at every context switch](https://superuser.com/questions/253424/the-tlb-changes-whenever-a-program-does-a-context-switch). – teapot418 Mar 22 '23 at 11:47

1 Answers1

2

CPU designers expect that programs will rarely, if ever, access unmapped addresses. Therefore, the TLB usually1 does not cache the fact that an address is unmapped. If the program does access an unmapped address, you'll have an ordinary TLB miss followed by a lookup failure in the actual page table, and it's the lookup failure that triggers the page fault. Similarly, if a page is mapped but not present, it won't1 be in the TLB, because the expectation is that the cost of making the page present again will dwarf the cost of a page table lookup.

However, the TLB can cache the fact that a page is mapped read-only, non-executable, supervisor only, etc., so you can get page faults triggered directly by the TLB in those cases.

1 I don't know every CPU design, it's possible that somebody somewhere tried making the TLB cache these things, but it's rare enough that I can't think of an example.

zwol
  • 135,547
  • 38
  • 252
  • 361