Tuesday, December 29, 2009

Types of PAGING in Operating System

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.

Loader Paging

Loader paging[original research?] guesses that the entire program will be used. Many operating systems (including those with a relocating loader) load every page of a program into RAM before beginning to execute the program.

Anticipatory Paging

Technique that preloads a process's nonresident pages that are likely to be referenced in the near future. 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".

Precleaning

Unix operating systems periodically use sync to pre-clean all dirty pages. This makes starting a large new program run much faster, because it can be loaded into page frames that held clean pages that were dropped, rather than being loaded into page frames that were dirty and needed to be written back to disk before they were dropped.

Thrashing
 Thrashing is a phenomenon in a virtual memory system where an excessive amount of page swapping back and forth between main memory and secondary storage results in higher overhead and a little useful work.

An example of demand paging that results in a page swap each time the loop is executed and results in thrashing.

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

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.

6 comments: