Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56
OPERATING SYSTEM
Mr. Anand H. D.
1
Department of Electronics & Communication Engineering
Dr. Ambedkar Institute of Technology
Bengaluru-56
Operating System: VIRTUAL MEMORY
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 2
Operating System: VIRTUAL MEMORY
Virtual memory Basics Demand paging
Page replacement policies
Topics to be covered:
 Virtual memory Basics
 Demand paging
 Page replacement policies
Virtual memory Basics Demand paging
Page replacement policies
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 3
Virtual memory Basics
 Users always want more from a computer system—more resources and more services. The need
for more resources is satisfied either by obtaining more efficient use of existing resources, or by
creating an illusion that more resources exist in the system.
 A virtual memory is what its name indicates—it is an illusion of a memory that is larger than
the real memory, i.e., RAM, of the computer system. A user or his application program sees
only the virtual memory.
 The kernel implements the illusion through a combination of hardware and software means.
We refer to real memory simply as memory. We refer to the software component of virtual
memory as a virtual memory manager.
 The illusion of memory larger than the system’s memory crops up any time a process whose
size exceeds the size of memory is initiated. The process is able to operate because it is kept in
its entirety on a disk and only its required portions are loaded in memory at any time.
 The basis of virtual memory is the noncontiguous memory allocation model described earlier in.
The address space of each process is assumed to consist of portions called components. The
portions can be loaded into nonadjacent areas of memory.
Operating System: VIRTUAL MEMORY
Virtual memory Basics Demand paging
Page replacement policies
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 4
Virtual memory Basics
 The address of each operand or instruction in the code of a process is a logical address of the
form (compi, bytei).
 The memory management unit (MMU) translates it into the address in memory where the
operand or instruction actually resides. Use of the noncontiguous memory allocation model
reduces memory fragmentation, since a free area of memory can be reused even if it is not large
enough to hold the entire address space of a process. More user processes can be
accommodated in memory this way, which benefits both users and the OS.
Operating System: VIRTUAL MEMORY
 The kernel carries this idea further—even
processes that can fit in memory are not
loaded fully into memory. This strategy
reduces the amount of memory that is
allocated to each process, thus further
increasing the number of processes that can
be in operation at the same time.
Figure shows a schematic diagram of a virtual
memory.
Virtual memory Basics Demand paging
Page replacement policies
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 5
Virtual memory Basics
 The logical address space of the process shown consists of five components. Three of these
components are presently in memory. Information about the memory areas where these
components exist is maintained in a data structure of the virtual memory manager. This
information is used by the MMU during address translation. When an instruction in the
process refers to a data item or instruction that is not in memory, the component containing it
is loaded from the disk. Occasionally, the virtual memory manager removes some components
from memory to make room for other components.
 The arrangement shown in Figure is a memory hierarchy as discussed earlier. The hierarchy
consists of the system’s memory and a disk. Memory is fast, but small in size. The disk is slow,
but has a much larger capacity.
 The MMU and the virtual memory manager together manage the memory hierarchy, so that the
current instruction in a process finds its operands in memory. We are now ready to define
virtual memory.
 Virtual Memory: A memory hierarchy, consisting of a computer system’s memory and a disk,
that enables a process to operate with only some portions of its address space in memory.
Operating System: VIRTUAL MEMORY
Virtual memory Basics Demand paging
Page replacement policies
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 6
Virtual memory Basics
 Demand Loading of Process Components The virtual memory manager loads only one
component of a process address space in memory to begin with—the component that contains
the start address of the process, that is, address of the instruction with which its execution
begins. It loads other components of the process only when they are needed. This technique is
called demand loading.
To keep the memory commitment to a process low, the virtual memory manager removes
components of the process from memory from time to time. These components would be loaded
back in memory when needed again.
Performance of a process in virtual memory depends on the rate at which its
components have to be loaded into memory. The virtual memory manager exploits the law of
locality of reference to achieve a low rate of loading of process components.
Operating System: VIRTUAL MEMORY
Virtual memory Basics Demand paging
Page replacement policies
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 7
Virtual memory Basics
 Paging and Segmentation: Implementation
