Open In App

Caching Page Tables

Last Updated : 12 May, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Paging is a memory management scheme which allows physical address space of a process to be non-contiguous. The basic idea of paging is to break physical memory into fixed-size blocks called frames and logical memory into blocks of same size called pages. While executing the process the required pages of that process are loaded into available frames from their source that is disc or any backup storage device. 

CPU generates logical address for the process which is divided into page number and page offset. The page table contains the base address of each page in physical memory. The base address combined with the page offset defines the physical memory address. The page number is used as an index into a page table. Page table is kept in main memory and a page table base register (PTBR) points to the page table. 

To access a location x, find entry in the page table, using the value in the PTBR offset by the page number for x. The page table entry gives the frame number, which is combined with the page offset to produce the actual address. We can then access the required memory location. Thus to access a location x , two memory accesses are required reducing the speed of the operation. 

A special, small, fast, lookup hardware cache called Translation Lookaside Buffer (TLB) is used to cache small number of entries from the page table. Each TLB entry consists of two parts: key(or tag) and value, here key is the page number and value is the frame number. All the entries of TLB are compared simultaneously with page number, the search is thus fast. A TLB typically contains 32–1024 entries. TLB is a hardware cache and modern computers implement it as a part of instruction pipeline thus causing no overhead of TLB search. 

 

If a page number is not found in TLB , it is called as a TLB miss, the corresponding frame number is taken from the page table and TLB is updated. Now if TLB is already full, an entry of TLB needs to be replaced with this new entry. Various policies are used for such replacement like Least Recently Used (LRU) , round-robin or random replacement. 

CPU today provides multi-level TLB. In case of L1 TLB miss, it is searched in L2 TLB and then in page table if L2 TLB is also a miss.The percentage of times that the page number of interest is found in the TLB is called the hit ratio (hit rate) and the percentage of times it is not found in the TLB is called the miss ratio (miss rate). Modern day systems have TLB miss rate of 0.1–1%, thus reducing overhead of accessing the page tables to a large extent. 

Some TLBs also store Address-Space Identifiers(ASIDS) in each TLB entry. It uniquely identifies each process and when translation of logical address to physical address is done, only those TLB entries are checked which belong to that process, if no such entry is found it is considered TLB miss. This allows TLB to have entries for several processes simultaneously.If TLB does not allow ASIDS, then every time a context switch happens (change the executing process from one process to another), the TLB needs to be flushed or erased to ensure that next executing process do not use the translation information from the previous process. 

Each TLB entry has a valid/invalid bit associated with it which signifies whether the TLB entry is valid or not. This is particularly useful when TLB is flushed, no actual deletion of TLB entry takes place, only all the entries of TLB are invalidated. Thus, before using the TLB entry for translation it is checked whether the entry is valid or not. Also, in case of TLB miss while updating a TLB entry, invalid entries are updated first. 

There are several other bits in a TLB entry like global bit(G) which is used for pages that are shared globally across processes, several bits for ASID (ignored for shared pages), dirty bit (to determine if the page has to be written) etc. All these bits are used in a general TLB entry. However, the actual size of entry, various protection bits in TLB entry, number of levels in TLB, number of TLB entries in each level etc varies from architecture to architecture.

Caching Page Tables is a technique used in virtual memory systems to improve the performance of memory accesses. In a traditional virtual memory system, the Page Table is stored in main memory and accessed whenever a memory access is performed. This can result in a significant overhead, as the time required to access the Page Table can be much longer than the time required to access the actual data.

To reduce this overhead, some virtual memory systems use a technique known as Page Table Caching. In Page Table Caching, a portion of the Page Table is stored in a cache, such as the Translation Lookaside Buffer (TLB) in the CPU. This allows for faster access to the Page Table and reduces the number of memory accesses required to perform a memory operation.

The cache used for Page Table Caching is typically a small, high-speed memory that is located on the CPU. When a memory access is performed, the CPU first checks the TLB to see if the required mapping is already present. If the mapping is present, the CPU can immediately access the corresponding physical memory location without accessing the main memory Page Table. If the mapping is not present in the TLB, a Page Table lookup is performed and the mapping is added to the TLB for future use.

