You are on page 1of 4

Memory Management Basics

Are We Done?

Implementing Paged Segmentation


Individual segments can be implemented as a paged, virtual address space
A segment address address is a pair ( s, va ) or a triple (s, (p, o))

Segmentation allows sharing but allocation/deallocation of arbitrary size segments is complex


Yields external fragmentation

s segment number p page number ( pmax pages) o page offset ( omax bytes/pages)

How can we improve memory management? Solution: Paged segmentation!


Partition segments into fixed-size pages Allocate and deallocate pages Contiguous pages in VAS need not be contiguous in PAS No external fragmentation, but internal fragmentation possible n 0

Virtual address = (s pmax +p) omax + o


18 19

Implementing Paged Segmentation


Combining segmentation and paging

Sharing in Paged-Segmented Systems


Sharing segments

Add one additional level of indirection to the page table CPU CPU Memory Memory

If segments are paged then page tables are automatically shared

Processes need only agree on a number for the shared segment

s
19 15

p
9

o
0

Virtual Addresses

Physical Addresses

f
11 9

o
0

shared seg heap seg code seg

(p,o) f=2 f=0 f=1

As Segment Table STBR STBR + + page table + + p Process Ps Segment Table Segment Ss Page Table f shared seg heap seg code seg

57

s
20

Shared Segment Page Table

jmp (p,o) Physical Memory


21

Bs Segment Table

Virtual Memory
Concept

Key problem: How can one support programs that require more memory than is physically available? Hide all physical aspects of memory from users

2n-1

Virtual Memory and Address Translation

Memory is a logically unbounded virtual address space of 2 n bytes Only portions of VAS are in physical memory at any one time

Issues
Placement strategies

Program Ps VAS

Where to place programs in physical memory What to do when there exist more processes than can fit in memory Determining how many processes can be in memory at one time

Replacement strategies

Load control strategies

0
2

Realizing Virtual Memory


Paging

Physical Address Specifications


Frame/Offset pair v. An absolute index (fMAX-1, oMAX-1)

Physical memory partitioned into equal sized page frames

Example: A 16-bit address space with ( omax =) 512 byte page frames
Addressing location (3, 6) = 1,542

(3,6)

1,542

(f,o) A memory address is a pair ( f, o )


f frame number ( fmax frames) o frame offset ( omax bytes/frames) Physical address = omaxf + o

o 3 Physical Memory 6 Physical Memory f

PA: 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1 0
16 10 9 1

f PA:
log 2 (fmax omax ) log 2 omax 1 (0,0) (0,0)
3

1,542

0
4

Realizing Virtual Memory


Paging 2n-1 = (pMAX-1, oMAX-1)

Paging

Mapping virtual addresses to physical addresses

A processs virtual address space is partitioned into equal sized pages


page = page frame

Pages map to frames


Pages are contiguous in a VAS...

(p,o)

A virtual address is a pair ( p, o)

o Virtual Address Space p

Virtual Address Space

But pages are arbitrarily located in physical memory, and Not all pages mapped at all times

(f1,o1)

p page number ( pmax pages) o page offset ( omax bytes/pages) Virtual address = omaxp + o

(p2,o2) (p1,o1)

Physical Memory
(f2,o2)

VA:
log 2 (pmax omax ) log 2 oMAX 1

(0,0)

Paging

Virtual address translation

Virtual Address Translation Details


Page table structure

Program Program P P CPU CPU Ps Virtual Address Space (p,o) p


20 10 9

A page table maps virtual pages to physical frames

(f,o)

1 table per process

Contents:

Part of processs state

Flags dirty bit, resident bit, clock/reference bit Frame number

CPU CPU f
1 16 10 9

o
1

p Physical Memory
20 10 9

o
1

f
16 10 9

o
1

Virtual Addresses

f p
Page Table

Physical Addresses

Virtual Addresses

PTBR PTBR

010

Physical Addresses

p
7

Page Table

Virtual Address Translation Details


Example

Virtual Address Translation


Performance Issues

A system with 16-bit addresses


32 KB of physical memory 1024 byte pages

(4,1023)

Problem VM reference requires 2 memory references!


One access to get the page table entry One access to get the data

(4,0) (3,1023)

CPU CPU Ps Virtual Address Space p


15 11 10

Physical Addresses

Page table can be very large; a part of the page table can be on disk!! Physical Memory

o
0 15

f
11 10

o
0

For a machine with 64-bit addresses and 1024 byte pages, what is the size of a page table?

Virtual Addresses 01000000 01000100

What to do?
Most computing problems are solved by some form of

Caching Indirection

Page Table

(0,0)
9 10