of virtual memory differ in the manner in
which the boundaries and sizes of address
space components are determined. Table
compares the two approaches. In paging,
each component of an address space is
called a page. All pages have identical size,
which is a power of two. Page size is defined
by the computer hardware and demarcation
of pages in the address space of a process is
performed implicitly by it. In segmentation,
each component of an address space is
called a segment. A programmer declares
some significant logical entities (e.g., data
structures or objects) in a process as
segments.
Operating System: VIRTUAL MEMORY
Virtual memory Basics Demand paging
Page replacement policies
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 8
Virtual memory Basics
 Thus identification of components is performed by the programmer, and segments can have
different sizes. This fundamental difference leads to different implications for efficient use of
memory and for sharing of programs or data. Some systems use a hybrid segmentation-with-
paging approach to obtain advantages of both the approaches.
 In paging, each component of an address space is called a page. All pages have identical size,
which is a power of two. Page size is defined by the computer hardware and demarcation of
pages in the address space of a process is performed implicitly by it. In segmentation, each
component of an address space is called a segment.
 A programmer declares some significant logical entities (e.g., data structures or objects) in a
process as segments. Thus identification of components is performed by the programmer, and
segments can have different sizes. This fundamental difference leads to different implications
for efficient use of memory and for sharing of programs or data. Some systems use a hybrid
segmentation-with-paging approach to obtain advantages of both the approaches.
Operating System: VIRTUAL MEMORY
Virtual memory Basics Demand paging
Page replacement policies
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 9
Virtual memory Basics Demand paging
A process is considered to consist of pages, numbered from 0 onward. Each page is of
size s bytes, where s is a power of 2. The memory of the computer system is considered
to consist of page frames, where a page frame is a memory area that has the same size
as a page.
Page frames are numbered from 0 to #frames-1 where #frames is the number of page
frames of memory. Accordingly, the physical address space consists of addresses from 0
to #frames × s - 1.
At any moment, a page frame may be free, or it may contain a page of some process.
Each logical address used in a process is considered to be a pair (pi, bi), where pi is a
page number and bi is the byte number in pi, 0 ≤ bi < s. The effective memory address of
a logical address (pi, bi) is computed as follows:
Effective memory address of logical address (pi, bi) = start address of the page frame
containing page pi + bi
The size of a page is a power of 2, and so calculation of the effective address is
performed through bit concatenation, which is much faster than addition
Operating System: VIRTUAL MEMORY
Virtual memory Basics Demand paging
Page replacement policies
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 10
Virtual memory Basics Demand paging
Figure is a schematic diagram of a virtual memory
using paging in which page size is assumed to be
1 KB, where 1 KB = 1024 bytes. Three processes
P1, P2 and P3, have some of their pages in
memory.
The memory contains 8 page frames numbered
from 0 to 7. Memory allocation information for a
process is stored in a page table. Each entry in the
page table contains memory allocation information
for one page of a process. It contains the page
frame number where a page resides.
Operating System: VIRTUAL MEMORY
Process P2 has its pages 1 and 2 in memory. They occupy page frames 5 and 7 respectively. Process P1 has its
pages 0 and 2 in page frames 4 and 1, while process P3 has its pages 1, 3 and 4 in page frames 0, 2 and 3,
respectively. The free frames list contains a list of free page frames. Currently only page frame 6 is free.
Process P2 is currently executing the instruction ‘Add ·· 2528’, so the MMU uses P2’s page table for address
translation. The MMU views the operand address 2528 as the pair (2, 480) because 2528 = 2 × 1024 + 480. It
now accesses the entry for page 2 in P2’s page table. This entry contains frame number 7, so the MMU forms
the effective address 7 × 1024 + 480 according to Eq. (12.1), and uses it to make a memory access. In effect,
byte 480 in page frame 7 is accessed.
Virtual memory Basics Demand paging
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 11
 A page replacement policy should replace a page that is not likely to be referenced in the
