Docsity

Virtual Memory Lecture Notes: Understanding Memory Management in Operating Systems - Prof., Study notes of Operating Systems

Partial preview of the text

Download Virtual Memory Lecture Notes: Understanding Memory Management in Operating Systems - Prof. and more Study notes Operating Systems in PDF only on Docsity!

CSCI 3753

Operating Systems

Virtual Memory Lecture Notes By Shivakant Mishra

Computer Science, CU-Boulder

Last Update: 04/06/

-^

Total memory requirements of all processes in amultiprogramming system often exceeds the totalmemory available in the system^ – Use swapping

-^

Only a small part of a process needs to be inmemory at any point time^ – No need to store an entire process in memory

  • Virtual memory

Virtual Memory Organization

Memory Image for p

i

Secondary Memory

Primary Memory

Names, Virtual Addresses &

Physical Addresses

SourceProgram

AbsoluteModule

Name SpaceName Space

P^ ’s VirtualP^ ’s Virtualii Address SpaceAddress Space

ExecutableImage Physical Address Space Physical Address Space

B: Virtual Address Spacet

Physical Address Space

Virtual Memory

Virtual Address Space for p

i

Virtual Address Space for p

j

Virtual Address Space for p

k

Secondary Memory

  • Complete virtual address space is stored insecondary memory

(^0) n-1 Primary Memory

Physical Address Space

-^ Fragments of the virtual address space are dynamically loaded into primary memory

at any

-^ Each address space is fragmented given time

Address Formation

-^

An executable code (load module) is written in avirtual address space: 0 – (

-^

Only some parts of a load module are loaded inmemory at any time.

-^

A virtual address, x:^ – Is mapped to physical address y =

Bt

(x) if x is loaded at

physical address y – Is mapped to

Ω^

if x is not loaded

-^

The map,

B

, changes as the process executes -- itt

is “time varying”

-^

B: Virtual Addresst

Physical Address

Paging

-^

Virtual address space is divided into units of samesize called pages.

-^

Memory is divided into units of same size calledpage frames.

-^

Virtual address space can be much larger than thephysical address space.

-^

Some pages from virtual address space are loadedonto page frames in physical address space.

-^

Page table maintains current mapping betweenpages and page frames

Example

Physical Address Space

Page Size = 4 KB

Virtual Address Space

X

X

X

X

X

X

X

X

Page Table

Address mapping

• Given a virtual address

  • Divide

x^

by page size

  • Quotient: page number • Remainder: offset
    • Use page table and page number to find pageframe number – Multiply page fame number by page size – Add offset

Page Size: Power of 2

  • Virtual address size (16 bit address): 2

16 B =

64 KB

  • Page Size: 2

12 B = 4 KB

  • Number of pages = 16 (4 bit page numbers)

8220 = 001000000001110024604 = 1100000000011100

Leftmost 4 bits in virtual address represent page number Replace those bits by page frame number

Demand Paging Algorithm

1.^

Page fault occurs

2.^

Process with missing page is interrupted

3.^

Memory manager locates the missing page

4.^

One page frame is unloaded (page replacementpolicy)

5.^

New page is loaded in the vacated page frame

6.^

Page table is updated

7.^

Process is restarted

Page Table Implementation

-^

Mapping virtual address to physical address isstraight forward.

-^

Problems:^ – Page tables can become extremely large

  • 32 bit address; 4K page size: 2^20 pages (more thana million) • Imagine 64-bit addresses.
    • Mapping must be extremely fast
      • Mapping is done for every memory reference. • One instruction: 1, 2, or more memory references • Want to do mapping in few (100-200) nanoseconds. -^

Need support from hardware

Translation Look-Aside Buffers

(TLBs)

  • Also known as associative registers • Special, small, fast-lookup cache • Each register consists of two parts
    • key and value
      • Given an input key, a fast, simultaneous

lookup is done, and corresponding valuefield is output.

-^

TLBs contain only a few of page table entries

-^

If a page number is found in the TLBs, memoryreference is only 10% longer than an unmappedmemory reference (~ 120 ns)

-^

If the page number is not found in the TLBs, amemory reference to the page table must be made^ – Hit ratio: Percentage of times a page number is found in

the TLBs^ • Motorola 68030: 22 entries TLB: 80% hit ratio^ • Intel 80486: 32 entries TLB: 98% hit ratio