0% found this document useful (0 votes)
24 views18 pages

OSY - 5th Unit Notes

The document discusses memory management techniques, focusing on partitioning types (fixed and variable), free space management techniques, virtual memory, paging, segmentation, fragmentation, and page replacement algorithms. It outlines the advantages and disadvantages of each method, highlighting issues like internal and external fragmentation, as well as different page replacement strategies such as FIFO, LRU, and Optimal. Overall, it provides a comprehensive overview of how memory is managed in operating systems.

Uploaded by

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

OSY - 5th Unit Notes

The document discusses memory management techniques, focusing on partitioning types (fixed and variable), free space management techniques, virtual memory, paging, segmentation, fragmentation, and page replacement algorithms. It outlines the advantages and disadvantages of each method, highlighting issues like internal and external fragmentation, as well as different page replacement strategies such as FIFO, LRU, and Optimal. Overall, it provides a comprehensive overview of how memory is managed in operating systems.

Uploaded by

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

Unit 5: Memory Management

Q.1] Explain partitioning types:


Types of Partitioning:
1. Fixed Partitioning
2. Variable Partitioning
1] Fixed Partitioning (Static):
▪ Memory is divided into number of fixed size partitions, which is called as
fixed or static memory partitioning.
▪ Each partition contains exactly one process.
▪ The number of programs to be executed depends on number of partitions.
▪ When the partition is free, a selected process from the input queue is loaded
into the free partition.
▪ When the process terminates, the partition becomes available for another
process.
▪ The operating system keeps a table indicating parts of memory which are
available and which are occupied.
▪ Initially, all memory is available for user processes and it is considered as
one large block of available memory, a hole.
▪ When a process arrives, large enough hole of memory is allocated to the
processes.
Advantages of Fixed Partitioning:
1. Simplifies memory management.
2. Allows fast allocation.
3. Minimizes internal fragmentation.
4. Easier to implement.
Disadvantages of Fixed Partitioning:
1. Causes internal fragmentation.
2. Limited flexibility for larger processes.
3. Wastes space in larger partitions.
4. Challenging for variable size processes.
2] Variable Partitioning (Dynamic):
▪ Variable partitioning divides the main memory into partitions of varying
sizes based on process requirements.
▪ Partitions are created dynamically as processes are loaded, allowing for
customized sizes.
▪ This approach minimizes wasted space by reducing internal fragmentation.
▪ It allows for more flexible memory use, accommodating processes of
different sizes.
▪ The method improves overall memory utilization.
▪ Advantages include better efficiency in memory allocation.
▪ It is adaptable for a diverse range of process sizes.
▪ Disadvantages include external fragmentation, where free memory
becomes fragmented over time.
▪ It requires complex management to track and allocate varying partition
sizes.
Advantages of Variable Partitioning:
1. Efficient memory utilization reduces wasted space.
2. Flexibility accommodates varying process sizes.
3. Dynamic allocation optimizes resource use.
4. Improved performance enhances overall system efficiency.
Disadvantages of Variable Partitioning:
1. External fragmentation complicates larger memory allocations.
2. Complex management requires sophisticated tracking.
3. Increased allocation time can lead to delays.
4. Potential overhead may impact system performance.

Q.2] List free space management techniques and explain


Types of Free Space Management:
1. Bit Vector
2. Linked List
3. Grouping
4. Counting
1. Bitmap or Bit vector
A Bitmap or Bit Vector is series or collection of bits where each bit corresponds
to a disk block. The bit can take two values: 0 and 1: 0 indicates that the block is
free and 1 indicates an allocated block. The given instance of disk blocks on the
disk in Figure 1 (where green blocks are allocated) can be represented by a bitmap
of 16 bits as: 1111000111111001.
Advantages of Bit Vector:
1. Space efficient; uses one bit per block.
2. Fast access for quick allocation.
3. Simple to implement and manage.
4. Easy to count contiguous free blocks.
Disadvantages of Bit Vector:
1. Fixed size can lead to wasted space.
2. Does not address fragmentation.
3. Can be large for extensive memory systems.
4. Finding contiguous blocks may be time-consuming.

2. Linked List:
▪ In this approach, the free disk blocks are linked together i.e. a free block
contains a pointer to the next free block.
▪ The block number of the very first disk block is stored at a separate location
on disk and is also cached in memory.
▪ In this approach, link all the disk blocks together, keeping a pointer to the
first free block.
▪ This block contains a pointer to the next free disk block, and so on.
In Figure-2, the free space list head points to Block 5 which points to Block 6, the
next free block and so on. The last free block would contain a null pointer
indicating the end of free list. A drawback of this method is the I/O required for
free space list traversal.
Advantages of Linked List:
1. Dynamic size; adjusts as needed.
2. Efficient allocation and deallocation.
3. Flexible with varying block sizes.
4. Simple to implement.
Disadvantages of Linked List:
1. Overhead from pointer storage.
2. External fragmentation may occur.
3. Slower access due to list traversal.
4. Increased management complexity.
Q.3] Explain virtual memory

