Download presentation
Presentation is loading. Please wait.
1
Paging
2
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
3
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)
4
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
5
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
6
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
7
Paging: Example Virtual Physical Virtual Process 1 Process 0
8
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
9
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
10
Page Tables Virtual Page Table
11
Page Table Structure Indexed by virtual page number
Contains frame number (if any) Contains protection bits Contains reference bit Frame No. v w r x f m Frame No. v w r x f m Frame No. v w r x f m v: valid bit w: write bit r: read bit x: execute bit (rare) f: reference bit m: modified bit
12
Mapping Virtual to Real Addresses
n bits Virtual address virtual page number offset s bits index into page table s bits frame no. offset p bits s: log (page size) Physical address
13
Example: PDP-11 Page size: 8K Up to 4M mem 16 bits Virtual address vpn
offset 13 bits 13 bits frame no. offset 8-entry page table 22 bits Physical address (in hardware)
14
Weird Stuff: Free Page Management
Virtual Physical Virtual Process 0 Process 1 Key fact: A memory frame cannot be accessed unless mapped Free space
15
Fun Stuff: Sharing Virtual Physical Virtual Process 1 Process 0
16
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)
17
Fork Revisited: Copy-on-Write
Virtual Physical Virtual W W W W W W Father Child
18
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
19
Copy-on-Write Virtual Physical Virtual W W W W W W Father Child
20
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)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.