ArticleslgStudy

computer science

Page fault

Page fault is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Page fault rather than just read about it. In short: In computing, a page fault is an exception that the memory management unit (MMU) raises when a process accesses a memory page without proper preparations. Accessing the page requires a mapping to be added to the process's virtual address space.

Key takeaways

  • Page fault belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Page fault to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Page fault from memory before moving on to harder problems.

Reference excerpt

In computing, a page fault is an exception that the memory management unit (MMU) raises when a process accesses a memory page without proper preparations. Accessing the page requires a mapping to be added to the process's virtual address space. Furthermore, the actual page contents may need to be loaded from a back-up, e.g. a disk. The MMU detects the page fault, but the operating system's kernel handles the exception by making the required page accessible in the physical memory or denying an illegal memory access. Valid page faults are common and necessary to increase the amount of memory available to programs in any operating system that uses virtual memory, such as Windows and macOS.

Types

Minor page fault If the page is loaded in memory at the time the fault is generated, but is not marked in the memory management unit as being loaded in memory, then it is called a minor, or soft, page fault. The page fault handler in the operating system merely needs to make the entry for that page in the memory management unit point to the page in memory and indicate that the page is loaded in memory; it does not need to read the page into memory. This could happen if the memory is shared by different programs and the page has already been brought into memory for another program.

Major page fault This is the mechanism used by an operating system to increase the amount of program memory available on demand. The operating system delays loading parts of the program from disk until the program attempts to use them, at which time page faults are generated. If the page is not loaded in memory at the time of the fault, then the fault is major, or hard. The page fault handler in the OS needs to load the page into working memory, and to do so it must choose a location: either a free page or, when free space is scarce, a page in use by another process. In the latter case the OS needs to write the data in that page out to mass storage (if it has not been written out since it was last modified) and mark that page as not being in memory in its process page table. Once the space has thus been made available, the OS reads the data for the new page into memory, adds an entry for its location in the memory management unit, and indicates that the page is loaded. Thus, major faults are more expensive than minor faults and add storage access latency to the interrupted program's execution.

Invalid page fault If a page fault occurs for a reference to an address that is not part of the virtual address space, meaning there cannot be a page in memory corresponding to it, then it is called an invalid page fault. The page fault handler in the operating system will then generally pass a segmentation fault to the offending process, indicating that the access was invalid; this usually results in abnormal termination of the code that made the invalid reference. A null pointer is usually represented as a pointer to address 0 in the address space; many operating systems set up the MMU to indicate that the page that contains that address is not in memory, and do not include that page in the virtual address space, so that attempts to read or write the memory referenced by a null pointer get an invalid page fault.

Invalid conditions Illegal accesses and invalid page faults can result in a segmentation fault or bus error, resulting in an app or OS crash. Software bugs are often the causes of these problems, but hardware memory errors, such as those caused by overclocking, may corrupt pointers and cause valid code to fail. Operating systems provide differing mechanisms for reporting page fault errors. Microsoft Windows uses structured exception handling to report invalid page faults as access violation exceptions. UNIX-like systems typically use signals, such as SIGSEGV, to report these error conditions to programs. If the program receiving the error does not handle it, the operating system performs a default action, typically involving the termination of the running process that caused the error condition, and notifying the user that the program has malfunctioned. Windows often reports such crashes without going to any details. An experienced user can retrieve detailed information using WinDbg and the minidump that Windows creates during the crash. UNIX-like operating systems report these conditions with such error messages as "segmentation violation" or "bus error", and may produce a core dump.

Performance impact Page faults degrade system performance and can cause thrashing. Major page faults on a conventional computer using hard disk drives can have a significant impact on performance, as a typical hard disk drive had an average rotational latency of 3 ms, a seek time of 5 ms and a transfer time of 0.05 ms/page. Therefore, the total time for paging is near 8 ms (8,000 μs). If the memory access time is 0.2 μs, then the page fault would make the operation take about 40,000 times as long. With a more modern system using a fast solid-state drive with a page read latency of 0.030 ms (30 μs) and a memory access latency of 70 ns (0.070 μs), a hard page fault is still takes over 400 times as long. Performance optimization of programs or operating systems often involves efforts to reduce the number of page faults, by reducing overall memory usage or by improving memory locality. To minimize page faults, OS developers use an appropriate page replacement algorithm that maximizes page hits. Many have been proposed, such as implementing heuristic algorithms to reduce the incidence of page faults. Having more physical memory also reduces the likelihood of page faults. Chunks of memory-mapped files can remain in memory longer and avoid slow re-reads from storage. Similarly, having more memory lessens the need for frequent swapping out of memory pages to a backing storage device.

See also Bélády's anomaly Memory hierarchy

References

Bibliography

External links "So What Is A Page Fault?"(subscription required) from OSR Online (a Windows-specific explanation) "Virtual Memory Details" from the Red Hat website. "UnhandledExceptionFilter (Windows)" from MSDN Online. "Page fault overhead" for information about how page faults can crucially affect processing time.

Worked examples

Example 1 — a first encounter with Page fault

Start with the simplest possible case. Write down what Page fault claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Page fault before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Page fault ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Page fault

In research
Page fault appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Page fault in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Page fault is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computer errors, Memory management, Virtual memory, so understanding it makes those chapters shorter.
In everyday life
Look for Page fault outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Page fault in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Page fault means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Page fault out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Page fault in simple terms?

In computing, a page fault is an exception that the memory management unit (MMU) raises when a process accesses a memory page without proper preparations. Accessing the page requires a mapping to be added to the process's virtual address space.

Why does Page fault matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Page fault?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Page fault.

Tags

  • Computer errors
  • Memory management
  • Virtual memory

Keep exploring