Professional Documents
Culture Documents
Memory Management
3.1 No Memory Abstraction
3.2 Memory Abstraction
3.3 Virtual memory
3.4 Page Replacement Algorithms
3.5 Design Issues For Paging Systems
3.6 Implementation issues
3.7 Segmentation
1
Memory Management
• Ideally programmers want memory that is
– large
– fast
– non volatile
• Memory hierarchy
– small amount of fast, expensive memory – cache
– some medium-speed, medium price main memory
– gigabytes of slow, cheap disk storage
• Memory manager handles the memory hierarchy
2
3.1 Memory Abstraction
3
No Memory Abstraction
Monoprogramming without Swapping or Paging
5
3.2 Memory Abstraction
6
Memory Abstraction
Base and Limit Registers
Base and limit registers can be used to give each process a separate
address space. 7
Memory Abstraction
Dynamic relocation using a relocation register
8
Memory Abstraction
Relocation and Protection
• Cannot be sure where program will be loaded in
memory
– address locations of variables, code routines cannot be
absolute
– must keep a program out of other processes’ partitions
• Use base and limit values
– address locations added to base value to map to physical
addr
– address locations larger than limit value is an error
9
Memory Abstraction
Relocation and Protection
• Relocation registers used to protect user processes
from each other, and from changing operating-
system code and data
– Base register contains value of smallest
physical address
– Limit register contains range of logical
addresses – each logical address must be less
than the limit register
– MMU maps logical address dynamically
10
Memory Abstraction
HW address protection with base and limit registers
11
Memory Abstraction
Swapping (1)
Schematic View of Swapping
12
Memory Abstraction
Swapping (2)
13
Memory Abstraction
Swapping (3)
15
Memory Abstraction
Swapping (4)
Multiple-partition allocation
16
Memory Abstraction
Swapping (5)
Multiple-partition allocation
19
Virtual Memory
• Virtual memory – separation of user logical memory from
physical memory.
– Only part of the program needs to be in memory for
execution
– Logical address space can therefore be much larger than
physical address space
– Allows address spaces to be shared by several processes
– Allows for more efficient process creation
• Virtual memory can be implemented via:
– Demand paging
– Demand segmentation
20
Virtual Memory
Paging
21
Virtual Memory
Paging
23
Virtual Memory
Address Translation Scheme
• Address generated by CPU is divided into:
– Page number (p) – used as an index into a page table
which contains base address of each page in physical
memory
24
Virtual Memory
Paging Hardware
25
Virtual Memory
Paging: Example
26
Virtual Memory
Page Tables: Example
Top-level
page table
29
Virtual Memory
Implementation of Page Table
30
Virtual Memory
Paging Hardware With TLB
31
Virtual Memory
TLBs – Translation Lookaside Buffers
33
Virtual Memory
Steps in Handling a Page Fault
34
Virtual Memory
Page Replacement
• What happens if there is no free frame?
• Page replacement – find some page in
memory, but not really in use, swap it out
– algorithm
– performance – want an algorithm which will
result in minimum number of page faults
• Same page may be brought into memory
several times
35
Virtual Memory
Basic Page Replacement
1. Find the location of the desired page on disk
2. Find a free frame:
- If there is a free frame, use it
- If there is no free frame, use a page
replacement algorithm to select a victim frame
3. Bring the desired page into the (newly) free
frame; update the page and frame tables
4. Restart the process
36
Virtual Memory
Page Replacement
37
3.4 Page Replacement Algorithms
38
Page Replacement Algorithms
39
Page Replacement Algorithms
Optimal Page Replacement Algorithm
• Estimate by …
– logging page use on previous runs of process
– although this is impractical
40
Page Replacement Algorithms
Not Recently Used Page Replacement Algorithm
• Disadvantage
– page in memory the longest may be often used
42
Page Replacement Algorithms
Second Chance Page Replacement Algorithm
44
Page Replacement Algorithms
Least Recently Used (LRU)
The aging algorithm simulates LRU in software. Shown are six page
for five clock ticks. The five clock ticks are represented by (a) to (e).
47
Page Replacement Algorithms
Working Set Page Replacement (1)
. The working set is the set of pages used by the k most recent
memory references. The function w(k, t) is the size of the
working set at time t.
48
Page Replacement Algorithms
Working Set Page Replacement (2)
52
Page Replacement Algorithms
Summary
53
1.5 Design Issues For Paging System
54
Design Issues For Paging System
Local versus Global Allocation Policies (1)
60
Implementation Issues
Operating System Involvement with Paging
61
Implementation Issues
Page Fault Handling (1)
62
Implementation Issues
Page Fault Handling (2)
63
Implementation Issues
Locking Pages in Memory
64
Implementation Issues
Backing Store
67
Segmentation (1)
72
Segmentation with Paging: Pentium (2)
A Pentium selector
GDT (Global Descriptor Table), LDT (Local Descriptor Table)
73
Segmentation with Paging: Pentium (3)
74
Segmentation with Paging: Pentium (4)
78
Segmentation with Paging: Pentium (8)
Level