Docsity

Virtual Memory: Understanding Paging and Page Replacement Algorithms - Prof. M. Ali, Study notes of Operating Systems

Toggle sidebar
bg1



 

Virtual Memory - giving the illusion of more physical memory
than there really is (via demand paging)
Pure Paging - The total program is kept in memory as sets of
(non-contiguous) pages
No illusion of virtual memory
Demand Paging - A program’s “working set” is kept in
memory, reference outside WS causes corresponding code to
be retrieved from disk (“page fault”)
Provides the illusion of virtual memory
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18

Partial preview of the text

Download Virtual Memory: Understanding Paging and Page Replacement Algorithms - Prof. M. Ali and more Study notes Operating Systems in PDF only on Docsity!

 Virtual Memory - giving the illusion of more physical memory

than there really is (via demand paging)

 Pure Paging - The total program is kept in memory as sets of

(non-contiguous) pages

 No illusion of virtual memory

 Demand Paging - A program’s “working set” is kept in

memory, reference outside WS causes corresponding code to

be retrieved from disk (“page fault”)

 Provides the illusion of virtual memory

  

  

 Processes (programs) are

divided into fixed size pieces

called Pages

 Main memory is divided into

fixed size partitions called

Blocks ( Page Frames)

 Pure Paging - entire program is

kept in memory during

execution, but pages are not

kept in contiguous blocks

 Demand paging - only parts of

program kept in memory during

execution, pages are not kept in

contiguous blocks

 

 A virtual address is represented as

where the page is determined by dividing each process into fixed size pages, the offset is a number in the range 0 - (page_size-1).

 Memory is divided into fixed size blocks (or page frames ) and accommodates a process’ pages. The physical address (PA) then is (block_number * page_size + offset).

 In pure paging systems the entire VA space of a process must reside in physical memory during execution, but pages are not kept in contiguous blocks.

  

*+    

CPU

Compiled Address PA

Address Translator: Determines VA Maps VA to PA (Hardware + OS)

Memory

Assume 256 bytes per page: page number offset

8 bits

VA:

*+    

A[0]

A[1]

A[2]

A[3]

Page Frame

Page Map

Table:

A[3]….

…A[0..2]

VA space:

PA space:

Page Offset

Frame

VA:

PA:

  

 

    8 9 

Job 1

Job 2

Job 3

PMT's

0 1 2 3 4 5 6

OS

J1 P

J2 P

J1 P

J3 P

J1 P

J2 P

MBT

Page Block

7 J3^ P

8 J3^ P

  

  

Maps each block of main memory either to a process id and page number or to "free"

Memory Block Table (MBT)

1 MBT / System 1 Entry / Block

  

Process (Job) Control Block (PCB)

Contains information about all jobs in the system

Stores: Job Size Location of PMT

1 PCB / system 1 entry / job

  

   :; ) 8 :

Main Memory

PMT

block #s

VA = < page, offset >

PA = block size * block + offset

Assume:

1 word PMT entries;

byte addressable MM

Example:

page & block size = 4 K bytes

VA = < 1, 1234 >

PA = 4096 * 16 + 1234

1   <  6="">

" 

 3 !5& ??@

 #& *3? 5  0

&  21!3  6    # =""2= 1 3  6    #

  

    ") 1-A 

C"  

 Advantages:

 Efficient memory usage

 Simple partition management due to discontiguous

loading and fixed partition size

 No compaction necessary

 Easy to share pages

  

C"  

 Disadvantages:

 Job Size <= Memory Size

 Internal fragmentation (half the page size on the average)

 Need special hardware for address translation

 Some main memory space used for PMT's

 Address translation lengthens memory cycle times

1   

Jobs are paged, but not all pages have to be in memory at the same time VIRTUAL MEMORY  The operating system creates the illusion of more memory  Job size can exceed main memory size

 Pages are only brought in when referenced (on demand )  Often page 0 is loaded initially when a job is scheduled

  

D  '=

  0!    E " 0 4 4  F ; .4 4  A    FA ; .  F-.4 4

.  AG0 "  A   

1    

  0E &   -E +   C

   0E   & H0C  /0 )"0   0 

 G0;  

."1E

'.CG 0

C 

  

1     

   ( I @

   ( I @

 H

H

1    1

OS

J1 P

J2 P

J1 P

J3 P

J1 P

J2 P

MBT

1. What happens if job 3 references page 1?

Referenced Changed

Job 1

Job 2

Job 3

Page Block In_Mem Disk Yes^ Dsk Addr Dsk Addr Dsk Addr Dsk Addr Dsk Addr

Dsk Addr Dsk Addr Dsk Addr

Yes Yes Yes Yes

Yes No No

  

  ;8 9   "

Question: Does a program need all its pages in main memory at all times?

.  ":

At any time, the locality of a process is the set of pages that are

actively being used together

Spatial There is a high probability that once a location is

referenced, the one after it will be accessed in the

near future

Sequential code, Array processing, Code within a loop

Temporal A referenced location is likely to be accessed again

in the near future

Loop indices, Single data elements

  

:

Does a recursive function display spatial

or temporal locality?

Does a linked list help or hurt locality?

DE . 3 '#J:J 5

 A process’ working set is the number of pages currently

being referenced during ( t , t+∆ ) for some small ∆.

 The working set size is an estimate of degree of locality

 A job should not be scheduled unless there is room for its entire working set

 Why?

  

 ) &  

 Replace the page which will not be used for the longest period of

time

 Lowest page fault rate of all algorithms

 Requires knowledge of the future

Example:

MM has 3 blocks containing 3,5,2.

Current and future refs:

fault (^) OPT replaces 5

= ) 

Page Trace: 0 1 2

Block Number

Page Faults =

Page Fault Rate =

  

) & 

 Replace the "oldest" page

 A frequently used page may be swapped out

Belady's Anomaly:

For some page replacement algorithms, the page fault rate may increase as the number of blocks increase

'+'=  )

Page Trace: 0 1 2

Block Number

0 1 2 3

Page Trace:

Block Number

Page Faults =

Page Faults =