UNIT – 3
1. Explain page replacement algorithms with example.
FCFS:
FIFO:
LRU:
2. Problems on page replacement algorithm (FCFS, LRU, Optimal Page
replacement)
3. Define :
a. Overlays.
b. Compaction
c. Swapping
d. Hit ratio
a. Overlays
Overlays are a technique used to run programs that are larger than the available
memory. Only the necessary parts (modules) of a program are loaded into memory at a
time, and others are swapped in as needed.
Think of it like using only the tools you need from a toolbox instead of dumping the
whole thing on your desk.
b. Compaction
Compaction is the process of rearranging memory contents to eliminate
fragmentation. It moves all occupied memory blocks to one end and combines all free
space into one large block.
It’s like tidying up your closet so all the empty hangers are together.
c. Swapping
Swapping is when a process is moved temporarily out of main memory to disk (and
back later) to free up space for other processes.
Imagine putting a paused game on hold so someone else can use the console.
d. Hit Ratio
Hit ratio is a performance metric in memory systems. It’s the percentage of memory
accesses that are found in the cache.
● Hit Ratio = (Cache Hits / Total Memory Accesses) × 100%
A higher hit ratio means faster performance.
4. What are the requirements of memory management?
Memory management in an operating system ensures that programs run efficiently and
safely by handling how memory is allocated, shared, and protected. Here are the key
requirements it must satisfy:
🧭 1. Relocation
Processes can be moved in and out of memory (swapped), so the OS must support
dynamic relocation—translating logical addresses to physical ones at runtime.
🛡️ 2. Protection
Each process must be protected from accessing another’s memory. This prevents
accidental or malicious interference and ensures system stability.
🔄 3. Sharing
Sometimes, processes need to share memory (e.g., shared libraries or interprocess
communication). The system must allow safe and controlled sharing.
🧠 4. Logical Organization
Programs are usually written in modules (code, data, stack). Memory management
should support this modular structure, allowing independent loading and protection of
each part.
🧱 5. Physical Organization
The OS must manage the physical memory layout, including handling fragmentation
and ensuring efficient use of RAM and secondary storage.
5. Explain Contiguous and non-contiguous memory allocation.
🧱 Contiguous Memory Allocation
In this method, a process is given one single block of memory that’s all together
(contiguous).
● Think of it like: Reserving a row of seats in a theater—all seats are side by side.
● Pros:
○ Easy to implement.
○ Fast access since memory is sequential.
● Cons:
○ Can lead to fragmentation (wasted space).
○ Hard to fit large processes if memory is scattered.
🧩 Non-Contiguous Memory Allocation
Here, a process is split across different memory blocks that may be scattered
throughout RAM.
● Think of it like: Booking separate seats in different rows when a full row isn’t
available.
● Pros:
○ Better use of memory—less wastage.
○ Supports larger and more processes.
● Cons:
○ Slightly slower due to extra bookkeeping.
○ Needs more complex memory management.
6. Write a note on :
a. Paging
b. Segmentation
c. Thrashing
a. Paging
Paging is a memory management technique where the logical memory is divided into
fixed-size blocks called pages, and physical memory is divided into blocks of the same
size called frames. When a program runs, its pages are loaded into any available
frames, not necessarily in a contiguous manner.
● Purpose: Solves the problem of external fragmentation.
● Example: If a program needs 12 KB and the page size is 4 KB, it will be divided
into 3 pages, which can be placed anywhere in memory.
b. Segmentation
Segmentation divides memory into variable-sized segments based on the logical
divisions of a program—like functions, arrays, or data structures.
● Purpose: Reflects the logical structure of programs and allows for easier sharing
and protection.
● Example: A program might have a code segment, data segment, and stack
segment, each with different sizes.
c. Thrashing
Thrashing happens when the system spends more time swapping pages in and out
of memory than executing actual processes. It usually occurs when there are too
many processes competing for too little memory, causing constant page faults.
● Symptoms: High CPU usage but low actual work done.
● Solution: Reduce the degree of multiprogramming or use better page
replacement strategies.
7. Differentiate between paging and segmentation.
Feature Paging Segmentation
Memory Fixed-size Variable-size
Division pages segments
Fragmentat Internal External
ion
Type
Address Page Segment
Structur number number +
e + offset offset
Programm Not visible Visible
er
Control
Logical Not Preserves
Organiz preserv logical
ation ed structure
8. Differentiate between external fragmentation and internal fragmentation.
Feature Internal External
Fragmentation Fragmentation
Memory Fixed-size Variable-size
Block
Size
Wasted Inside allocated blocks Between allocated
Space blocks
Visibility Hidden within blocks Visible as scattered free
space
Common Paging, fixed Segmentation, dynamic
in partitioning partitioning
Solution Best-fit allocation, Compaction, paging,
dynamic sizing segmentation
9. Virtual memory
Virtual memory is a clever trick used by operating systems to make your computer feel like it
has more RAM than it actually does. It does this by using a portion of your hard drive (or SSD)
as if it were extra memory.
🧠 Why Virtual Memory Exists
● RAM is fast but limited.
● When RAM fills up, the OS moves less-used data to a special space on the disk called
the page file or swap space.
● This frees up RAM for active tasks and keeps your system running smoothly.
🛠️ How It Works
1. Programs request memory.
2. If RAM is full, the OS shifts some data to virtual memory on the disk.
3. When that data is needed again, it’s swapped back into RAM.
⚖️ Pros and Cons
Pros Cons
Lets you run more programs Slower than real RAM
Prevents crashes from low RAM Can cause lag if overused
(thrashing)