immediate future. We evaluate the following three page replacement policies to see how well
they fulfill this requirement.
• Optimal page replacement policy
• First-in, first-out (FIFO) page replacement policy
• Least recently used (LRU) page replacement policy
Page replacement policies
Operating System: VIRTUAL MEMORY
Optimal Page Replacement: Optimal page replacement means making page replacement decisions
in such a manner that the total number of page faults during operation of a process is the minimum
possible; i.e., no other sequence of page replacement decisions can lead to a smaller number of page
faults. To achieve optimal page replacement, at each page fault, the page replacement policy would
have to consider all alternative page replacement decisions, analyze their implications for future page
faults, and select the best alternative. Of course, such a policy is infeasible in reality: the virtual
memory manager does not have knowledge of the future behavior of a process. As an analytical tool,
however, this policy provides a useful comparison in hindsight for the performance of other page
replacement policies. Although optimal page replacement might seem to require excessive analysis,
Belady (1966) showed that it is equivalent to the following simple rule: At a page fault, replace the
page whose next reference is farthest in the page reference string.
Virtual memory Basics Demand paging
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 12
Page replacement policies
Operating System: VIRTUAL MEMORY
FIFO Page Replacement At every page fault, the FIFO page replacement policy replaces the
page that was loaded into memory earlier than any other page of the process. To facilitate
FIFO page replacement, the virtual memory manager records the time of loading of a page in
the ref info field of its page table entry. When a page fault occurs, this information is used to
determine pearliest, the page that was loaded earlier than any other page of the process.
This is the page that will be replaced with the page whose reference led to the page fault.
LRU Page Replacement: The LRU policy uses the law of locality of reference as the basis
for its replacement decisions. Its operation can be described as follows: At every page fault
the least recently used (LRU) page is replaced by the required page. The page table entry of a
page records the time when the page was last referenced. This information is initialized
when a page is loaded, and it is updated every time the page is referenced. When a page
fault occurs, this information is used to locate the page pLRU whose last reference is earlier
than that of every other page. This page is replaced with the page whose reference led to the
page fault.
Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 13
Reference
1. D.M.Dhamdhare, “Operating Systems”,
Second Edition, TMH, 2008
Operating System: VIRTUAL MEMORY
Virtual memory Basics Demand paging
Page replacement policies
14
Prof. Anand H. D.
M. Tech. (PhD.)
Assistant Professor,
Department of Electronics & Communication Engineering
Dr. Ambedkar Institute of Technology, Bengaluru-56
Email: anandhdece@dr-ait.org
Phone: 9844518832

More Related Content

PDF
Os overview
PDF
OS introduction
PDF
OS scheduling
PDF
Structure of Operating System
PDF
OS-Process Management
PDF
OS Memory Management
PDF
Typical Embedded System
PDF
OS file systems
Os overview
OS introduction
OS scheduling
Structure of Operating System
OS-Process Management
OS Memory Management
Typical Embedded System
OS file systems

What's hot (16)

