Virtual Memory Concepts
Virtual Memory
When process runs, page containing data that currently accessing (working set) will be mapped to physical ram.
Virtual memory can be very important when you have multiple storage devices to manage(which is very common in today’s PC). It provides a abstract layer for memory management. Since we use virtual memory, we have to do address translation between virtual memory and physical memory. The corresponding responsible hardware in the CPU, often referred to as a memory management unit (MMU).
Pages:
Commonly, implementations of virtual memory divide a virtual address space into pages (blocks of contiguous virtual memory addresses).
Page Tables
Each entry in the page table holds a flag indicating whether the corresponding page is in real memory or not. If it is in real memory, the page table entry will contain the real memory address at which the page is stored. When a reference is made to a page by the hardware, if the page table entry for the page indicates that it is not currently in real memory, the hardware raises a page fault exception, invoking the paging supervisor component of the operating system.
Paging supervisor
This part of the operating system creates and manages page tables. If the hardware raises a page fault exception, the paging supervisor accesses secondary storage, returns the page that has the virtual address that resulted in the page fault, updates the page tables to reflect the physical location of the virtual address and tells the translation mechanism to restart the request. It may utilize algorithm such as LRU when all physical memory is already in use.
Thrashing
It occurs when a computer’s virtual memory resources are overused, leading to a constant state of paging in/out and page faults, which causes the performance of the computer to degrade or collapse.
Demand Paging
This is a page strategy when copies a disk page into physical memory only if an attempt is made to access it and that page is not already in memory (page fault occurs).
Context Switch
Context switch occurs when switch between different processes(not threads !!!). This is expensive and with a lot of overheads. It requires switching of different page tables for different processes. TLB information for a process is also lost (being flushed actually) when conducting context switch.
- 本文作者: Yu Wan
- 本文链接: https://cyanh1ll.github.io/2021/01/07/System concepts review/
- 版权声明: CYANH1LL