In computer operating systems there are various ways in which the operating system can store and retrieve data from secondary storage for use in main memory. One such memory management scheme is referred to as paging . In the paging memory-management scheme, the operating system retrieves data from secondary storage in same-size blocks called pages . The main advantage of paging is that it allows the physical address space of a process to be noncontiguous. Prior to paging, systems had to fit whole programs into storage contiguously which caused various storage and fragmentation problems.

Paging is an important part of virtual memory implementation in most contemporary general-purpose operating systems, allowing them to use disk storage for data that does not fit into physical Random-access memory (RAM). Paging is usually implemented as architecture-specific code built into the kernel of the operating system.

Overview

The main functions of paging are performed when a program tries to access pages that are not currently mapped to physical memory (RAM). This situation is known as a page fault. The operating system must then take control and handle the page fault, in a manner invisible to the program. Therefore, the operating system must:

  1. Determine the location of the data in auxiliary storage.
  2. Obtain an empty page frame in RAM to use as a container for the data.
  3. Load the requested data into the available page frame.
  4. Update the page table to show the new data.
  5. Return control to the program, transparently retrying the instruction that caused the page fault.

The need to reference memory at a particular address arises from two main sources:

  • Processor trying to load and execute a program's instructions itself.
  • Data being accessed by a program's instruction.

In step 2, when a page has to be loaded and all existing pages in RAM are currently in use, one of the existing pages must be swapped with the requested new page. The paging system must determine the page to swap by choosing one that is least likely to be needed within a short time. There are various page replacement algorithms that try to answer such issue.

Most operating systems use some approximation of the least recently used (LRU) page replacement algorithm (the LRU itself cannot be implemented on the current hardware) or working set based algorithm.

If a page chosen to be swapped has been modified since loading (if the page is dirty ), it has to be written to auxiliary storage, otherwise it is simply discarded.

In addition to swapping in pages because they are necessary, in reaction to a page fault, there are several strategies for guessing what pages might be needed, and speculatively pre-loading them.

Demand paging

Main article: Demand paging

Demand paging refuses to guess. With demand paging, no pages are brought into RAM until necessary. In particular, with demand paging, a program usually begins execution with none of its pages pre-loaded in RAM. Pages are copied from the executable file into RAM the first time the executing code references them, usually in response to a page fault. During a particular run of a program, pages of the executable file that implement functionality not used on that particular run are never loaded.

Anticipatory paging

This technique preloads a process's non-resident pages that are likely to be referenced in the near future (taking advantage of locality of reference). Such strategies attempt to reduce the number of page faults a process experiences.

Swap prefetch

A few operating systems use anticipatory paging, also called swap prefetch. These operating systems periodically attempt to guess which pages will soon be needed, and start loading them into RAM. There are various heuristics in use, such as "if a program references one virtual address which causes a page fault, perhaps the next few pages' worth of virtual address space will soon be used" and "if one big program just finished execution, leaving lots of free RAM, perhaps the user will return to using some of the programs that were recently paged out" .

Pre-cleaning

Unix operating systems periodically use sync to pre-clean all dirty pages, that is, to save all modified pages to hard disk. Windows operating systems do the same thing via "modified page writer" threads.

This makes starting a large new program run much faster, because it can be loaded into page frames that held dirty pages that were cleaned, rather than being loaded into page frames that were dirty and needed to be written back to disk before they were dropped.

Thrashing

Main article: Thrash (computer science)

Most programs reach a steady state in their demand for memory locality both in terms of instructions fetched and data being accessed. This steady state is usually much less than the total memory required by the program. This steady state is sometimes referred to as the working set: the set of memory pages that are most frequently accessed.

Virtual memory systems work most efficiently when the ratio of the working set to the total number of pages that can be stored in RAM is low enough to minimize the number of page faults. A program that works with huge data structures will sometimes require a working set that is too large to be efficiently managed by the page system resulting in constant page faults that drastically slow down the system. This condition is referred to as thrashing: pages are swapped out and then accessed causing frequent faults.