Advantages of Virtual Memory:


1. Provides process isolation and protection.
2. Enables flexible and efficient memory allocation.
3. Simplifies management with paging.
4. Supports concurrent process execution.
5. Facilitates efficient paging and swapping.
6. Reduces external fragmentation.
Disadvantages of Virtual Memory:
1. Increased disk I/O can slow performance.
2. Page faults add latency.
3. Page table management consumes CPU resources.
4. Internal fragmentation may waste space.
5. Adds complexity to the operating system.
6. Requires additional hardware support, increasing costs.
Q.5] Explain Paging
Paging:
Paging is a storage mechanism used to retrieve processes from the
secondary storage into the main memory in the form of pages.
▪ The main idea behind the paging is to divide each process in the form of
pages. The main memory will also be divided in the form of frames.
▪ One page of the process is to be stored in one of the frames of the memory.
The pages can be stored at the different locations of the memory but the
priority is always to find the contiguous frames or holes.
▪ Pages of the process are brought into the main memory only when they are
required otherwise, they reside in the secondary storage.

Advantages of Paging:
1. Eliminates external fragmentation.
2. Simplifies memory allocation.
3. Supports virtual memory.
4. Provides process isolation.
5. Allows memory sharing.
6. Eases memory management.
Disadvantages of Paging:
1. Can cause internal fragmentation.
2. Requires page table overhead.
3. Causes delays due to address translation.
4. Virtual address space may fragment.
5. Complex for large systems.
6. Can lead to thrashing if excessive paging occurs
Q.6] Explain Segmentation
Segmentation:
Segmentation is a memory management technique in which the
memory is divided into the variable size parts. Each part is known as a segment
which can be allocated to a process.
Basically, a process is divided into segments. Like paging, segmentation divides
or segments the memory. But there is a difference and that is while
the paging divides the memory into a fixed size and on the other hand,
segmentation divides the memory into variable segments these are then loaded
into logical memory space.
Advantages of Segmentation :

1. Aligns memory with program structure.


2. Allows flexible, varying segment sizes.
3. Provides access control per segment.
4. Reduces internal fragmentation.
5. Supports modular programming.
6. Segments can dynamically grow or shrink.

Disadvantages of Segmentation:
1. Causes external fragmentation.
2. Complex memory allocation/deallocation.
3. Adds overhead with segment tables.
4. Increases fragmentation over time.
5. Difficult to compact memory.
6. Complex address translation.

Q.7] Differentiate between paging and segmentation


Paging Segmentation
1. In paging, the program is divided 1. In segmentation, the program is
into fixed or mounted size pages. divided into variable size segments.
2. For the paging operating system is 2. For segmentation compiler is
accountable. accountable.
3. Page size is determined by 3. the segment size is given by the
hardware. user.
4. It is faster 4. Segmentation is slow.
5. Paging could result in internal 5. Segmentation could result in
fragmentation. external fragmentation.
6. This protection is hard to apply. 6. Easy to apply for protection in
segmentation.
7. A page is referred to as a physical 7. A segment is referred to as a logical
unit of information. unit of information.
8. Paging results in a less efficient 8. Segmentation results in a more
system. efficient system.
Q.8] Define fragmentation. Explain Internal and External Fragmentation
Fragmentation:
The problem due to which memory space is not getting utilized
at all is commonly known as Fragmentation in the operating system.
Types of Fragmentation
1. Internal Fragmentation
2. External Fragmentation

1] Internal Fragmentation:
Internal Fragmentation is a problem that occurs
when the process is allocated to a memory block whose size is more than the size
of that process and due to which some part of the memory is left unused. Thus the
space wasted inside the allocated memory block is due to the restriction on the
allowed sizes of allocated blocks.

In the above diagram, the difference between memory allocated and required
space or memory by the process is called internal fragmentation.
For Example:
Assume that memory allocation in RAM is done using fixed partitioning (i.e.,
memory blocks of fixed sizes). 2MB, 4MB, 4MB, and 8MB are the available
sizes. The Operating System uses a part of this RAM.

Let's suppose a process P1 with a size of 3MB arrives and is given a memory
block of 4MB. As a result, the 1MB of free space in this block is unused and
cannot be used to allocate memory to another process. It is known as internal
fragmentation.
Advantages of Internal Fragmentation:
1. Simple memory management.
2. Faster allocation/deallocation.
3. Predictable allocation.
4. Low management overhead.
Disadvantages of Internal Fragmentation:
1. Wastes memory within blocks.
2. Inefficient memory use.
3. Reduces available memory.
4. May require compaction.
2] External Fragmentation:
When the memory space in the system can easily
satisfy the requirement of the processes, but this available memory space is non-
contiguous, so it can’t be utilized further. Then this problem is referred to
as External Fragmentation.

