Paging

Alternate meanings: See paging (telecommunications). Bank switching is also sometimes referred to as paging.


In computer operating systems, paging memory allocation algorithms divide computer memory into small partitions, and allocates memory using a page as the smallest building block.

Contents

Advantages

A key advantage that this method has over simpler methods such as the buddy memory allocation technique and dynamic allocation techniques is that the memory allocated to a program does not have to be contiguous, and because of that, there is very little internal fragmentation - thus little memory is wasted.

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.

Disadvantages

The only major disadvantage of paging is the relatively complicated nature of the code required to handle it, especially if virtual memory is to be implemented. Otherwise, there are only minor disadvantages such as the need for a memory management unit (MMU), which means that paging cannot be implemented on some older or smaller processors (in the Intel x86 family, for example, only 80386 and higher CPUs possess MMUs).

How it works

The memory access part of paging is done at the hardware level, and is handled by the memory management unit (MMU for short). As mentioned earlier, physical memory is divided into small blocks (typically 4 kilobytes or less) in size, and each block is assigned a page number. The operating system may keep a list of free pages in its memory, or may choose to probe the memory each time a memory request is made (though most modern operating systems do the latter). Whatever the case, when a program requests for memory, the operating system allocates a number of pages to the program, and keeps a list of allocated pages for that particular program in memory. Now, let us take a look at an example.

Page NumberProgram Allocated toPhysical Memory Address
0Program A.01000:0000
1Program A.11000:1000
2Program A.21000:2000
3Program B.01000:3000
4Program B.11000:4000
5Program D.01000:5000
6Program D.11000:6000
7Program B.21000:7000

Figure 1 - A possible page allocation list. (4K pages) This allocation could have happened in the following order

  1. Program A requests 3 pages of memory
  2. Program C requests 2 pages of memory
  3. Program D requests 2 pages of memory
  4. Program C terminates, leaving 2 empty pages
  5. Program B requests 3 pages of memory, and it is allocated the 2 empty pages that program C left, plus an additional page after program D

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).

Ok. So far so good. But 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 (4096-1 = 4095 can be represented by 12 bits in binary) 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 smaller pages mean 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 particularly 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.

Paging and virtual memory

When paging is used alongside with virtual memory, the operating system has to keep track of pages in use and pages which will not be used or have not been used for some time. Then, when the operating system deems fit, or when a program requests a page that has been swapped out, the operating system swaps out a page to disk, and brings another page into memory. (See Page replacement algorithms for more details as to how the operating system decides which page to swap in and out.) In this way, you can use more memory than your computer physically has.de:Paging et:Lehekülgede saalimine

Navigation

  • Art and Cultures
    • Art (https://academickids.com/encyclopedia/index.php/Art)
    • Architecture (https://academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (https://www.academickids.com/encyclopedia/index.php/Cultures)
    • Music (https://www.academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (http://www.academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (http://www.academickids.com/encyclopedia/index.php/Clipart)
  • Geography (http://www.academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
    • Maps (http://www.academickids.com/encyclopedia/index.php/Maps)
    • Flags (http://www.academickids.com/encyclopedia/index.php/Flags)
    • Continents (http://www.academickids.com/encyclopedia/index.php/Continents)
  • History (http://www.academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (http://www.academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (http://www.academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
    • United States (http://www.academickids.com/encyclopedia/index.php/United_States)
    • Wars (http://www.academickids.com/encyclopedia/index.php/Wars)
    • World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (http://www.academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (http://www.academickids.com/encyclopedia/index.php/Reference)
  • Science (http://www.academickids.com/encyclopedia/index.php/Science)
    • Animals (http://www.academickids.com/encyclopedia/index.php/Animals)
    • Aviation (http://www.academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (http://www.academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (http://www.academickids.com/encyclopedia/index.php/Earth)
    • Inventions (http://www.academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (http://www.academickids.com/encyclopedia/index.php/Plants)
    • Scientists (http://www.academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (http://www.academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (http://www.academickids.com/encyclopedia/index.php/Economics)
    • Government (http://www.academickids.com/encyclopedia/index.php/Government)
    • Religion (http://www.academickids.com/encyclopedia/index.php/Religion)
    • Holidays (http://www.academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (http://www.academickids.com/encyclopedia/index.php/Planets)
  • Sports (http://www.academickids.com/encyclopedia/index.php/Sports)
  • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
  • Weather (http://www.academickids.com/encyclopedia/index.php/Weather)
  • US States (http://www.academickids.com/encyclopedia/index.php/US_States)

Information

  • Home Page (http://academickids.com/encyclopedia/index.php)
  • Contact Us (http://www.academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (http://classroomclipart.com)
Toolbox
Personal tools