0% found this document useful (0 votes)
11 views13 pages

UNIT IV Assignment

The document discusses various memory management techniques in operating systems, including memory partitioning methods (fixed, variable, paging, and segmentation) and their advantages and disadvantages. It also covers page replacement policies, memory allocation strategies (first fit, best fit, worst fit), and the concepts of virtual memory, fragmentation, and compaction. Additionally, it highlights the buddy memory allocation system and the differences between contiguous and non-contiguous memory allocation.

Uploaded by

Omkar Kumbhar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views13 pages

UNIT IV Assignment

The document discusses various memory management techniques in operating systems, including memory partitioning methods (fixed, variable, paging, and segmentation) and their advantages and disadvantages. It also covers page replacement policies, memory allocation strategies (first fit, best fit, worst fit), and the concepts of virtual memory, fragmentation, and compaction. Additionally, it highlights the buddy memory allocation system and the differences between contiguous and non-contiguous memory allocation.

Uploaded by

Omkar Kumbhar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

UNIT IV Assignment: Operating System

Q1) a) Explain Memory Partitioning Techniques in Detail?

What is Memory Partitioning?

Memory partitioning is a technique used in multiprogramming systems where the main


memory is divided into sections (partitions) to allocate processes.

Types of Memory Partitioning:

1. Fixed Partitioning (Static Partitioning)

 Memory is divided into fixed-sized partitions at system boot.

 Each partition can hold only one process.

 Unused space leads to internal fragmentation.

✅ Advantages:

 Simple to implement.

 Fast process allocation.

❌ Disadvantages:

 Internal fragmentation (unused memory inside a partition).

 Wastes memory if the process is smaller than partition size.

2. Variable Partitioning (Dynamic Partitioning)

 Memory is divided dynamically based on process size.

 No fixed partitions, so memory is allocated as per requirement.

 Compaction is used to remove fragmentation.

✅ Advantages:

 Better memory utilization (no fixed partitions).

 No internal fragmentation.
❌ Disadvantages:

 External fragmentation (scattered free memory).

 Needs compaction to merge free memory.

3. Paging

 Memory is divided into fixed-size pages (e.g., 4KB).

 Processes are divided into equal-sized frames.

 Pages are mapped to frames using a Page Table.

✅ Advantages:

 No external fragmentation.

 Efficient memory usage.

❌ Disadvantages:

 Page Table overhead.

 Internal fragmentation if process size is not a multiple of page size.

4. Segmentation

 Memory is divided into variable-sized segments based on logical divisions (code, data,
stack).

 Each segment has a base and limit.

✅ Advantages:

 Improves logical organization of memory.

 Reduces internal fragmentation.

❌ Disadvantages:

 External fragmentation may occur.

 Slower memory access due to segment mapping.


Q1) b) Explain Page Replacement Policies?

Page replacement policies determine which page to replace when memory is full in virtual
memory systems.

1. First In First Out (FIFO)

 The oldest page in memory is removed first.

 Simple but can lead to Belady’s Anomaly (higher frames → more page faults).

✅ Advantage: Easy to implement.


❌ Disadvantage: May replace frequently used pages.

2. Least Recently Used (LRU)

 The least recently used page is removed.

 Uses timestamps or a stack to track usage.

✅ Advantage: Good performance in most cases.


❌ Disadvantage: Overhead of tracking recent use.

3. Optimal Page Replacement

 Replaces the page that will not be used for the longest time.

 Theoretical best but not implementable in real-time.

✅ Advantage: Minimum page faults.


❌ Disadvantage: Cannot be implemented in real-world OS.

4. Least Frequently Used (LFU)

 Removes the page with least access count.

✅ Advantage: Prioritizes frequently used pages.


❌ Disadvantage: Slow tracking of access counts.

Q2) a) Explain LRU Algorithm with Example?


LRU (Least Recently Used) is a page replacement algorithm that removes the least recently
used page when a new page needs to be loaded.

Example:

Assume a memory with 3 frames and the reference string:


📌 Reference String: 7, 0, 1, 2, 0, 3, 4, 2, 3, 0, 3, 2, 1, 2

LRU Simulation:

Step Reference Page Frames Page Fault?

1 7 7-- ✅

2 0 70- ✅

3 1 701 ✅

4 2 012 ✅ (Replace 7)

5 0 012 ❌ (Already in memory)

6 3 123 ✅ (Replace 0)

7 4 234 ✅ (Replace 1)

✅ Total Page Faults: 9


✅ Better than FIFO as it considers usage history.

Here are detailed answers for your Unit IV Operating System Assignment questions.

Q2) b) Short Notes on:

(i) Contiguous Memory Allocation

 Definition: Contiguous memory allocation assigns a single continuous block of memory


to each process.

 Working:

o Each process is allocated memory in one single block.

o The OS maintains a table for tracking free and allocated spaces.

o If memory is fragmented, compaction is used to rearrange it.


 Example:
Assume a 100MB memory where:

o Process P1 (30MB) is allocated at address 0-29MB.

