In computer operating systems, paging memory allocation (also called memory address translation) algorithms divide computer memory into small partitions, and allocates memory using a page as the smallest building block.
Because programs rarely use all parts of their code and data at one point in time, the concept of virtual memory can be implemented by writing pages to disk, and reading pages from disk when they are needed. This is another advantage of paging over other memory allocation techniques.
| Frame Number | Page Allocated to | Physical Memory Address |
|---|---|---|
| Program A.0 | 1000:0000 | |
| 1 | Program A.1 | 1000:1000 |
| 2 | Program A.2 | 1000:2000 |
| 3 | Program B.0 | 1000:3000 |
| 4 | Program B.1 | 1000:4000 |
| 5 | Program D.0 | 1000:5000 |
| 6 | Program D.1 | 1000:6000 |
| 7 | Program B.2 | 1000:7000 |
The above table is a possible page allocation list. (4K pages) This allocation could have happened in the following order
Consequently, Program A's page tables would contain the following mapping (Program's Page #=>OS Page #): (0=>0, 1=>1, 2=>2); Program B's : (0=>3,1=>4,2=>7); and Program D's : (0=>5, 1=>6).
Now let's consider what happens when a program wants to access its own memory. Let's say Program A contains a statement "LOAD memory at 20FE". What happens? Let's take a look at it now.
20FE is 0010000011111110 in binary notation (in a 16-bit system), and we have pages of 4K in size. So when a request for memory at 20FE is made, the MMU looks at it in this way :
0010000011111110 = 20FE __ | | | v v Relative memory address in page (00FE) Page Number (2)
Because we have pages 4096 bytes in size, the MMU looks at the first 4 bits for the page number, and the next 12 bits for the relative memory address in the page. If our pages were 2048 bytes in size, the MMU would look at the first 5 bits for the page number, and the next 11 bits for the relative memory address. So a smaller page size means more pages.
Thus, when this memory access request is made, the MMU looks at the program's page tables for the mapping to the OS page number. In this case, the second page of Program A maps to the second OS page. Then, it looks for the physical mapping of the OS page. The second OS page maps to the physical memory address 1000:2000, and the relative memory address that the program wants is 00FE, so the MMU will return memory at the physical address 1000:20FE.
This is a general description. Modern computer architectures use various means to speed up paging. For example on the Intel i386 architecture used in personal computers, among others, the CPU employs a special cache called Translation Lookaside Buffer which contains the mapping between a virtual memory address and the physical address it is backed by. Thus between the first time this mapping is obtained by page table lookups until the physical page is evicted or swapped out, the computationally expensive page table lookups need not be repeated, since the result is cached in the TLB. It is the job of the operating system to delete a particular entry from the TLB when this mapping becomes invalid. But as long as the entry is valid it can save thousands or millions of page table references.
Virtual memory | Memory management
Stránkování | Paging | Lehekülgede saalimine | Pagination | Paging | ページング方式 | Stronicowanie pamięci | Memória paginada | Stránkovanie