An interesting characteristic of thrashing is that as the working set grows, there is very little increase in the number of faults until the critical point (when faults go up dramatically and majority of system's processing power is spent on handling them).

An extreme example of this sort of situation occurred on the IBM System/360 Model 67 and IBM System/370 series mainframe computers, in which a particular instruction could consist of an execute instruction, which crosses a page boundary, that the instruction points to a move instruction, that itself also crosses a page boundary, targeting a move of data from a source that crosses a page boundary, to a target of data that also crosses a page boundary. The total number of pages thus being used by this particular instruction is eight, and all eight pages must be present in memory at the same time. If the operating system will allocate less than eight pages of actual memory in this example, when it attempts to swap out some part of the instruction or data to bring in the remainder, the instruction will again page fault, and it will thrash on every attempt to restart the failing instruction.

To decrease excessive paging, and thus possibly resolve thrashing problem, a user can do any of the following:

  • Increase the amount of RAM in the computer (generally the best long-term solution).
  • Decrease the number of programs being concurrently run on the computer.

The term thrashing is also used in contexts other than virtual memory systems, for example to describe cache issues in computing or silly window syndrome in networking.

Terminology

Historically, paging sometimes referred to a memory allocation scheme that used fixed-length pages as opposed to variable-length segments, without implicit suggestion that virtual memory technique were employed at all or that those pages were transferred to disk. Such usage is rare today.

Some modern systems use the term swapping along with paging . Historically, swapping referred to moving from/to secondary storage a whole program at a time, in a scheme known as roll-in/roll-out. In the 1960s, after the concept of virtual memory was introduced—in two variants, either using segments or pages—the term swapping was applied to moving, respectively, either segments or pages, between disk and memory. Today with the virtual memory mostly based on pages, not segments, swapping became a fairly close synonym of paging , although with one difference.

In many popular systems, there is a concept known as page cache, of using the same single mechanism for both virtual memory and disk caching. A page may be then transferred to or from any ordinary disk file, not necessarily a dedicated space. Page in is transferring a page from the disk to RAM. Page out is transferring a page from RAM to the disk. Swap in and out only refer to transferring pages between RAM and dedicated swap space or swap file , and not any other place on disk.

On Windows NT based systems, dedicated swap space is known as a page file and paging/swapping are often used interchangeably.

Implementations

Windows 3.x and Windows 9x

Virtual memory has been a feature of Microsoft Windows since Windows 3.0 in 1990. Microsoft introduced virtual memory in response to the failures of Windows 1.0 and Windows 2.0, attempting to slash resource requirements for the operating system.

Confusion abounds about Microsoft's decision to refer to the swap file as "virtual memory". Novices unfamiliar with the concept accept this definition without question, and speak of adjusting Windows' virtual memory size. In fact every process has a fixed, unchangeable virtual memory size, usually 2 GB. The user has only an option to change disk capacity dedicated to paging.

<

Paging file functionality requires system account permissions and ...

You may receive the following error message while Windows starts: The system has no paging file, or the paging file is too small. However, if you look at the configuration settings ...

...

TrueCrypt - Free Open-Source Disk Encryption Software - Documentation ...

Paging File. Note: The issue described below does not affect you if the system partition or system drive is encrypted (for more information, see the chapter System Encryption) and ...

...

How to configure paging files for optimization and recovery in Windows ...

The paging file (Pagefile.sys) is a hidden file on your computer's hard disk that Windows XP uses as if it were random access memory (RAM). The paging file and physical memory make ...

...

The Windows XP Page File

Useful information about Windows XP including tweaks, guides, installation tips, registry edits, pagefile sizing, updates, and an XP Forum.

...

Amazon.com: "paging file": Key Phrase page

Key Phrase page for paging file: Books containing the phrase paging file

...

Paging File

Author Topic: Paging File (Read 1007 times) 0 Members and 1 Guest are viewing this topic.

...

Paging File Definition - What Is A Paging File?

Paging File Definition From Free Online Computer Dictionary.

...

Paging file definition of Paging file in the Free Online Encyclopedia.

paging (1) In a virtual memory computer, it is the transfer of program segments (pages) into and out of memory. Although paging is the primary mechanism for virtual memory ...

...

Paging file cache extremely fragmented.. help - PC Perspective Forums

Paging file cache extremely fragmented.. help Storage Forum

...

Paging - Wikipedia, the free encyclopedia

In computer operating systems there are various ways in which the operating system can store and retrieve data from secondary storage for use in main memory.

...