National University of Computer & Emerging Sciences: Introduction To Memory Management
National University of Computer & Emerging Sciences: Introduction To Memory Management
National University of
Computer & Emerging Sciences
Lecture 33
Introduction to Memory Management
Background
• Program must be brought (from disk) into memory and
placed within a process for it to be run
Main Memory
Disk
2
FAST, National University of Computer and Emerging Sciences, Islamabad
Lecture 33 - Introduction to Memory Management
Memory Manager
3
FAST, National University of Computer and Emerging Sciences, Islamabad
Lecture 33 - Introduction to Memory Management
Requirements: Relocation
200K
Partition 1
Operating 100K
System
0
6
FAST, National University of Computer and Emerging Sciences, Islamabad
Lecture 33 - Introduction to Memory Management
– Call 100k + 10
• If the program is loaded in 2nd partition, then 400K
7
FAST, National University of Computer and Emerging Sciences, Islamabad
Lecture 33 - Introduction to Memory Management
Requirements: Protection
10
FAST, National University of Computer and Emerging Sciences, Islamabad
Lecture 33 - Introduction to Memory Management
Relocation and Protection
Addition and comparison has to be performed on every address
Use a hardware module
Absolute
Physical Address
Interrupt 800K
Partition 4
700K
400K
Partition 2
Base Register Adder
200K
Partition 1
Memory Management Unit Operating 100K
(MMU) System
Relative
Logical Address
Address 0
11
FAST, National University of Computer and Emerging Sciences, Islamabad
Lecture 33 - Introduction to Memory Management
Memory Management/Organization
Uni-programming
• Run just one program at a time User
• Memory is shared between Program
– A User program
– Operating system
Operating
•The user types a command on the prompt
System
•The OS
Copies the program from the disk to memory
Executes the program
After execution, prompt is available again
•The new program is copied into RAM, overwriting the previous one 13
FAST, National University of Computer and Emerging Sciences, Islamabad
Lecture 33 - Introduction to Memory Management
Multi-programming systems
15
FAST, National University of Computer and Emerging Sciences, Islamabad
Lecture 33 - Introduction to Memory Management
Multiprogramming with Fixed Partitions
16
FAST, National University of Computer and Emerging Sciences, Islamabad
Lecture 33 - Introduction to Memory Management
17
FAST, National University of Computer and Emerging Sciences, Islamabad
Lecture 33 - Introduction to Memory Management
Internal Fragmentation
Memory that is internal to a partition but not being used
800K
B 4
Partition
Internal Fragmentation 700K
A
Partition 3
Internal Fragmentation
400K
Partition 2
200K
Partition 1
Operating 100K
System 0
18
Swapping
• If not enough space in memory for all the currently active
processes
• Excess processes must be kept on disk
– Fully Swapping
– Partially Virtual Memory
• Example of Swapping
– Round Robin Scheduling
• When the quantum expires
– Swap out the currently running process
– Swap in another process to freed memory space
19
FAST, National University of Computer and Emerging Sciences, Islamabad
Lecture 33 - Introduction to Memory Management
Swapping
• Another Example:
– Priority based scheduling
• If a higher priority process arrives
– Swap out a lower priority process
– Swap in the higher priority process
• When the higher priority process exits
– Swap in the lower priority process
20
FAST, National University of Computer and Emerging Sciences, Islamabad
Lecture 33 - Introduction to Memory Management
Swapping
Compaction
• Compaction involves CPU overhead
• If addresses are not generated relative to the partition location:
– Then Compaction is not possible
• How much memory should be allocated for a process?
– If all the memory is allocated statically in a program
– Then, OS knows exactly the amount of memory to be allocated:
executable code + variables
• However, if memory is allocated dynamically (say using new)
23
FAST, National University of Computer and Emerging Sciences, Islamabad
Lecture 33 - Introduction to Memory Management
24
FAST, National University of Computer and Emerging Sciences, Islamabad
Lecture 33 - Introduction to Memory Management