The Wayback Machine - https://web.archive.org/web/20241106071048/https://www.geeksforgeeks.org/page-fault-handling-in-operating-system/
Open In App

Page Fault Handling in Operating System

Last Updated : 03 Oct, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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 try to attempts 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

  • 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 .
  • An assembly program is started to save the general registers and other volatile information to keep the OS from destroying it.
  • Operating system finds that a page fault has occurred and tries to find out which virtual page is needed. Some times 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.
  • 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.
  • 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.
  • 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.
  • As soon as page frame is clean, operating system looks up disk address where needed page is, schedules disk operation to bring it in.
  • When disk interrupt indicates page has arrived, page tables are updated to reflect its position, and frame marked as being in normal state.
  • 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.

Page faults occur when a program accesses data that is not currently in memory, prompting the operating system to fetch the data from secondary storage. Understanding how page faults are handled is key to mastering memory management in operating systems. Since this topic frequently appears in exams, it’s important to approach it with both theoretical and practical knowledge. The GATE CS and IT – 2025 course offers detailed insights into page fault handling, with examples and case studies that illustrate how modern operating systems manage memory efficiently.

Causes of Page Faults

There are several reason 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.

Page Fault Handling Process

  • Page Fault Detection: Through a hardware interrupt the Operating system detects the page fault.
  • Address Validation: The OS checks for the page is present in the secondary storage or checks whether the memory is valid or not.
  • Page Replacement: If there is no space for the page that is not in the memory yet, then OS decides which page is removed or evicted from memory to make room for the new page.
  • Loading the Page: The required page is loaded from disk into memory.
  • Updating Page Tables: The OS updates the page table with the new mapping.
  • Restarting the Process: When there is any page fault occur then the process will restart.

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.

Frequently Asked Questions on Page Fault Handling – FAQs

What is the difference between a minor and a major page fault?

A minor page fault occurs when the page is already in memory but not in the current process’s page table, while a major page fault requires to fetch the page from the disk because it is not in memory.

How can the page fault be minimized?

By optimizing memory usage, which helps to maintain the sufficient physical memory available, and using efficient algorithms for page replacement.

Can Page faults be completely eliminated?

No, it can’t be possible but their frequency can be reduced through efficient memory management and optimization techniques.

What is thrashing, and how it is related to page faults?

When a system spends more time in handling of page faults than executing processes, often due to insufficient memory. Which causes severe performance degradation of system.



Similar Reads