In the above diagram, we can see that, there is enough space (55 KB) to run a
process-07 (required 50 KB) but the memory (fragment) is not contiguous.
Here, we use compaction, paging, or segmentation to use the free space to run a
process.
For Example:
Let's take the example of external fragmentation. In the above diagram, you can
see that there is sufficient space (50 KB) to run a process (05) (need 45KB), but
the memory is not contiguous. You can use compaction, paging, and
segmentation to use the free space to execute a process.
Advantages of External Fragmentation:
1. Flexible memory allocation.
2. No wasted space in blocks.
3. Fits dynamic memory needs.
4. Efficient for large allocations.
Disadvantages of External Fragmentation:
1. Small gaps prevent large allocations.
2. Complex memory management.
3. Increases over time.
4. Hard to track free memory.

Q.9] Difference between Internal Fragmentation and External Fragmentation


Internal Fragmentation External Fragmentation

1. Wasted memory within allocated 1. Wasted memory between allocated


blocks. blocks
2. Caused by fixed-size memory 2. Caused by variable-size memory
allocations allocations
3. Occurs inside individual blocks. 3. Occurs between allocated blocks.
4. Reduces usable space within 4. Reduces available space for large
allocations. allocations.
5. Easier to manage within blocks. 5. Harder to manage due to scattered
free spaces.
6. Can be resolved by compaction. 6. Requires defragmentation or
relocation.

Q.10] Define Page Fault


Page Fault:
A page fault occurs when a program tries to access data not currently
in RAM, prompting the operating system to load it from secondary storage.

Q.11] Explain Page Replacement Algorithm with example


Page Replacement Algorithm:
Page replacement algorithms are techniques used in operating systems to
manage memory efficiently when the virtual memory is full. When a new page
needs to be loaded into physical memory, and there is no free space, these
algorithms determine which existing page to replace.
Page Replacement Algorithm:
1. First In First Out (FIFO)
2. Least Recently Used (LRU)
3. Optimal Page Replacement
1] First In First Out (FIFO):
▪ FIFO replaces the oldest page in memory when a page fault occurs.
▪ It uses a queue to track the order of page loading.
▪ The page at the front of the queue is replaced when memory is full.
▪ Simple to implement with minimal overhead.
▪ Does not consider how often or recently a page is accessed.
▪ Can cause Belady’s Anomaly, where more memory results in more page
faults.
▪ Primarily used for simplicity, not performance.
▪ Works best with predictable memory access patterns.
Example:

Advantages of FIFO:
1. Simple to implement and understand.
2. Fair page replacement order.
3. Low overhead.
4. Works well with small memory systems.
Disadvantages of FIFO:
1. Can lead to poor performance with high locality of reference.
2. Can suffer from Belady’s Anomaly.
3. Does not consider page usage frequency.
4. May keep unused pages in memory
2] Least Recently Used (LRU):
▪ LRU replaces the least recently used page when a page fault occurs.
▪ It keeps track of the order in which pages are accessed, replacing the page
that has not been used for the longest time.
▪ LRU can be implemented using counters or a stack to maintain the access
history.
▪ More efficient than FIFO for programs with high locality of reference.
▪ Considers the recency of access, improving page replacement decisions.
▪ Requires extra memory and processing to track access history.
▪ Can be more complex and slower to implement than simpler algorithms
like FIFO.
▪ Works best when recent pages are more likely to be reused.
▪ Reduces the chances of replacing frequently used pages, leading to fewer
page faults.
▪ LRU is better suited for applications with irregular or unpredictable
memory access patterns.
Example:
Advantages of LRU:
1. Replaces least recently used pages.
2. Efficient with locality of reference.
3. Reduces frequent page replacements.
4. Easy to understand and implement.
Disadvantages of LRU:
1. Requires extra memory for tracking.
2. High overhead for maintaining access history.
3. Costly with many pages.
4. Not ideal for systems with limited memory
3] Optimal Page Replacement:
▪ The Optimal page replacement algorithm replaces the page that will not be
used for the longest time in the future.
▪ It requires knowledge of future page accesses to make the optimal
replacement decision.
▪ The algorithm minimizes the number of page faults by always choosing the
best candidate for replacement.
▪ It is considered the most efficient page replacement algorithm in terms of
minimizing page faults.
▪ The Optimal algorithm is not practical in real-world systems because it
requires predicting future memory accesses.
▪ It serves as a benchmark for comparing other page replacement algorithms.
▪ It ensures that pages with the least future use are replaced, improving
performance.
Example:

Advantages of Optimal Page Replacement:


1. Minimizes page faults.
2. Replaces pages with least future use.
3. Serves as a benchmark for other algorithms.
4. Works well with predictable memory access patterns.
Disadvantages of Optimal Page Replacement:
1. Requires knowledge of future page accesses.
2. Not feasible in real systems.
3. High overhead for predicting future usage.
4. Not effective with dynamic access patterns.
Q. 12] Consider the following memory map and assume a new process P4 comes
with memory requirements of 6 KB. Locate (Draw) this process in
memory using.
i) First fit
ii) Best Fit
iii) Worst Fit

You might also like