Page Table Caching can provide significant performance improvements for memory access operations, especially in systems with large virtual address spaces. However, there are some limitations to this technique, such as the limited size of the TLB and the potential for cache misses when accessing virtual memory pages that are not currently present in the TLB. To mitigate these limitations, some systems use additional levels of caching, such as multi-level Page Table Caches or Translation Lookaside Buffers with larger sizes or more efficient replacement algorithms.

Hardware Support for Paging:

  • Memory Management Unit (MMU) for address translation.
  • Translation Lookaside Buffer (TLB) for caching frequently accessed page table entries.
  • Address translation caches, like the Address Translation Cache (ATC), for faster address translation.
  • TLB management mechanisms for handling TLB misses and efficient entry replacement.
  • Hardware-based page table walkers for optimized page table traversals.
  • Translation caches and buffering structures, such as MicroTLB or MiniTLB, for faster address translation closer to the CPU. 

Previous Article
Next Article

Similar Reads

Hashed Page Tables in Operating System
There are several common techniques for structuring page tables like Hierarchical Paging, Hashed Page Tables, and Inverted Page Tables. In this article, we will discuss the Hashed Page Table. Hashed Page Tables are a type of data structure used by operating systems to efficiently manage memory mappings between virtual and physical memory addresses.
4 min read
File Caching in Distributed File Systems
File caching enhances I/O performance because previously read files are kept in the main memory. Because the files are available locally, the network transfer is zeroed when requests for these files are repeated. Performance improvement of the file system is based on the locality of the file access pattern. Caching also helps in reliability and sca
12 min read
Difference between Buffering and Caching in OS
Both the term buffering and caching is related to storage and then access of data, but there are some key difference that makes them different. First let's see what both these term means and after that we will see the differences. 1. Buffering : In computer system when the speed in which data is received and the speed in which data is processed are
3 min read
Page Table Entries in Page Table
A Page Table is a data structure used by the operating system to keep track of the mapping between virtual addresses used by a process and the corresponding physical addresses in the system's memory. A Page Table Entry (PTE) is an entry in the Page Table that stores information about a particular page of memory. Each PTE contains information such a
7 min read
Difference Between Page Table and Inverted Page Table
Paging is a concept for storage management in operating systems that retrieve processes from secondary storage and store them in main memory as pages. The main concept behind paging is to divide each process into pages. Frames will also be used to divide the main memory. One page of the process is to be saved in one of the memory frames. In various
5 min read
Routing Tables in Computer Network
Routers: A Router is a networking device that forwards data packets between computer network. This device is usually connected to two or more different networks. When a data packet comes to a router port, the router reads address information in packet to determine out which port the packet will be sent. For example, a router provides you with the i
4 min read
Optimal Page Replacement Algorithm
Prerequisite: Page Replacement Algorithms In operating systems, whenever a new page is referred and not present in memory, page fault occurs and Operating System replaces one of the existing pages with newly needed page. Different page replacement algorithms suggest different ways to decide which page to replace. The target for all algorithms is to
19 min read
Belady's Anomaly in Page Replacement Algorithms
In Operating System, process data is loaded in fixed-sized chunks and each chunk is referred to as a page. The processor loads these pages in fixed-sized chunks of memory called frames. Typically the size of each page is always equal to the frame size. Prerequisite - Page Replacement Algorithms A page fault occurs when a page is not found in the me
9 min read
Second Chance (or Clock) Page Replacement Policy
Prerequisite - Page Replacement Algorithms Apart from LRU, OPT and FIFO page replacement policies, we also have the second chance/clock page replacement policy. In the Second Chance page replacement policy, the candidate pages for removal are considered in a round robin matter, and a page that has been accessed between consecutive considerations wi
16 min read
Implementation of Least Recently Used (LRU) page replacement algorithm using Counters
Prerequisite - Least Recently Used (LRU) Page Replacement algorithm Least Recently Used page replacement algorithm replaces the page which is not used recently. Implementation: In this article, LRU is implemented using counters, a ctime (i.e., counter) variable is used to represent the current time, it is incremented for every page of the reference
8 min read
Article Tags :