Error Handling in Operating System
An operating system is defined as an interface between the computer system and its users. Once the operating system is loaded into the computer system through the boot program it is responsible for managing all the applications on the device. The operating system is a significant component of the system software in a computer system. As the operati
8 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 the operating system is a set of software some erro
7 min read
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. The Page Buffering Algorithm's primary goal is to r
7 min read
Difference Between LRU and FIFO Page Replacement Algorithms in Operating System
Page replacement algorithms are used in operating systems to manage memory effectively. Page replacement algorithms are essential in operating systems for efficient memory management. These algorithms select which memory pages should be changed when a new page is brought. Least Recently Used (LRU) and First-In-First-Out (FIFO) are two popular page
3 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 mappings between virtual and physical memory addresses.
4 min read
Counting Based Page Replacement Algorithm in Operating System
Counting Based Page Replacement Algorithm replaces the page based on count i.e. number of times the page is accessed in the past. If more than one page has the same count, then the page that occupied the frame first would be replaced. Page Replacement: Page Replacement is a technique of replacing a data block (frame) of Main Memory with the data bl
5 min read
Difference between page and block in operating system
In an operating system, a block is a variable-size storage that can either read a file or write data into a file. The page is a fixed-size memory unit that can be loaded into the processor from main memory. In this article, we will provide an overview of the page and block in the operating system and then discuss the differences by mentioning the f
7 min read
System Protection in Operating System
Introduction: System protection in an operating system refers to the mechanisms implemented by the operating system to ensure the security and integrity of the system. System protection involves various techniques to prevent unauthorized access, misuse, or modification of the operating system and its resources. There are several ways in which an op
3 min read
User View Vs Hardware View Vs System View of Operating System
User View of Operating System: The Operating System is an interface, hides the details which must be performed and present a virtual machine to the user that makes it easier to use. Operating System provides the following services to the user. Execution of a programAccess to I/O devicesControlled access to filesError detection (Hardware failures, a
1 min read
Xv6 Operating System -adding a new system call
Prerequisite - Xv6 Operating System -add a user program In last post we got to know how to add user program in Xv6 Operating System. Now here you will see how to add new system call in Xv6 Operating System. A dding new system call to xv6: A system call is way for programs to interact with operating system. A computer program makes system call when
6 min read
Traps and System Calls in Operating System (OS)
Traps and system calls are two mechanisms used by an operating system (OS) to perform privileged operations and interact with user-level programs. Here is an overview of each mechanism: Traps: A trap is an interrupt generated by the CPU when a user-level program attempts to execute a privileged instruction or encounters an error. When a trap occurs
3 min read
Fork System Call in Operating System
In many operating systems, the fork system call is an essential operation. The fork system call allows the creation of a new process. When a process calls the fork(), it duplicates itself, resulting in two processes running at the same time. The new process that is created is called a child process. It is a copy of the parent process. The fork syst
5 min read
System Programs in Operating System
System Programming can be defined as the act of building Systems Software using System Programming Languages. According to Computer Hierarchy, Hardware comes first then is Operating System, System Programs, and finally Application Programs. Program Development and Execution can be done conveniently in System Programs. Some of the System Programs ar
3 min read
File System Implementation in Operating System
A file is a collection of related information. The file system resides on secondary storage and provides efficient and convenient access to the disk by allowing data to be stored, located, and retrieved. File system implementation in an operating system refers to how the file system manages the storage and retrieval of data on a physical storage de
11 min read
Difference between System Software and Operating System
Software is like a set of instructions that tell a computer what to do. There are two main types application software and system software. Application software is extra programs you can add to your computer to do specific things, like write documents or play games. You don't need these to use your computer, but they help you do particular tasks. Sy
5 min read
Page Replacement Algorithms in Operating Systems
In an operating system that uses paging for memory management, a page replacement algorithm is needed to decide which page needs to be replaced when a new page comes in. Page replacement becomes necessary when a page fault occurs and no free page frames are in memory. However, another page fault would arise if the replaced page is referenced again.
8 min read
Page Table Entries in Page Table
A Page Table is a data structure used by the operating system to keep track of the mapping between virtual addresses used by a process and the corresponding physical addresses in the system's memory. A Page Table Entry (PTE) is an entry in the Page Table that stores information about a particular page of memory. Each PTE contains information such a
7 min read
Difference Between Page Table and Inverted Page Table
Paging is a concept for storage management in operating systems that retrieve processes from secondary storage and store them in main memory as pages. The main concept behind paging is to divide each process into pages. Frames will also be used to divide the main memory. One page of the process is to be saved in one of the memory frames. In various
5 min read
Banker's Algorithm in Operating System
Prerequisite - Resource Allocation Graph (RAG), Banker’s Algorithm, Program for Banker’s Algorithm Banker's Algorithm is a resource allocation and deadlock avoidance algorithm. This algorithm test for safety simulating the allocation for predetermined maximum possible amounts of all resources, then makes an “s-state” check to test for possible acti
15 min read
Swap Space in Operating System
A computer has a sufficient amount of physical memory but most of the time we need more so we swap some memory on disk. Swap space is a space on a hard disk that is a substitute for physical memory. It is used as virtual memory which contains process memory images. Whenever our computer runs short of physical memory it uses its virtual memory and s
6 min read
Allocation of frames in Operating System
An important aspect of operating systems, virtual memory is implemented using demand paging. Demand paging necessitates the development of a page-replacement algorithm and a frame allocation algorithm. Frame allocation algorithms are used if you have multiple processes; it helps decide how many frames to allocate to each process. There are various
3 min read
Thread Models in Operating System
A thread is a light weight process which is similar to a process where every process can have one or more threads. Each thread contains a Stack and a Thread Control Block. There are four basic thread models : 1. User Level Single Thread Model : Each process contains a single thread.Single process is itself a single thread.process table contains an
2 min read
The Tempo Operating System
Operating system : An Operating system is an interface between the computer user and computer hardware. An Operating system is a software which performs all the basic task like file handling, file management, memory management, handling input and output, controlling peripherals devices such as disk drive and printer, mouse...etc Tempo operating sys
5 min read
Boot Block in Operating System
Basically for a computer to start running to get an instance when it is powered up or rebooted it need to have an initial program to run. And this initial program which is known as bootstrap needs to be simple. It must initialize all aspects of the system, from CPU registers to device controllers and the contents of the main memory, and then starts
5 min read
Comparison on using Java for an Operating System instead of C
Java is a managed language which offers memory safety. In Java, pointers do not exist, so we cannot do pointer arithmetic on a function pointer. An application can invoke a method defined in a class through the class object. In Java, we cannot do unsafe typecast of an object to overwrite the method pointer with something else. An out of bound array
2 min read
Difference between Loading and Linking in Operating System
An operating system acts as an intermediary between the user of a computer and computer hardware. The purpose of an operating system is to provide an environment in which a user can execute programs conveniently and efficiently. Linking and Loading are utility programs that play an important role in the execution of a program. Linking intakes the o
4 min read
Stack Implementation in Operating System uses by Processor
A stack is an associate ordered a set of components, only one of that (last added) are often accessed at a time. The point of access is named the highest of the stack. The number of components within the stack, or length of the stack, is variable. Items could solely be side to or deleted from the highest of the stack. For this reason, a stack is ad
4 min read
Best-Fit Allocation in Operating System
INTRODUCTION: Best-Fit Allocation is a memory allocation technique used in operating systems to allocate memory to a process. In Best-Fit, the operating system searches through the list of free blocks of memory to find the block that is closest in size to the memory request from the process. Once a suitable block is found, the operating system spli
4 min read
Thread Control Block in Operating System
Very similar to Process Control Blocks (PCBs) which represents processes, Thread Control Blocks (TCBs) represents threads generated in the system. It contains information about the threads, such as it's ID and states. The components have been defined below: Thread ID: It is a unique identifier assigned by the Operating System to the thread when it
1 min read
Two State Process Model in Operating System
Pre-requisite: States of a Process in Operating Systems The process in an operating system passes from different states starting from its formation to its completion. A process consists of program data and its associated data and a process control block (PCB). A process may change its state because of the following events like I/O requests, interru
3 min read
Article Tags :
three90RightbarBannerImg