Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Aptitude
  • Engineering Mathematics
  • Discrete Mathematics
  • Operating System
  • DBMS
  • Computer Networks
  • Digital Logic and Design
  • C Programming
  • Data Structures
  • Algorithms
  • Theory of Computation
  • Compiler Design
  • Computer Org and Architecture
Open In App
Next Article:
Page Fault Handling in Operating System
Next article icon

Page Fault Handling in Operating System

Last Updated : 14 Jan, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

A page fault occurs when a program attempts to access data or code that is in its address space but is not currently located in the system RAM. This triggers a sequence of events where the operating system must manage the fault by loading the required data from secondary storage into RAM. Page faults are essential for implementing virtual memory systems that provide the illusion of a larger contiguous memory space.

What is Page Fault?

A page fault is a critical event in computer systems in which a program tries to attempt to access data or code that is not currently available in the physical memory (main memory). This occurrence is an integral part of virtual memory management which allows the system to physically fit large amounts of data efficiently in memory. So when a page fault occurs then the following sequence of events happens:


page-fault

Page Fault Handling Process

  • Trap to Kernel: The computer hardware traps to the kernel and program counter (PC) is saved on the stack. Current instruction state information is saved in CPU registers. The hardware detects the page fault when the CPU attempts to access a virtual page that is not currently in physical memory (RAM).
  • Save State Information: An assembly program is started to save the general registers and other volatile information to keep the OS from destroying it.
  • Determine Cause of Fault: Operating system finds that a page fault has occurred and tries to find out which virtual page is needed. Sometimes hardware register contains this required information. If not, the operating system must retrieve PC, fetch instruction and find out what it was doing when the fault occurred.
  • Validate Address: Once virtual address caused page fault is known, system checks to see if address is valid and checks if there is no protection access problem.
  • Allocate Page Frame: If the virtual address is valid, the system checks to see if a page frame is free. If no frames are free, the page replacement algorithm is run to remove a page.
  • Handle Dirty Pages: If frame selected is dirty, page is scheduled for transfer to disk, context switch takes place, fault process is suspended and another process is made to run until disk transfer is completed.
  • Load Page into Memory: As soon as page frame is clean, operating system looks up disk address where needed page is, schedules disk operation to bring it in.
  • Update Page Table: When disk interrupt indicates page has arrived, page tables are updated to reflect its position, and frame marked as being in normal state.
  • Restore State and Continue Execution: Faulting instruction is backed up to state it had when it began, and PC is reset. Faulting is scheduled, operating system returns to routine that called it. Assembly Routine reloads register and other state information, returns to user space to continue execution.

Causes of Page Faults

There are several reasons of causing Page faults:

  • Demand Paging: Accessing the page that is not currently loaded in the memory (RAM).
  • Invalid Memory Access, it occurs when a program tries to access that memory which is it's beyond access boundaries or not allocated.
  • Process Violation: when a process tries to write to a read-only page or otherwise violates memory protection rules.

Types of Page Fault

  • Minor Page Fault: Occurs when the required page is in memory but not in current process's page table.
  • Major Page Fault: Occurs when the page is not in memory and must be fetched from disk.
  • Invalid Page Fault: It happens when the process tries to access an invalid memory address.

Impact of Page Faults or System Performance

Page Fault impact the system if it occurs frequently

  • Thrashing: If occurrence of page fault is frequent then the system spends more time to handle it than executing the processes, and because of which overall performance also degrades.
  • Increased Latency: Fetching pages from disk takes more time than accessing them in memory, which causes to more delays.
  • CPU Utilization: If the Page fault occur excessively than it can reduce CPU Utilization as the processor waits for for memory operations to complete or remain idle which is not efficient.

Conclusion

In an operating system, page fault handling is an essential process that ensures smooth and efficient memory management. When a program tries to access data that isn't currently in the computer's physical memory (RAM), a page fault occurs. The operating system steps in to retrieve the necessary data from a slower storage (like a hard drive) and loads it into RAM. Although page faults can temporarily slow down a program, they are a normal part of how virtual memory works, allowing computers to run large applications efficiently without needing an excessive amount of physical memory. Effective page fault handling helps the system maintain performance and stability.


Next Article
Page Fault Handling in Operating System

S

swasthik
Improve
Article Tags :
  • Misc
  • Operating Systems
  • GATE CS
  • memory-management
Practice Tags :
  • Misc

Similar Reads

    Page Buffering Algorithm in Operating System
    The Page Buffering Algorithm is used in Operating systems and Database Management Systems as a key method to streamline data access and minimize disc I/O operations. It is largely used in virtual memory systems, where data is kept on secondary storage (disc) and brought into main memory as needed.Th
    7 min read
    Operating System Error Handling
    An operating system is considered a medium between the computer systems and its users. After the booting process, the Operating System takes over and manages all of its applications on a device. The operating system is a key part of the framework software application in an electronic device. Since t
    7 min read
    Hashed Page Tables in Operating System
    There are several common techniques for structuring page tables like Hierarchical Paging, Hashed Page Tables, and Inverted Page Tables. In this article, we will discuss the Hashed Page Table. Hashed Page Tables are a type of data structure used by operating systems to efficiently manage memory mappi
    4 min read
    Paging in Operating System
    Paging is the process of moving parts of a program, called pages, from secondary storage (like a hard drive) into the main memory (RAM). The main idea behind paging is to break a program into smaller fixed-size blocks called pages.To keep track of where each page is stored in memory, the operating s
    8 min read
    What is Demand Paging in Operating System?
    Demand paging is a memory management scheme used in operating systems to improve memory usage and system performance. Let's understand demand paging with real life example Imagine you are reading a very thick book, but you don’t want to carry the entire book around because it’s too heavy. Instead, y
    10 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences