Page fault

From Wikipedia, the free encyclopedia

In computer storage technology, a page fault is an interrupt (or exception) to the software raised by the hardware, when a program accesses a page that is not mapped in physical memory. The software that handles the page fault is generally part of an operating system and the hardware that detects this situation is the memory management unit in processors. Then an operating system can try to handle the page fault by making the required page accessible at a location in physical memory or kill the program in case it is an illegal access.

Contents

[edit] Reasons for page fault

Situations when a page fault can happen, when a program accesses a memory location in its memory and

  1. if the page corresponding to that memory is not loaded;
  2. if the program does not have privileges to access the page corresponding to that memory.
    1. The page access is legal, but it is mapped with demand paging.
    2. The page access is not legal like out of address range or null pointer access.

If the page is already in memory, the fault is called a soft page fault or minor fault. Operating systems may need to do in memory copy of the page or change the permissions of existing page or program the hardware with new access information to handle them. If the page must also be retrieved from disk, the fault is called a hard page fault or major fault. The major faults are more expensive and add latency to the interrupted program.

Page faults that are generated because of illegal access can result in program crash, segmentation error, bus error or core dump based on the semantics of operating system environment.

[edit] Page fault is not fatal error

Contrary to what its name might suggest, a page fault is not necessarily a fatal error. In any operating system that utilises virtual memory to increase the amount of memory available to programs, page faults are a common and necessary occurrence. The general protection fault, or the less common "invalid page fault," found on computers running a Microsoft Windows operating system, are actually generated by the exception handling code in the operating system's page fault handler. When a page fault occurs that would cause Windows to page in memory that the currently-running program does not have permissions to access, such as accessing memory that properly belongs to another process, the system will generate a "general protection fault." If a page fault occurs that references a non-existent memory page, such as trying to read a null pointer, the system may alternately generate an "invalid page fault." (Recent versions of Windows replace both these and other hardware-generated fault errors with a single, less technical error simply stating that "this program must close", but the underlying causes are the same). UNIX and UNIX-like operating systems will handle these conditions by delivering signals, such as SIGSEGV ("segmentation violation"), to the offending process. Frequently this is the manifestation of software bugs, but hardware memory errors (frequently caused by overclocking) may corrupt pointers causing even correct software to fail.

[edit] Performance

Page faults, by their very nature, degrade the performance of a program or operating system and in the degenerate case can cause thrashing. Optimizations to programs and the operating system that reduce the number of page faults that occur improves the program's or the entire system's performance. The two primary focuses of the optimization effort focus on reducing overall memory usage and improving memory locality. Generally, making more physical memory available also reduces page faults. Many page replacement algorithms have been proposed, implementing a heuristic to reduce the incidence of page faults.


[edit] See also

[edit] References

  • John L. Hennessy, David A. Patterson, Computer Architecture, A Quantitative Approach (ISBN 1-55860-724-2)
  • Tanenbaum, Andrew S. Operating Systems: Design and Implementation (Second Edition). New Jersey: Prentice-Hall 1997.

[edit] External links

In other languages