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

Page Fault Handling in Operating System

Last Updated : 16 Aug, 2019
Improve
Suggest changes
Post a comment
Like Article
Like
Save
Share
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. So when page fault occurs then following sequence of events happens :

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

References –
cs.uttyler.edu
professormerwyn.wordpress.com



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
Difference between page and block in operating system
In this article, we will discuss the overview of the page and block in Operating System and then will discuss the differences by mentioning features of both. Let's discuss it one by one. Block Overview :Block is the smallest unit of data storage. It is used to read a file or write data to a file. Block is also a sequence of bits and bytes. Block is
5 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
Inverted Page Table in Operating System
Most Operating Systems implement a separate page table for each process, i.e. for the 'n' number of processes running on a Multiprocessing/ Timesharing Operating System, there is an 'n' number of page tables stored in the memory. Sometimes when a process is very large and it occupies virtual memory then with the size of the process, its page table
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 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
Segmentation Fault (SIGSEGV) vs Bus Error (SIGBUS)
Segmentation fault(SIGSEGV) and Bus error(SIGBUS) are signals generated when serious program error is detected by the operating system and there is no way the program could continue to execute because of these errors.1) Segmentation Fault (also known as SIGSEGV and is usually signal 11) occur when the program tries to write/read outside the memory
3 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
Article Tags :
Practice Tags :
three90RightbarBannerImg