How does virtual memory work? What is the purpose of swapping?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%
  • How does virtual memory work? What is the purpose of swapping?
Expert Solution
Step 1 INTRODUCTION

virtual memory is concept about  memory management technique in which secondary memory acts like a part of primary memory.As that amount of RAM is not enough to run all of the programs that most users expect to run at once. Virtual memory can be used to swap data that has not been used recently -- and move it over to a storage device like a hard drive or (SDD). This will free up more space on the RAM.Virtual memory  improves performance , multitasking, using large programs and flexibility.

The  main goal of virtual memory is to map virtual memory addresses generated by an executing program into physical addresses in computer memory.

Step 2

How does virtual memory work?

Lets say a process is running on RAM. If at any point  the RAM space is needed for something more data so unnecessary (not used for long time) can be swapped out of RAM and into virtual memory.computer's memory manager is in charge of keeping track of the shifts between physical and virtual memory. . The memory manager maintains a table which maps virtual addresses used by the operating system and applications to the physical addresses that data is actually stored in. When data is swapped between RAM and virtual memory, the table is updated so that a given virtual address always points to the correct physical location.If that data is needed again, a context switch can be used to resume execution again. While copying virtual memory into physical memory, the OS divides memory into pagefiles or swap files with a fixed number of addresses. Each page is stored on a disk, and when the page is needed, the OS copies it from the disk to main memory and translates the virtual addresses into real addresses.

Detail explanation---

When a virtual address needs to be translated into a physical address, the Memory management unit (MMU) first searches for it in the TLB cache. If a match is found (i.e., TLB hit) then the physical address is returned and the computation simply goes on. However, if there is no match for the virtual address in the TLB cache (i.e., TLB miss), the MMU searches for a match on the whole page table. If this match exists on the page table, this is accordingly written to the TLB cache . Thus, the address translation is restarted so that the MMU is able find a match on the updated TLB  but  Unfortunately, page table lookup may fail due to two reasons. The first one is when there is no valid translation for the specified virtual address (e.g., when the process tries to access an area of memory which it cannot ask for). Otherwise, it may happen if the requested page is not loaded in main memory at the moment . In both cases, the control passes from the MMU to the kernel. In the first case, the kernel raises a segmentation fault exception. In the second case, instead, a page fault occurs , which means the requested page has to be retrieved from the secondary storage (i.e., disk) where it is currently stored. Thus, the kernel accesses the disk, re-stores in main memory the page corresponding to the virtual address that originated the page fault, updates the page table and the TLB with a new mapping between the virtual address and the physical address where the page has been stored , and finally tells the MMU to start again the request so that a TLB hit will take place .

The figure below give  description of step during this process

Computer Science homework question answer, step 2, image 1

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Types of Database Architectures
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education