Operating Systems - Lesson 1 Notes
Introduction to Memory Management
Lesson Title: Introduction to Memory Management and the Role of the Memory
Management Unit (MMU)
Lesson Objectives:
By the end of this lesson, students should be able to:
Define memory management in an operating system.
Explain the role of the Memory Management Unit (MMU).
Distinguish between logical and physical addresses.
Appreciate the importance of memory management in modern computers.
Lesson Content and Notes:
1.1 What is Memory Management?
Memory management is a function of the operating system that handles the allocation and
deallocation of memory space to processes during execution. It ensures efficient utilization
of the computer's main memory (RAM). It prevents situations like memory wastage,
overlapping of processes, and ensures system stability.
1.2 Why is Memory Management Important?
Prevents processes from interfering with each other's memory space.
Ensures fair and efficient use of limited RAM.
Allows multitasking by handling memory allocation for multiple processes.
Supports system security through memory protection.
Facilitates the use of virtual memory, allowing systems to run large programs that
exceed physical RAM.
1.3 Memory Management Unit (MMU)
The MMU is a hardware component responsible for translating logical addresses generated
by a program into physical addresses in the computer's memory (RAM).
Functions of the MMU:
Translates logical addresses to physical addresses.
Implements memory protection mechanisms.
Controls access to memory to prevent unauthorized use.
Supports techniques like paging and segmentation.
1.4 Logical vs. Physical Addresses
Aspect Logical Address Physical Address
Generated By CPU during program Actual location in RAM
execution
Visibility Seen by the user/program Hidden from the user;
managed by MMU
Purpose Refers to abstract memory Refers to actual memory
locations cells in RAM
Translation Translated by MMU to Final address where data
physical addresses resides
Example:
- A program refers to memory location 0x0015 (Logical Address).
- The MMU maps this to Physical Address 0x7F15 in RAM.
1.5 Role of Operating System in Memory Management
Keeps track of memory usage.
Decides which process gets memory, how much, and when.
Handles memory allocation and deallocation.
Works closely with the MMU to enforce memory protection.
Summary of Key Points:
Memory management is essential for efficient system operation.
The MMU translates logical addresses to physical addresses.
Logical addresses are generated by programs, physical addresses correspond to actual
RAM locations.
OS and MMU work together to ensure safe and efficient memory use.
Short Quiz/Exercise:
1. Define memory management.
2. What is the role of the MMU?
3. Differentiate between logical and physical addresses.
4. Why is memory protection important?
Next Lesson: Memory Management Techniques: Contiguous Allocation and Fragmentation
Operating Systems - Lesson 2 Notes
Memory Management Techniques
Lesson Title: Memory Management Techniques - Contiguous Allocation and Fragmentation
Lesson Objectives:
By the end of this lesson, students should be able to:
Explain contiguous memory allocation.
Describe fixed and variable partitioning techniques.
Differentiate between internal and external fragmentation.
Understand the advantages and disadvantages of each technique.
Lesson Content and Notes:
2.1 Contiguous Memory Allocation
In contiguous memory allocation, each process is allocated a single continuous block of
memory space. This is one of the simplest memory management techniques used in early
operating systems.
2.2 Partitioning Techniques
There are two common types of memory partitioning:
a) Fixed Partitioning
Memory is divided into fixed-sized partitions at system boot time.
Each partition can hold exactly one process.
Simple to implement but can lead to wasted space if process size is smaller than
partition size.
b) Variable Partitioning
Memory is divided dynamically based on process size.
Processes are allocated exactly the amount of memory they need.
Reduces wasted space but can lead to fragmentation over time.
2.3 Fragmentation
Fragmentation refers to the inefficient use of memory, where free memory exists but cannot
be used effectively.
Types of Fragmentation:
**Internal Fragmentation:** Occurs when fixed-size memory partitions have unused
space within them.
**External Fragmentation:** Happens when enough total free memory exists, but it is
scattered in small blocks preventing process allocation.
Example of Fragmentation:
Assume a system with 4 fixed partitions of 1MB each.
- Process A (0.8MB) occupies one partition, leaving 0.2MB unused (internal fragmentation).
- In variable partitioning, small leftover memory chunks scattered across RAM lead to
external fragmentation.
Summary of Key Points:
Contiguous memory allocation assigns processes to continuous memory blocks.
Fixed partitioning is simple but can waste memory (internal fragmentation).
Variable partitioning is flexible but suffers from external fragmentation.
Fragmentation affects memory utilization and system performance.
Short Quiz/Exercise:
5. What is contiguous memory allocation?
6. Differentiate between fixed and variable partitioning.
7. Explain internal fragmentation with an example.
8. What causes external fragmentation?
Next Lesson: Paging Concept - Introduction to Paging and Page Tables
Operating Systems - Lesson 3 Notes
Paging Concept
Lesson Title: Paging Concept - Introduction to Paging and Page Tables
Lesson Objectives:
By the end of this lesson, students should be able to:
Define paging in memory management.
Explain how paging works.
Describe the structure and function of a page table.
State the advantages of using paging.
Lesson Content and Notes:
3.1 What is Paging?
Paging is a memory management technique that eliminates the problem of contiguous
memory allocation by dividing both the physical memory (RAM) and logical memory into
fixed-size blocks. Logical memory is divided into pages, and physical memory is divided into
frames.
3.2 How Paging Works
The program is divided into fixed-size pages.
The operating system maintains a page table for each process.
The MMU translates logical addresses to physical addresses using the page table.
Pages are loaded into available frames in physical memory, which may be scattered.
3.3 Structure of a Page Table
A page table is a data structure used by the operating system to map logical page numbers
to physical frame numbers.
Page Number Frame Number
0 5
1 3
2 9
3 2
3.4 Logical to Physical Address Translation
The logical address consists of two parts:
- **Page Number:** Identifies which page of the process is being accessed.
- **Offset:** The specific location within that page.
The MMU uses the page number to look up the corresponding frame number in the page
table, then adds the offset to determine the physical address.
3.5 Advantages of Paging
Eliminates external fragmentation.
Allows processes to occupy non-contiguous memory locations.
Efficient utilization of available memory.
Simplifies memory allocation for large processes.
Summary of Key Points:
Paging divides logical and physical memory into fixed-size blocks.
Page tables map pages to frames.
Logical addresses are translated to physical addresses using the page table.
Paging allows efficient, flexible memory management.
Short Quiz/Exercise:
9. What is paging in memory management?
10. Describe the role of the page table.
11. Explain how logical addresses are translated to physical addresses in a paging system.
12. State two advantages of using paging.
Next Lesson: Segmentation - Concept and Comparison with Paging
Operating Systems - Lesson 4 Notes
Lesson Title:
Segmentation - Concept and Comparison with Paging
Lesson Objectives:
By the end of this lesson, students should be able to:
✔ Define segmentation in memory management.
✔ Explain how segmentation works.
✔ Differentiate between segmentation and paging.
✔ Understand the advantages and disadvantages of segmentation.
Lesson Content and Notes:
4.1 What is Segmentation?
Segmentation is a memory management technique that divides the logical memory of a
process into variable-sized segments, based on logical divisions such as:
Functions
Arrays
Data structures
Each segment represents a logical unit of the program, making memory management
more reflective of how programs are structured.
4.2 How Segmentation Works
✔ A process is divided into multiple segments (e.g., Code Segment, Stack Segment, Data
Segment).
✔ Each segment has:
A Segment Number
A Length (Size)
✔ The Operating System maintains a Segment Table for each process.
✔ Logical addresses consist of two parts:
Segment Number: Identifies the specific segment.
Offset: The location within the segment.
✔ The MMU uses the segment table to translate the logical address into a
physical memory address.
4.3 Logical Address Structure in Segmentation
A logical address in segmentation is structured as:
mathematica
CopyEdit
Logical Address = (Segment Number, Offset)
The MMU translates this using the segment table to locate the corresponding physical
memory location.
4.4 Comparison: Segmentation vs Paging
Aspect Segmentation Paging
Division Basis Logical units (functions, arrays, Fixed-size blocks called pages
etc.)
Size of Division Variable-sized segments Fixed-size pages and frames
Fragmentation Type Suffers from External Eliminates external
Fragmentation fragmentation
Logical Matches programmer's view of Not directly visible to the
Representation memory programmer
4.5 Advantages of Segmentation
✔ Logical memory structure reflects how programmers design programs.
✔ Provides memory protection at the segment level.
✔ Allows code sharing between processes, enhancing efficiency.
4.6 Disadvantages of Segmentation
✔ Suffers from external fragmentation, leading to inefficient memory use.
✔ More complex memory management compared to paging.
✔ Finding space for variable-sized segments becomes increasingly difficult as processes
are created and terminated.
Summary of Key Points:
✔ Segmentation divides logical memory into variable-sized segments.
✔ Logical addresses consist of a segment number and an offset.
✔ Segmentation provides logical memory structure similar to programmer design.
✔ Unlike paging, segmentation suffers from external fragmentation.
Short Quiz/Exercise:
1. What is segmentation in memory management?
2. How does segmentation differ from paging?
3. List two advantages and two disadvantages of segmentation.
4. Explain the structure of a logical address in segmentation.
Next Lesson:
Virtual Memory - Concept, Paging with Virtual Memory, and Page Replacement
Algorithms.
Operating Systems - Lesson 5 Notes
Lesson Title:
Virtual Memory - Concept, Paging with Virtual Memory, and Page Replacement
Algorithms
Lesson Objectives:
By the end of this lesson, students should be able to:
✔ Define virtual memory.
✔ Explain how virtual memory works.
✔ Understand the role of paging in virtual memory.
✔ Describe common page replacement algorithms.
Lesson Content and Notes:
5.1 What is Virtual Memory?
Virtual memory is a memory management technique that allows a computer to
compensate for shortages of physical memory (RAM) by temporarily transferring data to
disk storage.
Key Points:
✔ Allows the system to run large programs or multiple programs simultaneously.
✔ Provides an illusion that each process has more memory than physically available.
✔ Achieved by using a portion of the hard disk as an extension of RAM, known as the
swap space or page file.
5.2 How Virtual Memory Works
✔ Programs are divided into pages.
✔ Only necessary pages are loaded into physical memory (RAM).
✔ When a page is needed but not in RAM, a page fault occurs.
✔ The operating system loads the required page from disk into RAM, possibly replacing
an existing page.
✔ This process is invisible to the user and programs.
5.3 Paging and Virtual Memory
Virtual memory is implemented using paging:
✔ Logical memory is divided into pages.
✔ Physical memory holds frames.
✔ The system keeps only active pages in RAM; others reside on the hard disk.
✔ When needed, pages are swapped between RAM and disk.
5.4 Page Replacement Algorithms
When RAM is full and a new page needs to be loaded, the system uses a Page
Replacement Algorithm to decide which page to remove.
Common Algorithms:
a) First-In, First-Out (FIFO)
✔ The oldest loaded page is replaced.
✔ Simple but may lead to poor performance in some cases.
b) Least Recently Used (LRU)
✔ The page that has not been used for the longest time is replaced.
✔ Assumes that recently used pages are more likely to be used again.
✔ More efficient but requires tracking page usage.
c) Optimal Page Replacement (Theoretical)
✔ Replaces the page that will not be used for the longest time in the future.
✔ Provides the best performance but is impractical because it requires future knowledge.
5.5 Advantages of Virtual Memory
✔ Allows execution of large programs.
✔ Supports multitasking efficiently.
✔ Reduces the need for large physical RAM.
✔ Provides isolation between processes, enhancing security.
5.6 Disadvantages of Virtual Memory
✔ Excessive page faults can slow down the system (thrashing).
✔ Relies on slower disk storage, reducing performance compared to RAM.
✔ Complex to implement and manage.
Summary of Key Points:
✔ Virtual memory uses disk space to extend available RAM.
✔ Paging enables virtual memory by swapping pages between RAM and disk.
✔ Page replacement algorithms decide which page to evict when memory is full.
✔ Common algorithms include FIFO, LRU, and Optimal Replacement.
✔ Virtual memory enhances system flexibility but can introduce performance issues.
Short Quiz/Exercise:
1. What is virtual memory?
2. How does paging support virtual memory?
3. Name and explain two page replacement algorithms.
4. List two advantages and two disadvantages of virtual memory.
Next Lesson:
Memory Protection and Allocation - Mechanisms to Prevent Unauthorized Access and
How OS Allocates Memory to Processes.
Operating Systems - Lesson 6 Notes
Lesson Title:
Memory Protection and Allocation
Lesson Objectives:
By the end of this lesson, students should be able to:
✔ Explain the concept of memory protection.
✔ Understand why memory protection is important.
✔ Describe mechanisms used for memory protection.
✔ Explain how the operating system allocates memory to processes.
Lesson Content and Notes:
6.1 What is Memory Protection?
Memory protection refers to the techniques and mechanisms used by the operating
system and hardware to prevent a process from accessing memory locations allocated to
another process or to the system itself.
6.2 Importance of Memory Protection
✔ Prevents processes from interfering with each other's memory.
✔ Enhances system stability and reliability.
✔ Provides security by preventing unauthorized access to system memory.
✔ Helps in debugging by detecting invalid memory accesses.
6.3 Mechanisms for Memory Protection
a) Base and Limit Registers
✔ The Base Register holds the starting address of a process's memory.
✔ The Limit Register defines the size (range) of the process's memory.
✔ The MMU ensures that a process can only access memory within its allocated range.
Example:
Base = 1000
Limit = 500
Allowed addresses: 1000 to 1499
b) Paging and Segmentation Protection
✔ Paging inherently prevents processes from accessing frames belonging to other
processes.
✔ In segmentation, access is restricted to a process's segments only.
c) Access Control Bits
✔ Memory areas can have attributes like Read, Write, or Execute permissions.
✔ The MMU enforces these permissions, preventing illegal operations.
d) Virtual Memory and Isolation
✔ Virtual memory provides process isolation by ensuring each process operates in its
own virtual address space.
✔ Processes cannot directly access each other's memory.
6.4 Memory Allocation by the Operating System
✔ The OS keeps track of free and used memory using data structures like Free Lists or
Bitmaps.
✔ Memory is allocated when a process is created and deallocated when it terminates.
✔ Allocation techniques include:
Contiguous Allocation: Allocates a continuous block of memory (prone to
fragmentation).
Paging: Allocates memory in fixed-size blocks (pages), reducing fragmentation.
Segmentation: Allocates memory in variable-sized segments based on program
structure.
6.5 Dynamic Memory Allocation
✔ Some programs request memory during execution using functions like malloc() (in
C).
✔ The OS provides memory from the free pool and tracks usage.
✔ Proper memory protection ensures dynamically allocated memory does not interfere
with other processes.
Summary of Key Points:
✔ Memory protection prevents unauthorized memory access.
✔ Base and limit registers, paging, segmentation, and access control bits enforce
protection.
✔ The OS is responsible for allocating memory efficiently and safely.
✔ Memory allocation techniques vary based on system design.
Short Quiz/Exercise:
1. What is memory protection, and why is it necessary?
2. Explain how base and limit registers work for memory protection.
3. Name two mechanisms used by the OS to protect memory.
4. Describe how the OS allocates memory to processes.
Next Lesson:
Revision and Evaluation - Recap of Memory Management Concepts and Sample Test.
Operating Systems - Lesson 7 Notes
Lesson Title:
Revision and Evaluation - Memory Management Unit
Lesson Objectives:
By the end of this lesson, students should be able to:
✔ Recap all key concepts related to memory management.
✔ Answer sample questions and exercises to test understanding.
✔ Identify areas needing further clarification.
✔ Prepare for formal assessment on memory management topics.
Lesson Content and Notes:
7.1 Quick Recap of Memory Management Topics
1. Memory Management Fundamentals
✔ The operating system is responsible for efficient memory allocation and protection.
✔ The Memory Management Unit (MMU) translates logical addresses to physical
addresses.
2. Contiguous Memory Allocation
✔ Processes are allocated continuous blocks of memory.
✔ Fixed and variable partitioning techniques are used.
✔ Fragmentation occurs, classified as internal or external.
3. Paging
✔ Logical memory divided into pages, physical memory into frames.
✔ Pages are mapped to frames via a page table.
✔ Paging eliminates external fragmentation.
4. Segmentation
✔ Logical memory divided into variable-sized segments.
✔ Reflects how programs are logically structured.
✔ Suffers from external fragmentation.
5. Virtual Memory
✔ Extends available memory using disk space.
✔ Allows execution of large programs.
✔ Involves page replacement algorithms like FIFO and LRU.
6. Memory Protection and Allocation
✔ Ensures processes cannot access unauthorized memory areas.
✔ Uses mechanisms like base and limit registers, access control bits, and paging.
✔ The OS allocates and deallocates memory during process life cycles.
7.2 Sample Test Questions
Section A: Short Answer Questions
1. Define memory management.
2. What is the role of the MMU?
3. Differentiate between logical and physical addresses.
4. What is external fragmentation?
5. How does paging help solve memory management problems?
6. Explain segmentation with an example.
7. What is virtual memory?
8. State two advantages of virtual memory.
9. How do base and limit registers enforce memory protection?
10. List two disadvantages of segmentation.
Section B: Structured Questions
1. Draw and explain the translation of logical to physical address using paging.
2. Compare segmentation and paging, highlighting at least three differences.
3. Describe how the operating system handles a page fault in virtual memory.
4. Explain with an example how a page replacement algorithm works.
5. Discuss three memory protection mechanisms used by modern operating systems.
7.3 Class Activities
✔ Group discussion on real-life examples of memory management (e.g., mobile phone
app behavior).
✔ Attempting quiz questions in groups.
✔ Trainer to provide feedback and clarification.
7.4 Summary of Key Takeaways
✔ Memory management is essential for efficient, secure operation of computer systems.
✔ Techniques like paging and segmentation solve specific memory allocation problems.
✔ The MMU and OS work together to translate addresses and protect memory.
✔ Virtual memory extends system capabilities beyond physical RAM.
7.5 Conclusion
This marks the completion of the Memory Management Unit. Students should now be
able to:
✔ Explain key memory management concepts.
✔ Apply their understanding to simple problem-solving tasks.
✔ Prepare for upcoming assessments on the topic.
Next Topic:
Process Management in Operating Systems.