PDF
Characteristics and Quality Attributes of Embedded System
PPTX
PDF
PI-Tool To Improve Performance of Application In Multi-core Architecture
PDF
COMPARATIVE ANALYSIS OF FCFS, SJN & RR JOB SCHEDULING ALGORITHMS
PDF
Operating system concepts ninth edition (2012), chapter 2 solution e1
PDF
RTOS for Embedded System Design
PDF
A Parallel Computing-a Paradigm to achieve High Performance
DOCX
Os files 2
PDF
A Runtime Evaluation Methodology and Framework for Autonomic Systems
PDF
VIEW OF MEMORY ALLOCATION AND MANAGEMENT IN COMPUTER SYSTEMS
DOCX
PDF
AN EFFICIENT HYBRID SCHEDULER USING DYNAMIC SLACK FOR REAL-TIME CRITICAL TASK...
PDF
CSI-503 - 6. Memory Management
PDF
VTU 5TH SEM CSE SOFTWARE ENGINEERING SOLVED PAPERS - JUN13 DEC13 JUN14 DEC14 ...
PDF
Os Question Bank
DOC
Software rejuvenation
Characteristics and Quality Attributes of Embedded System
PI-Tool To Improve Performance of Application In Multi-core Architecture
COMPARATIVE ANALYSIS OF FCFS, SJN & RR JOB SCHEDULING ALGORITHMS
Operating system concepts ninth edition (2012), chapter 2 solution e1
RTOS for Embedded System Design
A Parallel Computing-a Paradigm to achieve High Performance
Os files 2
A Runtime Evaluation Methodology and Framework for Autonomic Systems
VIEW OF MEMORY ALLOCATION AND MANAGEMENT IN COMPUTER SYSTEMS
AN EFFICIENT HYBRID SCHEDULER USING DYNAMIC SLACK FOR REAL-TIME CRITICAL TASK...
CSI-503 - 6. Memory Management
VTU 5TH SEM CSE SOFTWARE ENGINEERING SOLVED PAPERS - JUN13 DEC13 JUN14 DEC14 ...
Os Question Bank
Software rejuvenation
Ad

Similar to OS virtual memory (20)

PPTX
Operating system 36 virtual memory
PPT
Power Point Presentation on Virtual Memory.ppt
PPT
memory management and Virtual Memory.ppt
PPT
Cache replacement policies,cache miss,writingtechniques
PPTX
Computer architecture virtual memory
PDF
Virtual memory
PPT
Virtual Memory
PPTX
virtual memory
PPTX
coafinal1-copy-150430204758-conversion-gate01.pptx
PPTX
chapter 2 memory and process management
DOCX
virtual memory - Computer operating system
PDF
CSI-503 - 9. Virtual Memory
PPTX
Os Module 4_Virtual Memory Management.pptx
PPT
virtual memory.ppt
PPT
Chapter 09 - Virtual Memory.ppt
PPTX
Paging +Algorithem+Segmentation+memory management
PPTX
Virtual Memory Management
PPT
NOV11 virtual memory.ppt
PPTX
Abhaycavirtual memory and the pagehit.pptx
PPT
Virtual memory Chapter 9 simple and easy
Operating system 36 virtual memory
Power Point Presentation on Virtual Memory.ppt
memory management and Virtual Memory.ppt
Cache replacement policies,cache miss,writingtechniques
Computer architecture virtual memory
Virtual memory
Virtual Memory
virtual memory
coafinal1-copy-150430204758-conversion-gate01.pptx
chapter 2 memory and process management
virtual memory - Computer operating system
CSI-503 - 9. Virtual Memory
Os Module 4_Virtual Memory Management.pptx
virtual memory.ppt
Chapter 09 - Virtual Memory.ppt
Paging +Algorithem+Segmentation+memory management
Virtual Memory Management
NOV11 virtual memory.ppt
Abhaycavirtual memory and the pagehit.pptx
Virtual memory Chapter 9 simple and easy
Ad

More from anand hd (20)

PDF
RMV sensors
PDF
RMV robot programming
PDF
Robot applications
PDF
RMV Mechanics
PDF
Robot Machine Vision
PDF
RMV Artificial Intelligence
PPTX
Modules and ports in Verilog HDL
PDF
Basic concepts in Verilog HDL
PDF
Overview of digital design with Verilog HDL
PDF
Robotics Endeffectors
PDF
Fundamentals of Robotics and Machine Vision System
PDF
Robotics and Automation Introduction
PDF
Programmable Logic Devices
PDF
Logic synthesis using Verilog HDL
PDF
Case Study of Embedded Systems
PDF
Modeling examples
PDF
Verilog Tasks & Functions
PDF
Concepts of Behavioral modelling in Verilog HDL
PDF
ARM 32-bit Microcontroller Cortex-M3 introduction
PDF
Computational models
RMV sensors
RMV robot programming
Robot applications
RMV Mechanics
Robot Machine Vision
RMV Artificial Intelligence
Modules and ports in Verilog HDL
Basic concepts in Verilog HDL
Overview of digital design with Verilog HDL
Robotics Endeffectors
Fundamentals of Robotics and Machine Vision System
Robotics and Automation Introduction
Programmable Logic Devices
Logic synthesis using Verilog HDL
Case Study of Embedded Systems
Modeling examples
Verilog Tasks & Functions
Concepts of Behavioral modelling in Verilog HDL
ARM 32-bit Microcontroller Cortex-M3 introduction
Computational models

