Page fault occurs whena)When a requested page is in memoryb)When a req...
Page fault occurs when a requested page is mapped in virtual address space but not present in memory.
View all questions of this test
Page fault occurs whena)When a requested page is in memoryb)When a req...
Page fault occurs when a requested page is not in memory
Page fault is a type of exception that occurs when a program requests a page from memory that is not currently present. It happens when the memory management unit (MMU) tries to access a page that has been mapped into the virtual address space of a process but is not present in physical memory.
Explanation:
When a program is executed, it is loaded into the main memory (RAM) for execution. The operating system divides the program into fixed-size units called pages. These pages are then mapped into the virtual address space of the process. The virtual address space is a range of memory addresses that a process can use for its execution.
When a program tries to access a memory location, the MMU translates the virtual address into a physical address and checks if the corresponding page is present in physical memory. If the page is not present, a page fault occurs.
Causes of Page Fault:
- Demand Paging: In demand paging, pages are loaded into memory only when they are needed. If a requested page is not in memory, a page fault occurs.
- Page Replacement: When the physical memory becomes full and a new page needs to be brought in, the operating system selects a page to be replaced. If the page to be replaced is dirty (modified), it needs to be written back to the disk before bringing in the new page. This process also results in a page fault.
- Copy-on-Write: In copy-on-write mechanism, when a process forks, the parent and child processes share the same memory pages. If either process modifies a shared page, a copy of that page is created, and a page fault occurs.
Handling Page Fault:
When a page fault occurs, the operating system needs to handle it. The steps involved in handling a page fault are as follows:
1. The operating system receives a page fault interrupt.
2. It checks the page table to find the location of the requested page.
3. If the page is not in memory, it triggers a page replacement algorithm to make space for the new page.
4. The required page is then loaded from the disk into the free frame in memory.
5. The page table is updated to reflect the new mapping.
6. Finally, the program is restarted from the instruction that caused the page fault.
In summary, a page fault occurs when a requested page is not in memory. It is a mechanism used by the operating system to handle memory management efficiently and provide virtual memory to processes.