BCA Semester 5 - Thrashing, Fragmentation and other Questions and Answers
Operating Systems:
Thrashing, Fragmentation
and other
Questions and Answers
Q: Explain the concept of thrashing.
Answer: When a process does not have enough enough number of frames, page fault occurs. For this, replacement of pages would be there. But all pages are in use, resulting in page faults again and again. The process continues to replace pages and repeatedly page faults occur.
This high paging activity is called 'Thrashing'. A process is thrashing when it is spending more time in paging rather than executing.
When a process is busy in pages swapping-in and swapping-out, this process is known as Thrashing. A system that is thrashing is either working very slow or has come to a halt. Thrashing may lead to :
Thrashing can be prevented by using locality model of process execution. In this localities, a process is divided into different localities. A locality contains local variables and sub-routines.A Process migrates from locality to locality. Localities may overlap too. Paging occurs for each locality separately. So if, the number of frames for one process are less than the pages being used, which results in thrashing.But when the process moves to another locality, this problem of thrashing, gets removed. This is one of the ways to prevent thrashing.
This high paging activity is called 'Thrashing'. A process is thrashing when it is spending more time in paging rather than executing.
When a process is busy in pages swapping-in and swapping-out, this process is known as Thrashing. A system that is thrashing is either working very slow or has come to a halt. Thrashing may lead to :
- Low CPU utilisation
- Operating System thinks that it needs to increase the degree of multi-programming.
- Another process added to the system.
Thrashing can be prevented by using locality model of process execution. In this localities, a process is divided into different localities. A locality contains local variables and sub-routines.A Process migrates from locality to locality. Localities may overlap too. Paging occurs for each locality separately. So if, the number of frames for one process are less than the pages being used, which results in thrashing.But when the process moves to another locality, this problem of thrashing, gets removed. This is one of the ways to prevent thrashing.
Q: Discuss various types of fragmentation and memory allocation strategies.
Answer: Fragmentation is a phenomenon in which storage space is used inefficiently, reducing the capacity and often performance. Fragmentation leads to storage space being "wasted".
Types Of Fragmentation:
- External Fragmentation -Total memory space is enough to store a process, the memory space is not contiguous. The storage is fragmented into a large number of small holes or chunks. This wasted space cannot be allocated to any partition, and is called External Fragmentation.
- Internal Fragmentation – Allocated memory may be slightly larger than the requested memory; this size difference is memory internal to a partition, but not being used. The space at the end of the partition is wasted and not being used. This wasted space within the partition is internal fragmentation.
We can reduce external fragmentation by compaction .
- Shuffle Memory contents to place all free memory together in one large block.
- Compaction is possible only if relocation is dynamic, and is done at execution time.
Memory Allocation Strategies:
- Main memory is usually segmented into two partitions:
- The operating system resides in the lower part of the memory and,
- The user processes then held in the higher section of the memory.
- Single-partition allocation
- Requires a relocation-register scheme used to protect user processes from each other, and from changing operating-system code and data
- Relocation register contains value of smallest physical address; limit register contains range of logical addresses – each logical address must be less than the limit register
-
Multiple-partition allocation
- Hole – a block of available memory; holes of various size are scattered throughout memory
- When a process arrives, it is allocated memory from a hole large enough to accommodate it
-
Operating system maintains information about:
a) allocated partitions b) free partitions (holes)
Dynamic Storage-Allocation
To satisfy a request of size n from a list of free holes.
- First-fit: Allocate the first hole that is big enough
- Best-fit: Allocate the smallest hole that is big enough; must search entire list, unless ordered by size. Produces the smallest leftover hole.
- Worst-fit: Allocate the largest hole; must also search entire list. Produces the largest leftover hole.
First-fit and best-fit better than worst-fit in terms of speed and storage utilization