Recently uploaded (20)

PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PPTX
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
PPTX
Amdahl’s law is explained in the above power point presentations
PDF
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
PDF
Exploratory_Data_Analysis_Fundamentals.pdf
PPTX
tack Data Structure with Array and Linked List Implementation, Push and Pop O...
PPTX
ASME PCC-02 TRAINING -DESKTOP-NLE5HNP.pptx
PPTX
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
PPTX
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PDF
Design Guidelines and solutions for Plastics parts
PPTX
Management Information system : MIS-e-Business Systems.pptx
PDF
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
PDF
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
PDF
737-MAX_SRG.pdf student reference guides
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PDF
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
PPTX
communication and presentation skills 01
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
Amdahl’s law is explained in the above power point presentations
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
Exploratory_Data_Analysis_Fundamentals.pdf
tack Data Structure with Array and Linked List Implementation, Push and Pop O...
ASME PCC-02 TRAINING -DESKTOP-NLE5HNP.pptx
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
Fundamentals of safety and accident prevention -final (1).pptx
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
Design Guidelines and solutions for Plastics parts
Management Information system : MIS-e-Business Systems.pptx
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
737-MAX_SRG.pdf student reference guides
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
communication and presentation skills 01

OS virtual memory

  • 1. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 OPERATING SYSTEM Mr. Anand H. D. 1 Department of Electronics & Communication Engineering Dr. Ambedkar Institute of Technology Bengaluru-56 Operating System: VIRTUAL MEMORY
  • 2. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 2 Operating System: VIRTUAL MEMORY Virtual memory Basics Demand paging Page replacement policies Topics to be covered:  Virtual memory Basics  Demand paging  Page replacement policies
  • 3. Virtual memory Basics Demand paging Page replacement policies Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 3 Virtual memory Basics  Users always want more from a computer system—more resources and more services. The need for more resources is satisfied either by obtaining more efficient use of existing resources, or by creating an illusion that more resources exist in the system.  A virtual memory is what its name indicates—it is an illusion of a memory that is larger than the real memory, i.e., RAM, of the computer system. A user or his application program sees only the virtual memory.  The kernel implements the illusion through a combination of hardware and software means. We refer to real memory simply as memory. We refer to the software component of virtual memory as a virtual memory manager.  The illusion of memory larger than the system’s memory crops up any time a process whose size exceeds the size of memory is initiated. The process is able to operate because it is kept in its entirety on a disk and only its required portions are loaded in memory at any time.  The basis of virtual memory is the noncontiguous memory allocation model described earlier in. The address space of each process is assumed to consist of portions called components. The portions can be loaded into nonadjacent areas of memory. Operating System: VIRTUAL MEMORY
  • 4. Virtual memory Basics Demand paging Page replacement policies Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 4 Virtual memory Basics  The address of each operand or instruction in the code of a process is a logical address of the form (compi, bytei).  The memory management unit (MMU) translates it into the address in memory where the operand or instruction actually resides. Use of the noncontiguous memory allocation model reduces memory fragmentation, since a free area of memory can be reused even if it is not large enough to hold the entire address space of a process. More user processes can be accommodated in memory this way, which benefits both users and the OS. Operating System: VIRTUAL MEMORY  The kernel carries this idea further—even processes that can fit in memory are not loaded fully into memory. This strategy reduces the amount of memory that is allocated to each process, thus further increasing the number of processes that can be in operation at the same time. Figure shows a schematic diagram of a virtual memory.
  • 5. Virtual memory Basics Demand paging Page replacement policies Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 5 Virtual memory Basics  The logical address space of the process shown consists of five components. Three of these components are presently in memory. Information about the memory areas where these components exist is maintained in a data structure of the virtual memory manager. This information is used by the MMU during address translation. When an instruction in the process refers to a data item or instruction that is not in memory, the component containing it is loaded from the disk. Occasionally, the virtual memory manager removes some components from memory to make room for other components.  The arrangement shown in Figure is a memory hierarchy as discussed earlier. The hierarchy consists of the system’s memory and a disk. Memory is fast, but small in size. The disk is slow, but has a much larger capacity.  The MMU and the virtual memory manager together manage the memory hierarchy, so that the current instruction in a process finds its operands in memory. We are now ready to define virtual memory.  Virtual Memory: A memory hierarchy, consisting of a computer system’s memory and a disk, that enables a process to operate with only some portions of its address space in memory. Operating System: VIRTUAL MEMORY
  • 6. Virtual memory Basics Demand paging Page replacement policies Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 6 Virtual memory Basics  Demand Loading of Process Components The virtual memory manager loads only one component of a process address space in memory to begin with—the component that contains the start address of the process, that is, address of the instruction with which its execution begins. It loads other components of the process only when they are needed. This technique is called demand loading. To keep the memory commitment to a process low, the virtual memory manager removes components of the process from memory from time to time. These components would be loaded back in memory when needed again. Performance of a process in virtual memory depends on the rate at which its components have to be loaded into memory. The virtual memory manager exploits the law of locality of reference to achieve a low rate of loading of process components. Operating System: VIRTUAL MEMORY
  • 7. Virtual memory Basics Demand paging Page replacement policies Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 7 Virtual memory Basics  Paging and Segmentation: Implementation of virtual memory differ in the manner in which the boundaries and sizes of address space components are determined. Table compares the two approaches. In paging, each component of an address space is called a page. All pages have identical size, which is a power of two. Page size is defined by the computer hardware and demarcation of pages in the address space of a process is performed implicitly by it. In segmentation, each component of an address space is called a segment. A programmer declares some significant logical entities (e.g., data structures or objects) in a process as segments. Operating System: VIRTUAL MEMORY
  • 8. Virtual memory Basics Demand paging Page replacement policies Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 8 Virtual memory Basics  Thus identification of components is performed by the programmer, and segments can have different sizes. This fundamental difference leads to different implications for efficient use of memory and for sharing of programs or data. Some systems use a hybrid segmentation-with- paging approach to obtain advantages of both the approaches.  In paging, each component of an address space is called a page. All pages have identical size, which is a power of two. Page size is defined by the computer hardware and demarcation of pages in the address space of a process is performed implicitly by it. In segmentation, each component of an address space is called a segment.  A programmer declares some significant logical entities (e.g., data structures or objects) in a process as segments. Thus identification of components is performed by the programmer, and segments can have different sizes. This fundamental difference leads to different implications for efficient use of memory and for sharing of programs or data. Some systems use a hybrid segmentation-with-paging approach to obtain advantages of both the approaches. Operating System: VIRTUAL MEMORY
  • 9. Virtual memory Basics Demand paging Page replacement policies Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 9 Virtual memory Basics Demand paging A process is considered to consist of pages, numbered from 0 onward. Each page is of size s bytes, where s is a power of 2. The memory of the computer system is considered to consist of page frames, where a page frame is a memory area that has the same size as a page. Page frames are numbered from 0 to #frames-1 where #frames is the number of page frames of memory. Accordingly, the physical address space consists of addresses from 0 to #frames × s - 1. At any moment, a page frame may be free, or it may contain a page of some process. Each logical address used in a process is considered to be a pair (pi, bi), where pi is a page number and bi is the byte number in pi, 0 ≤ bi < s. The effective memory address of a logical address (pi, bi) is computed as follows: Effective memory address of logical address (pi, bi) = start address of the page frame containing page pi + bi The size of a page is a power of 2, and so calculation of the effective address is performed through bit concatenation, which is much faster than addition Operating System: VIRTUAL MEMORY
  • 10. Virtual memory Basics Demand paging Page replacement policies Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 10 Virtual memory Basics Demand paging Figure is a schematic diagram of a virtual memory using paging in which page size is assumed to be 1 KB, where 1 KB = 1024 bytes. Three processes P1, P2 and P3, have some of their pages in memory. The memory contains 8 page frames numbered from 0 to 7. Memory allocation information for a process is stored in a page table. Each entry in the page table contains memory allocation information for one page of a process. It contains the page frame number where a page resides. Operating System: VIRTUAL MEMORY Process P2 has its pages 1 and 2 in memory. They occupy page frames 5 and 7 respectively. Process P1 has its pages 0 and 2 in page frames 4 and 1, while process P3 has its pages 1, 3 and 4 in page frames 0, 2 and 3, respectively. The free frames list contains a list of free page frames. Currently only page frame 6 is free. Process P2 is currently executing the instruction ‘Add ·· 2528’, so the MMU uses P2’s page table for address translation. The MMU views the operand address 2528 as the pair (2, 480) because 2528 = 2 × 1024 + 480. It now accesses the entry for page 2 in P2’s page table. This entry contains frame number 7, so the MMU forms the effective address 7 × 1024 + 480 according to Eq. (12.1), and uses it to make a memory access. In effect, byte 480 in page frame 7 is accessed.
  • 11. Virtual memory Basics Demand paging Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 11  A page replacement policy should replace a page that is not likely to be referenced in the immediate future. We evaluate the following three page replacement policies to see how well they fulfill this requirement. • Optimal page replacement policy • First-in, first-out (FIFO) page replacement policy • Least recently used (LRU) page replacement policy Page replacement policies Operating System: VIRTUAL MEMORY Optimal Page Replacement: Optimal page replacement means making page replacement decisions in such a manner that the total number of page faults during operation of a process is the minimum possible; i.e., no other sequence of page replacement decisions can lead to a smaller number of page faults. To achieve optimal page replacement, at each page fault, the page replacement policy would have to consider all alternative page replacement decisions, analyze their implications for future page faults, and select the best alternative. Of course, such a policy is infeasible in reality: the virtual memory manager does not have knowledge of the future behavior of a process. As an analytical tool, however, this policy provides a useful comparison in hindsight for the performance of other page replacement policies. Although optimal page replacement might seem to require excessive analysis, Belady (1966) showed that it is equivalent to the following simple rule: At a page fault, replace the page whose next reference is farthest in the page reference string.
  • 12. Virtual memory Basics Demand paging Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 12 Page replacement policies Operating System: VIRTUAL MEMORY FIFO Page Replacement At every page fault, the FIFO page replacement policy replaces the page that was loaded into memory earlier than any other page of the process. To facilitate FIFO page replacement, the virtual memory manager records the time of loading of a page in the ref info field of its page table entry. When a page fault occurs, this information is used to determine pearliest, the page that was loaded earlier than any other page of the process. This is the page that will be replaced with the page whose reference led to the page fault. LRU Page Replacement: The LRU policy uses the law of locality of reference as the basis for its replacement decisions. Its operation can be described as follows: At every page fault the least recently used (LRU) page is replaced by the required page. The page table entry of a page records the time when the page was last referenced. This information is initialized when a page is loaded, and it is updated every time the page is referenced. When a page fault occurs, this information is used to locate the page pLRU whose last reference is earlier than that of every other page. This page is replaced with the page whose reference led to the page fault.
  • 13. Prepared by Prof. Anand H. D., Dept. of ECE, Dr. AIT, Bengaluru-56 13 Reference 1. D.M.Dhamdhare, “Operating Systems”, Second Edition, TMH, 2008 Operating System: VIRTUAL MEMORY Virtual memory Basics Demand paging Page replacement policies
  • 14. 14 Prof. Anand H. D. M. Tech. (PhD.) Assistant Professor, Department of Electronics & Communication Engineering Dr. Ambedkar Institute of Technology, Bengaluru-56 Email: [email protected] Phone: 9844518832