Translation lookaside buffer
Flushing the TLB
One other wrinkle occurs with TLBs. We saw that if a MMU keeps the page
table in registers, then every time a context switch occurs, the OS must
copy the new process's page table into the registers.
Similarly, when a context switch occurs when a TLB is being used, the
OS must take care that the MMU is using only PTEs from the new process,
not entries from the old process (because any two processes have different
page tables, and if one was not careful, the MMU might be using cached
PTEs from the old process instead of the new one.
-
Flush the TLB on every context switch. This ensures that all the PTEs for
the new process will be fetched initially from page tables in memory (but
thereafter they will be cached). Each PTE in the TLB has a 'valid' bit.
'Invalid' lines in the cache are ignored. Flushing the cache means invalidating
all the entries in the cache.
-
Include a 'context number' along with every PTE in the TLB. The OS allocates
every process a unique context ID, which is stored in a special MMU register
while the process is running. The context ID is implicitly added to the
front of every page number when the comparison is made with the entries
in the TLB. Only PTEs with a context ID matching the process's context
ID are matched. For example, processes 1 & 2. Process 1 accesses page
4, and the PTE for page 4 is stored in the TLB. Context switch. Thread
in process 2 accesses its page 4. MMU sees that the PTEs have different
context numbers and treats them as separate pages.
The SPARC processor uses 12-bit context numbers, allowing up to 4096 seperate
address spaces.
PTEs in the TLB must sometimes be invalidated for other reasons. For
example, when a page is swapped out of memory, to disk, its PTE in the
TLB must be marked as invalid. In fact in any case where a page table entry
is deleted or modified, the entry must be removed from the TLB if
it is there, forcing the MMU to read the updated entry from the page table
next time the page is accessed.
In the case of the SPARC, if a process were terminated, all the PTEs
with its context number would be flushed, to allow the context number to
be reused for another, new process.
last updated 24 March 1998