0% found this document useful (0 votes)
3 views

L-12

The document discusses memory management issues, particularly fragmentation and the need for compaction in memory partitioning. It introduces the concept of virtual addresses and paging, explaining how a Memory Management Unit (MMU) can create the illusion of contiguous address space while allowing non-contiguous physical memory allocation. Key features include independent virtual address spaces, page tables, and mechanisms for sharing and managing memory efficiently through techniques like copy-on-write.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

L-12

The document discusses memory management issues, particularly fragmentation and the need for compaction in memory partitioning. It introduces the concept of virtual addresses and paging, explaining how a Memory Management Unit (MMU) can create the illusion of contiguous address space while allowing non-contiguous physical memory allocation. Key features include independent virtual address spaces, page tables, and mechanisms for sharing and managing memory efficiently through techniques like copy-on-write.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 20

Paging

Memory Partitioning Troubles

Fragmentation
Need for compaction/swapping
A process size is limited by the available
physical memory
Dynamic growth of partition is troublesome
No winning policy on allocation/deallocation

P2

P3
The Basic Problem

A process needs a contiguous partition(s)


But
Contiguity is difficult to manage

Contiguity mandates the use of physical memory addressing


(so far)
The Basic Solution

Give illusion of a contiguous address space


The actual allocation need not be contiguous
Use a Memory Management Unit (MMU) to translate from the
illusion to reality
A solution: Virtual Addresses

Use n-bit to represent virtual or logical addresses


A process perceives an address space extending from address
0 to 2n-1
MMU translates from virtual addresses to real ones
Processes no longer see real or physical addresses
Paged Memory

Subdivide the address space (both virtual and physical) to


“pages” of equal size
Use MMU to map from virtual pages to physical ones
Physical pages are called frames
Paging: Example
Virtual Physical Virtual
0 0

Process 1
Process 0
Key Facts

Virtual address spaces of different processes are independent


Two or more may have the same address range
Yet the mappings differentiate between them
A virtual page has no storage of its own
It must be backed by a physical frame (real page) that provides the
actual storage
A contiguous virtual space need not be physically contiguous
Key Facts

Physical address space is independent of virtual address


spaces
They can have different sizes
Allows process size to be independent of available physical memory
size
Page size is always a power of 2, to simplify hardware
addressing
Page Tables
Virtual
0

Page Table
Page Table Structure

Indexed by virtual page Frame No. v w r x f m


number
Contains frame number (if Frame No. v w r x f m
any)
Contains protection bits Frame No. v w r x f m
Contains reference bit v: valid bit
w: write bit
r: read bit
x: execute bit (rare)
f: reference bit
m: modified bit
Mapping Virtual to Real Addresses
n bits

virtual page number offset Virtual


address
s bits

index into
page table
s bits
frame no. offset
p bits
s: log (page size) Physical address
Example: PDP-11
Page size: 8K
16 bits Up to 4M mem

vpn offset Virtual


address
13 bits

13 bits
frame no. offset
8-entry 22 bits
page Physical address
table
(in hardware)
Weird Stuff: Free Page Management
Virtual Physical Virtual

Process 0 Process 1

Key fact:
A memory frame
cannot be accessed
Free space unless mapped
Fun Stuff: Sharing
Virtual Physical Virtual
0 0

Process 1
Process 0
Sharing

Processes can share pages by mapping their virtual pages to


the same memory frame
In UNIX and Windows, code segments of processes running
the same program to share the pages containing executables
saves a lot of memory
saves loading time for frequently run programs
Fine tuning using protection bits (rwx)
Fork Revisited: Copy-on-Write
Virtual Physical Virtual
W W
W W
W W
Father Child
Copy-on-Write Fork

Initially no memory copying


Efficient
If an exec follows, no much harm
Page tables set the protection to disallow writes
If either father or child attempts to write, a page fault occurs
Copy-on-Write
Virtual Physical Virtual
W W
W W
W W
Father Child
Requirements for Sharing

Page frames must have a reference count


Cannot be deallocated unless unmapped
Adds complexity to memory manager
Protection bits must be set properly
Must externalize protection bits to user programs (mprotect())
Protection bits meaning could be overloaded (bad)

You might also like