o Process P2 (40MB) is allocated at address 30-69MB.

o Process P3 (20MB) is allocated at address 70-89MB.

Process Start Address End Address Size

P1 0 29 30MB

P2 30 69 40MB

P3 70 89 20MB

✅ Advantages:

 Faster memory access due to sequential storage.

 Simple memory management.

❌ Disadvantages:

 Internal & External Fragmentation due to inefficient allocation.

 Limited process size (cannot exceed the largest free partition).

(ii) Non-Contiguous Memory Allocation

 Definition: In non-contiguous memory allocation, a process is divided into smaller


blocks and placed anywhere in memory.

 Used in: Paging & Segmentation

 Working:

o The process is divided into pages (in Paging) or segments (in Segmentation).

o These pages/segments are mapped to available frames anywhere in RAM.

o Page Tables or Segment Tables are used for tracking.

 Example:

o Process P1 has 3 pages and is stored in different memory locations.


o Instead of allocating one 30MB block, it uses three 10MB blocks.

Page No. Memory Address (Frame)

P1-Page 1 Address 0-9MB

P1-Page 2 Address 40-49MB

P1-Page 3 Address 80-89MB

✅ Advantages:

 No External Fragmentation since memory is used dynamically.

 Allows processes larger than available free space (uses paging/swapping).

❌ Disadvantages:

 Memory Access is Slower due to address translation.

 Page Table Overhead (extra memory is used for mapping tables).

Q3) a) Buddy Memory Allocation System in Operating System

What is Buddy System?

The Buddy Memory Allocation system is a dynamic memory allocation technique that:

 Divides memory into power-of-2 sized blocks.

 Splits and merges memory blocks dynamically as needed.

Working of Buddy System

1. Memory Initialization

o Assume 128MB RAM.

o It starts as one large block.

2. Process Requesting Memory

o Process P1 requests 50MB → 128MB splits into 64MB + 64MB.

o 64MB block is further split into 32MB + 32MB, until a sufficient block (64MB) is
found.

3. Memory Deallocation & Merging (Coalescing)


o When a process terminates, its memory is freed.

o If its "buddy" is also free, they merge into a larger block.

Example

Initial Memory After Allocation After Deallocation

128MB 64MB (P1) + 64MB Free 128MB Free

✅ Advantages:

 Fast Allocation & Deallocation.

 Efficient memory utilization.

❌ Disadvantages:

 Internal Fragmentation when process sizes are not exact multiples of power-of-2.

 Complex implementation.

Q3) b) Best Fit, Worst Fit, and First Fit Allocation

What is Memory Allocation?

Memory allocation algorithms decide how to allocate memory to a process.

1. First Fit

 The first available free block that fits the process is used.

 Fast but causes fragmentation.

Example:

Free Blocks (MB) Process Request (MB) Allocation

10MB 6MB ✅ Allocated

20MB 15MB ✅ Allocated

30MB 25MB ✅ Allocated

✅ Fastest Algorithm
❌ Causes External Fragmentation
2. Best Fit

 The smallest possible free block that fits is used.

 Minimizes leftover memory.

Example:

Free Blocks (MB) Process Request (MB) Allocation

10MB 6MB ✅ Allocated (Best Fit)

20MB 15MB ✅ Allocated

30MB 25MB ✅ Allocated

✅ Minimizes waste
❌ Slower than First Fit

3. Worst Fit

 The largest available free block is used.

 Leaves largest possible gaps.

Example:

Free Blocks (MB) Process Request (MB) Allocation

30MB 6MB ✅ Allocated (Worst Fit)

20MB 15MB ✅ Allocated

10MB 8MB ✅ Allocated

✅ Leaves larger free space for future requests.


❌ Wastes memory.

Q4) a) Difference Between Contiguous & Non-Contiguous Memory Allocation

Non-Contiguous Memory
Feature Contiguous Memory Allocation
Allocation

Definition Process occupies a single continuous Process occupies multiple scattered


Non-Contiguous Memory
Feature Contiguous Memory Allocation
Allocation

block. blocks.

Suffers from internal & external


Fragmentation No external fragmentation.
fragmentation.

Speed Faster access (sequential). Slower (requires mapping).

Memory
Wastes memory due to fragmentation. Uses memory efficiently.
Utilization

Example Fixed & Variable Partitioning Paging & Segmentation

Q4) b) Difference Between Paging & Segmentation

Feature Paging Segmentation

Divides memory into fixed-size Divides memory into variable-sized


Memory Division
pages. segments.

Fragmentation Internal Fragmentation occurs. External Fragmentation occurs.

Address Mapping Uses a Page Table. Uses a Segment Table.

Logical Divides processes into pages Divides processes into segments (logical
Organization (fixed-size blocks). units like Code, Data, Stack).

Example Virtual Memory Paging Compilers store functions in Segments

Final Answer Summary

Concept Explanation

Contiguous Memory Allocates memory as one continuous block, suffers from


Allocation fragmentation.

Non-Contiguous Memory Allocates memory in scattered pages/segments, requires


Allocation mapping tables.

