OSY - 5th Unit Notes
OSY - 5th Unit Notes
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 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 :
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.
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.
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: