OPERATING SYSTEM BASICS
This book covers the core topics in operating system including process management ,memory and file systems.
3. MEMORY MANAGEMENT
3.2. VIRTUAL MEMORY
Virtual memory is a memory management technique that gives an application the illusion it has contiguous working memory while in reality, it may be fragmented or partially stored on disk. This allows the system to run larger applications than the physical memory would normally allow.
3.2.1 Paging and Page Replacement
Virtual memory is typically implemented using paging, where only part of the program is loaded into memory at any time. When the required page is not in memory, a page fault occurs, and the OS loads the needed page from the disk.
-
Page Replacement Algorithms determine which page to remove from memory when space is needed:
-
FIFO (First-In, First-Out): Removes the oldest page.
-
LRU (Least Recently Used): Removes the page that hasn’t been used for the longest time.
-
Optimal Algorithm: Replaces the page that will not be used for the longest future duration (theoretical).
-
3.2.2 Thrashing
Thrashing happens when the OS spends more time swapping pages in and out of memory than executing processes. This leads to a significant drop in performance. It usually occurs when too many processes are competing for limited memory.
Solutions to Thrashing:
-
Reduce the number of running processes.
-
Increase physical memory.
-
Use better page replacement algorithms.