Buddy System Allocates memory in power-of-2 sized blocks, splits & merges
Concept Explanation

memory dynamically.

Best Fit Chooses smallest block that fits, minimizes fragmentation.

Worst Fit Chooses largest block, leaves big free spaces.

First Fit Allocates first free block, fast but causes fragmentation.

Fixed-size pages, avoids external fragmentation but causes


Paging
internal fragmentation.

Variable-size segments, efficient but suffers from external


Segmentation
fragmentation.

Q5) a) How Does Virtual Memory Work?

What is Virtual Memory?

Virtual Memory is a memory management technique that allows a computer to execute


processes larger than the available physical RAM by using secondary storage (HDD/SSD) as
temporary memory.

How Virtual Memory Works?

1. Process Execution & Address Translation

o A process is loaded into RAM, but only a part of it is kept in memory.

o The rest is stored on the hard disk in a swap file.

2. Demand Paging & Page Faults

o When a process needs a page not in RAM, a page fault occurs.

o The OS retrieves the required page from secondary storage.

3. Page Replacement

o If RAM is full, the OS replaces old pages using a page replacement algorithm
(LRU, FIFO, Optimal).

4. Translation Lookaside Buffer (TLB)

o A hardware cache that speeds up logical to physical address translation.


Advantages of Virtual Memory:

✅ Allows larger programs to run.


✅ Supports multitasking efficiently.
✅ Reduces the need for expensive RAM upgrades.

Disadvantages of Virtual Memory:

❌ Slower than physical RAM due to disk access.


❌ Causes page faults, slowing performance.
❌ Overuse leads to thrashing (excessive page swapping).

Q5) b) Explain the Concepts of Memory Fragmentation & Memory Compaction

Memory Fragmentation

Memory fragmentation occurs when free memory is divided into small, non-contiguous
blocks, making it difficult to allocate memory to new processes.

Types of Fragmentation:

1. Internal Fragmentation

o Occurs when allocated memory is slightly larger than requested.

o Unused space inside the allocated block.

o Example: Allocating 4KB blocks for a 3.5KB process leaves 0.5KB unused.

2. External Fragmentation

o Occurs when free memory is scattered in small non-contiguous blocks.

o Even if total free space is enough, allocation fails due to fragmentation.

o Example: A 10MB process cannot be allocated if RAM has 5MB free at two
different locations.

Memory Compaction

Memory compaction is a technique used to reduce external fragmentation by rearranging


memory contents to place all free memory together.

How Compaction Works?


 The OS shifts processes to eliminate gaps between allocated memory blocks.

 This creates one large block of free space.

Example of Compaction

Before Compaction:

| P1 (5MB) | Free (3MB) | P2 (6MB) | Free (2MB) | P3 (4MB) |

After Compaction:

| P1 (5MB) | P2 (6MB) | P3 (4MB) | Free (5MB) |

✅ Advantage: More efficient memory utilization.


❌ Disadvantage: High CPU overhead during rearrangement.

Q6) a) Advantages & Disadvantages of Variable Partitioning

What is Variable Partitioning?

 Unlike fixed partitioning, variable partitioning allocates memory dynamically based on


process size.

 Reduces internal fragmentation but can cause external fragmentation.

Advantages of Variable Partitioning

✅ Efficient Memory Utilization – No fixed partitions, processes get exactly what they need.
✅ No Internal Fragmentation – Unlike fixed partitions, no wasted memory within allocated
space.
✅ More Flexibility – Allows different-sized processes to enter memory dynamically.

Disadvantages of Variable Partitioning

❌ External Fragmentation – Small free spaces remain unusable.


❌ Compaction Overhead – OS must rearrange memory frequently to avoid fragmentation.
❌ Slower Allocation – OS must search for free space before allocating memory.

Q6) b) Advantages & Disadvantages of Segmentation

What is Segmentation?
Segmentation is a memory management technique that divides a program into logical
segments (Code, Data, Stack). Each segment has:

 Base Address (starting location in memory)

 Limit (size of the segment)

Advantages of Segmentation

✅ Logical Memory Division – Each segment represents a logical unit (e.g., functions, arrays,
stacks).
✅ Efficient Memory Usage – No internal fragmentation.
✅ Supports Dynamic Memory Growth – Segments can grow/shrink based on needs.

Disadvantages of Segmentation

❌ External Fragmentation – Segments vary in size, causing free space to be scattered.


❌ Segment Table Overhead – Each process needs a segment table for memory mapping.
❌ Slower Memory Access – Two-step address translation increases access time.

Final Answer Summary

Concept Explanation

Virtual Memory Uses secondary storage as an extension of RAM to run large programs.

Memory Internal: Wasted space inside allocated memory. External: Free memory
Fragmentation scattered in small blocks.

Memory Compaction Rearranges memory to merge free spaces and reduce fragmentation.

Variable Partitioning ✅ No internal fragmentation. ❌ Causes external fragmentation.

Segmentation ✅ Logical memory division. ❌ Suffers from external fragmentation.

You might also like